From 268caa3d52f6d30fa87daab58ba0d186285ae064 Mon Sep 17 00:00:00 2001 From: okseby Date: Mon, 28 Aug 2023 16:48:51 -0400 Subject: [PATCH] Ok so PR's aren't working but I made it a little prettier. --- bot/utils.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bot/utils.go b/bot/utils.go index 4fbfda8..cffbfa2 100644 --- a/bot/utils.go +++ b/bot/utils.go @@ -11,7 +11,7 @@ import ( ) // Wrap the shared transport for use with the integration ID and authenticating with installation ID. -var itr, err = ghinstallation.NewKeyFromFile(http.DefaultTransport, 381312, 41105280, "theopenestsource.2023-08-26.private-key.pem") +var itr, _ = ghinstallation.NewKeyFromFile(http.DefaultTransport, 381312, 41105280, "theopenestsource.2023-08-26.private-key.pem") // Use installation transport with client. var client = github.NewClient(&http.Client{Transport: itr}) @@ -55,6 +55,8 @@ func webhookHandler(w http.ResponseWriter, r *http.Request) { panic(err) } + w.WriteHeader(200) + switch event := event.(type) { case *github.IssuesEvent: processIssuesEvent(event) @@ -65,6 +67,9 @@ func webhookHandler(w http.ResponseWriter, r *http.Request) { case *github.PullRequestReviewCommentEvent: processPullRequestReviewCommentEvent(event) break + default: + fmt.Println("Unhandled Event!") + break } } @@ -83,10 +88,10 @@ func processIssuesEvent(event *github.IssuesEvent) { } func processPullRequestEvent(event *github.PullRequestEvent) { - if event.GetAction() == "opened" { + if event.GetAction() == "opened" || event.GetAction() == "reopened" { // Respond with a comment comment := &github.IssueComment{ - Body: github.String("React to this comment with +1 to vote for getting it merged!"), + Body: github.String("React to this comment with :+1: to vote for getting it merged!"), } _, _, err := client.Issues.CreateComment(ctx, event.GetRepo().GetOwner().GetLogin(), event.GetRepo().GetName(), event.GetPullRequest().GetNumber(), comment) @@ -94,10 +99,6 @@ func processPullRequestEvent(event *github.PullRequestEvent) { log.Println("Error creating comment:", err) } } - - if event.GetAction() == "reaction" { - - } } func processPullRequestReviewCommentEvent(event *github.PullRequestReviewCommentEvent) {