Skip to content

Commit

Permalink
Do not add do not merge label when PR is merged
Browse files Browse the repository at this point in the history
This commit fixes the issue described in #23205. Release note plugin
should not label the PR when it is already merged.

Signed-off-by: Jakub Guzik <jguzik@redhat.com>
  • Loading branch information
jmguzik committed Nov 24, 2021
1 parent 261259c commit febd708
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion prow/plugins/releasenote/releasenote.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func handlePR(gc githubClient, log *logrus.Entry, pr *github.PullRequestEvent) e
}
if containsNoneCommand(comments) {
labelToAdd = labels.ReleaseNoteNone
} else if !prLabels.Has(labels.ReleaseNoteLabelNeeded) {
} else if !prLabels.Has(labels.ReleaseNoteLabelNeeded) && !pr.PullRequest.Merged {
comment := plugins.FormatSimpleResponse(pr.PullRequest.User.Login, releaseNoteBody)
if err := gc.CreateComment(org, repo, pr.Number, comment); err != nil {
log.WithError(err).Errorf("Failed to comment on %s/%s#%d with comment %q.", org, repo, pr.Number, comment)
Expand Down
11 changes: 9 additions & 2 deletions prow/plugins/releasenote/releasenote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ func TestShouldHandlePR(t *testing.T) {
name string
action github.PullRequestEventAction
label string
pr github.PullRequest
expectedResult bool
}{
{
Expand All @@ -606,6 +607,11 @@ func TestShouldHandlePR(t *testing.T) {
label: "",
expectedResult: true,
},
{
name: "Pull Request Action: Release Note label not needed when PR merged",
pr: github.PullRequest{Merged: true},
expectedResult: false,
},
{
name: "Pull Request Action: Release Note label",
action: github.PullRequestActionLabeled,
Expand All @@ -621,13 +627,14 @@ func TestShouldHandlePR(t *testing.T) {
}

for _, test := range tests {
pr := github.PullRequestEvent{
pre := github.PullRequestEvent{
Action: test.action,
Label: github.Label{
Name: test.label,
},
PullRequest: test.pr,
}
result := shouldHandlePR(&pr)
result := shouldHandlePR(&pre)

if test.expectedResult != result {
t.Errorf("(%s): Expected value to be: %t, but got %t.", test.name, test.expectedResult, result)
Expand Down

0 comments on commit febd708

Please sign in to comment.