From e76e22ca6b6cc3a4b733adf9753e7a230693b549 Mon Sep 17 00:00:00 2001 From: okseby Date: Mon, 28 Aug 2023 19:21:16 -0400 Subject: [PATCH 1/4] Move required thumbs up for merge to 5 --- bot/utils.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bot/utils.go b/bot/utils.go index 06a52a5..4135188 100644 --- a/bot/utils.go +++ b/bot/utils.go @@ -90,7 +90,7 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) { repo := event.GetRepo().GetName() prNumber := event.GetIssue().GetNumber() reactionCount := 0 - reactionCountGoal := 2 + reactionCountGoal := 5 if event.GetIssue().IsPullRequest() { comments, _, err := client.Issues.ListComments(ctx, owner, repo, prNumber, nil) @@ -102,7 +102,6 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) { // Check if there are thumbs up (:+1:) reactions for _, comment := range comments { if strings.Contains(comment.GetBody(), "+1") && !strings.Contains(comment.GetUser().GetLogin(), "bot") { - fmt.Println(comment.GetUser().GetLogin()) reactionCount++ } } From 2943a7dd0bb595bca2451b895558f421f1c29416 Mon Sep 17 00:00:00 2001 From: okseby Date: Mon, 28 Aug 2023 19:44:46 -0400 Subject: [PATCH 2/4] Make sure votes are unique --- bot/utils.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bot/utils.go b/bot/utils.go index 4135188..50c4903 100644 --- a/bot/utils.go +++ b/bot/utils.go @@ -91,6 +91,7 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) { prNumber := event.GetIssue().GetNumber() reactionCount := 0 reactionCountGoal := 5 + approvers := []string{} if event.GetIssue().IsPullRequest() { comments, _, err := client.Issues.ListComments(ctx, owner, repo, prNumber, nil) @@ -102,7 +103,22 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) { // Check if there are thumbs up (:+1:) reactions for _, comment := range comments { if strings.Contains(comment.GetBody(), "+1") && !strings.Contains(comment.GetUser().GetLogin(), "bot") { - reactionCount++ + for _, name := range approvers { + if !strings.Contains(name, comment.GetUser().GetLogin()) { + reactionCount++ + approvers = append(approvers, comment.GetUser().GetLogin()) + } else { + // Respond with a comment + comment := &github.IssueComment{ + Body: github.String("You've already voted!"), + } + + _, _, err := client.Issues.CreateComment(ctx, owner, repo, prNumber, comment) + if err != nil { + log.Println("Error creating comment:", err) + } + } + } } } From c9470925679d27842782023b64456b556af1cc3c Mon Sep 17 00:00:00 2001 From: okseby Date: Mon, 28 Aug 2023 20:16:00 -0400 Subject: [PATCH 3/4] Ok that didn't work --- bot/utils.go | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/bot/utils.go b/bot/utils.go index 50c4903..e01aff8 100644 --- a/bot/utils.go +++ b/bot/utils.go @@ -91,7 +91,6 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) { prNumber := event.GetIssue().GetNumber() reactionCount := 0 reactionCountGoal := 5 - approvers := []string{} if event.GetIssue().IsPullRequest() { comments, _, err := client.Issues.ListComments(ctx, owner, repo, prNumber, nil) @@ -103,22 +102,7 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) { // Check if there are thumbs up (:+1:) reactions for _, comment := range comments { if strings.Contains(comment.GetBody(), "+1") && !strings.Contains(comment.GetUser().GetLogin(), "bot") { - for _, name := range approvers { - if !strings.Contains(name, comment.GetUser().GetLogin()) { - reactionCount++ - approvers = append(approvers, comment.GetUser().GetLogin()) - } else { - // Respond with a comment - comment := &github.IssueComment{ - Body: github.String("You've already voted!"), - } - - _, _, err := client.Issues.CreateComment(ctx, owner, repo, prNumber, comment) - if err != nil { - log.Println("Error creating comment:", err) - } - } - } + reactionCount++ } } @@ -147,7 +131,7 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) { return } else { - commentText := "Current :+1: count is (#{reactionCount}) need (#{reactionRemainingCount}) more to merge" + commentText := "Votes: (#{reactionCount})/(#{reactionRemainingCount})" commentText = strings.Replace(commentText, "(#{reactionCount})", strconv.Itoa(reactionCount), 1) commentText = strings.Replace(commentText, "(#{reactionRemainingCount})", strconv.Itoa(reactionCountGoal-reactionCount), 1) From e9081773632d07f741959df38ab16cece17ff837 Mon Sep 17 00:00:00 2001 From: okseby Date: Mon, 28 Aug 2023 20:16:48 -0400 Subject: [PATCH 4/4] Downgrade go version for deployment compatibility --- bot/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/go.mod b/bot/go.mod index 7f74909..820d987 100644 --- a/bot/go.mod +++ b/bot/go.mod @@ -1,6 +1,6 @@ module bot -go 1.21 +go 1.20 require ( github.com/bradleyfalzon/ghinstallation/v2 v2.6.0