Ok I think it works now, add message on successful merge

This commit is contained in:
Sebastian Cabrera 2023-08-28 19:18:11 -04:00
parent 2661344d14
commit 6e15e53410

View file

@ -103,38 +103,47 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
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") {
fmt.Println(comment.GetUser().GetLogin()) fmt.Println(comment.GetUser().GetLogin())
return
reactionCount++ reactionCount++
}
}
if reactionCount >= reactionCountGoal { if reactionCount >= 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
} }
_, _, err := client.PullRequests.Merge(ctx, owner, repo, prNumber, "Merging based on reactions", merge) // Respond with a comment
if err != nil { comment := &github.IssueComment{
log.Println("Error merging pull request:", err) Body: github.String("Merging based on reactions :fireworks:"),
} else { }
log.Println("Pull request #", prNumber, "merged successfully")
}
return _, _, err := client.Issues.CreateComment(ctx, owner, repo, prNumber, comment)
} else { if err != nil {
commentText := "Current :+1: count is (#{reactionCount}) need (#{reactionRemainingCount}) more to merge" log.Println("Error creating comment:", err)
commentText = strings.Replace(commentText, "(#{reactionCount})", strconv.Itoa(reactionCount), 1) }
commentText = strings.Replace(commentText, "(#{reactionRemainingCount})", strconv.Itoa(reactionCountGoal-reactionCount), 1)
// Respond with a comment _, _, err = client.PullRequests.Merge(ctx, owner, repo, prNumber, "Merging based on reactions", merge)
comment := &github.IssueComment{ if err != nil {
Body: github.String(commentText), log.Println("Error merging pull request:", err)
} } else {
log.Println("Pull request #", prNumber, "merged successfully")
}
_, _, err := client.Issues.CreateComment(ctx, owner, repo, prNumber, comment) return
if err != nil { } else {
log.Println("Error creating comment:", err) 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)
} }
} }
} }