Skip to content

Commit 9b39fcc

Browse files
author
Lukas Matt
committed
Fix nil pointer and register webhook with json response
1 parent 39bbc8e commit 9b39fcc

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

frontend.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func frontend(w http.ResponseWriter, r *http.Request) {
6060
hook := github.Hook{
6161
Name: &name, Events: []string{"pull_request"},
6262
Config: map[string]interface{}{
63+
"content_type": "json",
6364
"url": serverDomain + "/hook",
6465
"secret": secret,
6566
},
@@ -80,8 +81,15 @@ func frontend(w http.ResponseWriter, r *http.Request) {
8081
return
8182
}
8283

83-
fmt.Fprintf(w, `Success :) You can undo it by simply deleting the
84-
<a href="https://github.com/%s/settings/hooks">webhook</a>.`, repo)
84+
fmt.Fprintf(w, `<!DOCTYPE html>
85+
<html>
86+
<body>
87+
<p>
88+
Success :) You can undo it by simply deleting the
89+
<a href="https://github.com/%s/settings/hooks">webhook</a>.
90+
</p>
91+
</body>
92+
</html>`, repo)
8593
return
8694
}
8795

webhook.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ func webhook(w http.ResponseWriter, r *http.Request) {
3636

3737
var event github.PullRequestReviewEvent
3838
err = json.Unmarshal(b, &event)
39-
if err != nil {
39+
pr := event.PullRequest
40+
if err != nil || pr == nil {
4041
logger.Println("Not supported event type", string(b))
4142
fmt.Fprintf(w, `{"error":"unsupported event type"}`)
4243
return
4344
}
44-
pr := event.PullRequest
45+
46+
// skip all events except for open PRs
4547
if *pr.State != "open" {
4648
logger.Println("Ignore closed pull request")
4749
fmt.Fprintf(w, `{}`)

0 commit comments

Comments
 (0)