diff --git a/pr/webhook/pull_request.go b/pr/webhook/pull_request.go index b0a6b78..d1bde6a 100644 --- a/pr/webhook/pull_request.go +++ b/pr/webhook/pull_request.go @@ -116,7 +116,7 @@ func (receiver *Receiver) processPullRequest(event *github.PullRequestEvent) { if receiver.production { mentionSymbol = "@" } - if len(handles) > 0 && !strings.Contains(*event.PullRequest.Body, "[skip notification]") { + if len(handles) > 0 && (event.PullRequest.Body == nil || !strings.Contains(*event.PullRequest.Body, "[skip notification]")) { body := "Notifying maintainers:\n" for handle, ports := range handles { body += mentionSymbol + handle + " for port " + strings.Join(ports, ", ") + ".\n" @@ -177,13 +177,15 @@ func (receiver *Receiver) processPullRequest(event *github.PullRequestEvent) { if strings.Contains(strings.ToLower(*event.PullRequest.Title), ": update") || strings.HasPrefix(strings.ToLower(*event.PullRequest.Title), "update") { typeLabels = appendIfUnique(typeLabels, "type: update") } - if cveRegexp.FindString(*event.PullRequest.Title) != "" || cveRegexp.FindString(*event.PullRequest.Body) != "" { + if cveRegexp.FindString(*event.PullRequest.Title) != "" || (event.PullRequest.Body != nil && cveRegexp.FindString(*event.PullRequest.Body) != "") { typeLabels = appendIfUnique(typeLabels, "type: security fix") } - typesFromBody := []string{"bugfix", "enhancement", "security fix", "update"} - for _, t := range typesFromBody { - if strings.Contains(*event.PullRequest.Body, "[x] "+t) { - typeLabels = appendIfUnique(typeLabels, "type: "+t) + if event.PullRequest.Body != nil { + typesFromBody := []string{"bugfix", "enhancement", "security fix", "update"} + for _, t := range typesFromBody { + if strings.Contains(*event.PullRequest.Body, "[x] "+t) { + typeLabels = appendIfUnique(typeLabels, "type: "+t) + } } } diff --git a/pr/webhook/pull_request_test.go b/pr/webhook/pull_request_test.go index 1ff6a75..f3882a6 100644 --- a/pr/webhook/pull_request_test.go +++ b/pr/webhook/pull_request_test.go @@ -22,11 +22,15 @@ type PullRequestEventTest struct { number int sender string title string - body string + body *string comment string labels []string } +func addrof(s string) *string { + return &s; +} + func TestHandlePullRequest(t *testing.T) { stubClient := stubGitHubClient{} receiver := &Receiver{ @@ -61,13 +65,13 @@ func TestHandlePullRequest(t *testing.T) { } }`), &event) prTests := []*PullRequestEventTest{ - {number: 1, sender: "l2dy", title: "z: update to 1.1", labels: []string{"maintainer: none", "type: update", "by: member"}}, - {number: 1, sender: "jverne", title: "z: update to 1.1", body: "[x] enhancement", labels: []string{"maintainer: none", "type: update", "type: enhancement"}}, - {number: 1, sender: "jverne", title: "z: update to 1.1", body: "Fixes CVE-0000-0.", labels: []string{"maintainer: none", "type: update", "type: security fix"}}, + {number: 1, sender: "l2dy", title: "z: update to 1.1", body: nil, labels: []string{"maintainer: none", "type: update", "by: member"}}, + {number: 1, sender: "jverne", title: "z: update to 1.1", body: addrof("[x] enhancement"), labels: []string{"maintainer: none", "type: update", "type: enhancement"}}, + {number: 1, sender: "jverne", title: "z: update to 1.1", body: addrof("Fixes CVE-0000-0."), labels: []string{"maintainer: none", "type: update", "type: security fix"}}, {number: 2, sender: "jverne", title: "upx-devel: new port", labels: []string{"type: submission"}}, {number: 3, sender: "l2dy", title: "upx: update to 1.1", labels: []string{"maintainer", "maintainer: open", "type: update", "by: member"}}, {number: 3, sender: "jverne", title: "upx: update to 1.1", comment: "Notifying maintainers:\n@_l2dy for port upx.\n", labels: []string{"maintainer: open", "type: update"}}, - {number: 3, sender: "jverne", title: "upx: update to 1.1", body: "", labels: []string{"maintainer: open", "type: update"}}, + {number: 3, sender: "jverne", title: "upx: update to 1.1", body: addrof(""), labels: []string{"maintainer: open", "type: update"}}, } for _, prt := range prTests { stubClient.newComment = "" @@ -75,7 +79,7 @@ func TestHandlePullRequest(t *testing.T) { event.Number = &prt.number event.Sender.Login = &prt.sender event.PullRequest.Title = &prt.title - event.PullRequest.Body = &prt.body + event.PullRequest.Body = prt.body eventBody, err := json.Marshal(event) if err != nil { t.Error(err)