Make sure votes are unique
This commit is contained in:
parent
e76e22ca6b
commit
2943a7dd0b
1 changed files with 17 additions and 1 deletions
16
bot/utils.go
16
bot/utils.go
|
@ -91,6 +91,7 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
prNumber := event.GetIssue().GetNumber()
|
prNumber := event.GetIssue().GetNumber()
|
||||||
reactionCount := 0
|
reactionCount := 0
|
||||||
reactionCountGoal := 5
|
reactionCountGoal := 5
|
||||||
|
approvers := []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)
|
||||||
|
@ -102,7 +103,22 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
// Check if there are thumbs up (:+1:) reactions
|
// Check if there are thumbs up (:+1:) reactions
|
||||||
for _, comment := range comments {
|
for _, comment := range comments {
|
||||||
if strings.Contains(comment.GetBody(), "+1") && !strings.Contains(comment.GetUser().GetLogin(), "bot") {
|
if strings.Contains(comment.GetBody(), "+1") && !strings.Contains(comment.GetUser().GetLogin(), "bot") {
|
||||||
|
for _, name := range approvers {
|
||||||
|
if !strings.Contains(name, comment.GetUser().GetLogin()) {
|
||||||
reactionCount++
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue