Merge pull request #31 from rowbawts/dev

Merging based on reactions
This commit is contained in:
openest-source-bot[bot] 2023-08-29 03:21:41 +00:00 committed by GitHub
commit 7d36f5cad1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

View file

@ -44,7 +44,12 @@ func listenForWebhook() {
} }
func webHandle(w http.ResponseWriter, r *http.Request) { func webHandle(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Turn back!") _, err := fmt.Fprintf(w, "Turn back!")
if err != nil {
return
}
log.Println("Request received to / endpoint:", r)
} }
func webhookHandler(w http.ResponseWriter, r *http.Request) { func webhookHandler(w http.ResponseWriter, r *http.Request) {
@ -58,21 +63,26 @@ func webhookHandler(w http.ResponseWriter, r *http.Request) {
panic(err) panic(err)
} }
w.WriteHeader(200)
switch event := event.(type) { switch event := event.(type) {
case *github.IssuesEvent: case *github.IssuesEvent:
log.Println("Received Issues Event: processing now!")
processIssuesEvent(event) processIssuesEvent(event)
break break
case *github.IssueCommentEvent: case *github.IssueCommentEvent:
if !strings.Contains(event.GetComment().GetUser().GetLogin(), "bot") { if !strings.Contains(event.GetComment().GetUser().GetLogin(), "bot") {
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!")
processPullRequestEvent(event) processPullRequestEvent(event)
break break
default: default:
fmt.Println("Unhandled Event!") log.Println("Received Unhandled Event!")
break break
} }
} }
@ -143,7 +153,7 @@ func processIssueCommentEvent(event *github.IssueCommentEvent) {
return return
} else { } else {
commentText := "Votes: (#{reactionCount})/(#{reactionRemainingCount})" commentText := "Votes: (#{reactionCount}) Needed: (#{reactionRemainingCount})"
commentText = strings.Replace(commentText, "(#{reactionCount})", strconv.Itoa(reactionCount), 1) commentText = strings.Replace(commentText, "(#{reactionCount})", strconv.Itoa(reactionCount), 1)
commentText = strings.Replace(commentText, "(#{reactionRemainingCount})", strconv.Itoa(reactionCountGoal-reactionCount), 1) commentText = strings.Replace(commentText, "(#{reactionRemainingCount})", strconv.Itoa(reactionCountGoal-reactionCount), 1)