From 2943a7dd0bb595bca2451b895558f421f1c29416 Mon Sep 17 00:00:00 2001 From: okseby Date: Mon, 28 Aug 2023 19:44:46 -0400 Subject: [PATCH] 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) + } + } + } } }