idek a lot changed
This commit is contained in:
parent
8a8545ec63
commit
3dc5751b79
1 changed files with 32 additions and 21 deletions
53
bot/utils.go
53
bot/utils.go
|
@ -83,11 +83,15 @@ func webhookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
processIssuesEvent(event)
|
processIssuesEvent(event)
|
||||||
break
|
break
|
||||||
case *github.IssueCommentEvent:
|
case *github.IssueCommentEvent:
|
||||||
if !strings.Contains(event.GetComment().GetUser().GetLogin(), "bot") {
|
eventLogin := event.GetComment().GetUser().GetLogin()
|
||||||
|
commentBody := event.GetComment().GetBody()
|
||||||
|
|
||||||
|
if !strings.Contains(eventLogin, "bot") && strings.Contains(commentBody, "+1") {
|
||||||
log.Println("Received Issue Comment Event: processing now!")
|
log.Println("Received Issue Comment Event: processing now!")
|
||||||
processIssueCommentEvent(event)
|
processIssueCommentEvent(event)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
case *github.PullRequestEvent:
|
case *github.PullRequestEvent:
|
||||||
log.Println("Received Pull Request Event: processing now!")
|
log.Println("Received Pull Request Event: processing now!")
|
||||||
|
@ -123,9 +127,10 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
owner := event.GetRepo().GetOwner().GetLogin()
|
owner := event.GetRepo().GetOwner().GetLogin()
|
||||||
repo := event.GetRepo().GetName()
|
repo := event.GetRepo().GetName()
|
||||||
prNumber := event.GetIssue().GetNumber()
|
prNumber := event.GetIssue().GetNumber()
|
||||||
reactionCountGoal := 5
|
eventSender := event.GetSender().GetLogin()
|
||||||
|
|
||||||
var approvals = map[string]string{}
|
reactionCountGoal := 5
|
||||||
|
approvals := map[string]int{}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -138,25 +143,12 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
for _, comment := range comments {
|
for _, comment := range comments {
|
||||||
commentAuthor := comment.GetUser().GetLogin()
|
commentAuthor := comment.GetUser().GetLogin()
|
||||||
|
|
||||||
if strings.Contains(comment.GetBody(), "+1") && !strings.Contains(commentAuthor, "bot") {
|
if !strings.Contains(commentAuthor, "bot") {
|
||||||
_, exists := approvals[commentAuthor]
|
_, exists := approvals[commentAuthor]
|
||||||
if !exists {
|
if !exists {
|
||||||
approvals[commentAuthor] = commentAuthor
|
approvals[commentAuthor] = 1
|
||||||
} else {
|
} else {
|
||||||
commentText := "@(#{commentAuthor}) your vote has already been counted :x:"
|
approvals[commentAuthor]++
|
||||||
commentText = strings.Replace(commentText, "(#{commentAuthor})", commentAuthor, 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +179,7 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
commentText := "Votes: (#{reactionCount})/(#{reactionCountGoal})"
|
commentText := "Votes: (#{reactionCount})/(#{reactionCountGoal})"
|
||||||
commentText = strings.Replace(commentText, "(#{reactionCount})", strconv.Itoa(reactionCount), 1)
|
commentText = strings.Replace(commentText, "(#{reactionCount})", strconv.Itoa(len(approvals)), 1)
|
||||||
commentText = strings.Replace(commentText, "(#{reactionCountGoal})", strconv.Itoa(reactionCountGoal), 1)
|
commentText = strings.Replace(commentText, "(#{reactionCountGoal})", strconv.Itoa(reactionCountGoal), 1)
|
||||||
|
|
||||||
// Respond with a comment
|
// Respond with a comment
|
||||||
|
@ -200,17 +192,36 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
|
||||||
log.Println("Error creating comment:", err)
|
log.Println("Error creating comment:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if approvals[eventSender] > 1 {
|
||||||
|
commentText := "@(#{commentAuthor}) your vote has already been counted :x:"
|
||||||
|
commentText = strings.Replace(commentText, "(#{commentAuthor})", eventSender, 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func processPullRequestEvent(event *github.PullRequestEvent) {
|
func processPullRequestEvent(event *github.PullRequestEvent) {
|
||||||
|
owner := event.GetRepo().GetOwner().GetLogin()
|
||||||
|
repo := event.GetRepo().GetName()
|
||||||
|
prNumber := event.GetPullRequest().GetNumber()
|
||||||
|
|
||||||
if event.GetAction() == "opened" || event.GetAction() == "reopened" {
|
if event.GetAction() == "opened" || event.GetAction() == "reopened" {
|
||||||
// Respond with a comment
|
// Respond with a comment
|
||||||
comment := &github.IssueComment{
|
comment := &github.IssueComment{
|
||||||
Body: github.String("Comment on this PR with :+1: to vote for getting it merged!"),
|
Body: github.String("Comment on this PR with :+1: to vote for getting it merged!"),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err := client.Issues.CreateComment(ctx, event.GetRepo().GetOwner().GetLogin(), event.GetRepo().GetName(), event.GetPullRequest().GetNumber(), comment)
|
_, _, err := client.Issues.CreateComment(ctx, owner, repo, prNumber, comment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error creating comment:", err)
|
log.Println("Error creating comment:", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue