chris broke everything
This commit is contained in:
parent
c0df5250a9
commit
8a8545ec63
1 changed files with 6 additions and 15 deletions
21
bot/utils.go
21
bot/utils.go
|
@ -23,8 +23,6 @@ var itr, _ = ghinstallation.New(http.DefaultTransport, 381312, 41105280, []byte(
|
||||||
var client = github.NewClient(&http.Client{Transport: itr})
|
var client = github.NewClient(&http.Client{Transport: itr})
|
||||||
var ctx = context.Background()
|
var ctx = context.Background()
|
||||||
|
|
||||||
var approvals = map[int]string{}
|
|
||||||
|
|
||||||
func initGitHubClient(v string) {
|
func initGitHubClient(v string) {
|
||||||
log.Println("Initializing......", v)
|
log.Println("Initializing......", v)
|
||||||
|
|
||||||
|
@ -125,9 +123,10 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
owner := event.GetRepo().GetOwner().GetLogin()
|
owner := event.GetRepo().GetOwner().GetLogin()
|
||||||
repo := event.GetRepo().GetName()
|
repo := event.GetRepo().GetName()
|
||||||
prNumber := event.GetIssue().GetNumber()
|
prNumber := event.GetIssue().GetNumber()
|
||||||
reactionCount := 0
|
|
||||||
reactionCountGoal := 5
|
reactionCountGoal := 5
|
||||||
|
|
||||||
|
var approvals = map[string]string{}
|
||||||
|
|
||||||
if event.GetIssue().IsPullRequest() {
|
if event.GetIssue().IsPullRequest() {
|
||||||
comments, _, err := client.Issues.ListComments(ctx, owner, repo, prNumber, nil)
|
comments, _, err := client.Issues.ListComments(ctx, owner, repo, prNumber, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -140,13 +139,9 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
commentAuthor := comment.GetUser().GetLogin()
|
commentAuthor := comment.GetUser().GetLogin()
|
||||||
|
|
||||||
if strings.Contains(comment.GetBody(), "+1") && !strings.Contains(commentAuthor, "bot") {
|
if strings.Contains(comment.GetBody(), "+1") && !strings.Contains(commentAuthor, "bot") {
|
||||||
value, exists := approvals[prNumber]
|
_, exists := approvals[commentAuthor]
|
||||||
if exists && !strings.Contains(value, commentAuthor) {
|
if !exists {
|
||||||
reactionCount++
|
approvals[commentAuthor] = commentAuthor
|
||||||
approvals[prNumber] = commentAuthor
|
|
||||||
} else if !exists {
|
|
||||||
reactionCount++
|
|
||||||
approvals[prNumber] = commentAuthor
|
|
||||||
} else {
|
} else {
|
||||||
commentText := "@(#{commentAuthor}) your vote has already been counted :x:"
|
commentText := "@(#{commentAuthor}) your vote has already been counted :x:"
|
||||||
commentText = strings.Replace(commentText, "(#{commentAuthor})", commentAuthor, 1)
|
commentText = strings.Replace(commentText, "(#{commentAuthor})", commentAuthor, 1)
|
||||||
|
@ -166,7 +161,7 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if reactionCount >= reactionCountGoal {
|
if len(approvals) >= reactionCountGoal {
|
||||||
// Merge the pull request
|
// Merge the pull request
|
||||||
merge := &github.PullRequestOptions{
|
merge := &github.PullRequestOptions{
|
||||||
MergeMethod: "merge", // Change this as needed
|
MergeMethod: "merge", // Change this as needed
|
||||||
|
@ -209,8 +204,6 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func processPullRequestEvent(event *github.PullRequestEvent) {
|
func processPullRequestEvent(event *github.PullRequestEvent) {
|
||||||
prNumber := event.GetPullRequest().GetNumber()
|
|
||||||
|
|
||||||
if event.GetAction() == "opened" || event.GetAction() == "reopened" {
|
if event.GetAction() == "opened" || event.GetAction() == "reopened" {
|
||||||
// Respond with a comment
|
// Respond with a comment
|
||||||
comment := &github.IssueComment{
|
comment := &github.IssueComment{
|
||||||
|
@ -221,7 +214,5 @@ func processPullRequestEvent(event *github.PullRequestEvent) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error creating comment:", err)
|
log.Println("Error creating comment:", err)
|
||||||
}
|
}
|
||||||
} else if event.Action != nil && *event.Action == "closed" && event.PullRequest.Merged != nil && *event.PullRequest.Merged {
|
|
||||||
delete(approvals, prNumber)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue