From 6e15e534109e4b8698ea8be8fdbea1a69090a630 Mon Sep 17 00:00:00 2001 From: okseby Date: Mon, 28 Aug 2023 19:18:11 -0400 Subject: [PATCH] Ok I think it works now, add message on successful merge --- bot/utils.go | 61 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/bot/utils.go b/bot/utils.go index 0e11292..06a52a5 100644 --- a/bot/utils.go +++ b/bot/utils.go @@ -103,38 +103,47 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) { for _, comment := range comments { if strings.Contains(comment.GetBody(), "+1") && !strings.Contains(comment.GetUser().GetLogin(), "bot") { fmt.Println(comment.GetUser().GetLogin()) - return reactionCount++ + } + } - if reactionCount >= reactionCountGoal { - // Merge the pull request - merge := &github.PullRequestOptions{ - MergeMethod: "merge", // Change this as needed - } + if reactionCount >= reactionCountGoal { + // Merge the pull request + merge := &github.PullRequestOptions{ + MergeMethod: "merge", // Change this as needed + } - _, _, err := client.PullRequests.Merge(ctx, owner, repo, prNumber, "Merging based on reactions", merge) - if err != nil { - log.Println("Error merging pull request:", err) - } else { - log.Println("Pull request #", prNumber, "merged successfully") - } + // Respond with a comment + comment := &github.IssueComment{ + Body: github.String("Merging based on reactions :fireworks:"), + } - return - } else { - commentText := "Current :+1: count is (#{reactionCount}) need (#{reactionRemainingCount}) more to merge" - commentText = strings.Replace(commentText, "(#{reactionCount})", strconv.Itoa(reactionCount), 1) - commentText = strings.Replace(commentText, "(#{reactionRemainingCount})", strconv.Itoa(reactionCountGoal-reactionCount), 1) + _, _, err := client.Issues.CreateComment(ctx, owner, repo, prNumber, comment) + if err != nil { + log.Println("Error creating comment:", err) + } - // Respond with a comment - comment := &github.IssueComment{ - Body: github.String(commentText), - } + _, _, err = client.PullRequests.Merge(ctx, owner, repo, prNumber, "Merging based on reactions", merge) + if err != nil { + log.Println("Error merging pull request:", err) + } else { + log.Println("Pull request #", prNumber, "merged successfully") + } - _, _, err := client.Issues.CreateComment(ctx, owner, repo, prNumber, comment) - if err != nil { - log.Println("Error creating comment:", err) - } - } + return + } else { + commentText := "Current :+1: count is (#{reactionCount}) need (#{reactionRemainingCount}) more to merge" + commentText = strings.Replace(commentText, "(#{reactionCount})", strconv.Itoa(reactionCount), 1) + commentText = strings.Replace(commentText, "(#{reactionRemainingCount})", strconv.Itoa(reactionCountGoal-reactionCount), 1) + + // Respond with a comment + comment := &github.IssueComment{ + Body: github.String(commentText), + } + + _, _, err := client.Issues.CreateComment(ctx, owner, repo, prNumber, comment) + if err != nil { + log.Println("Error creating comment:", err) } } }