diff --git a/changelog.d/fixed-approve-reply-tests-removed.md b/changelog.d/fixed-approve-reply-tests-removed.md new file mode 100644 index 0000000000..ace34e0684 --- /dev/null +++ b/changelog.d/fixed-approve-reply-tests-removed.md @@ -0,0 +1 @@ +- The `/hive approve` reply no longer promises that a trusted merger's Approve review will merge a contributor PR whose head edits CI workflow files and also removes tests; the lane stops such a head at `contributor-lane:tests-removed` regardless of approval, so the reply now says a maintainer must merge it manually. Message-only change. (#15034) diff --git a/src/pkg/github/automerge/pr_approve_command.go b/src/pkg/github/automerge/pr_approve_command.go index 46f3ade989..653a7cab21 100644 --- a/src/pkg/github/automerge/pr_approve_command.go +++ b/src/pkg/github/automerge/pr_approve_command.go @@ -85,7 +85,7 @@ func (c *Engine) PRApproveReply(ctx context.Context, displayRepo string, number if contributor { diffReason = contributorLaneDiffReason(files) } - if len(intent.HumanMergePathMatches(files, patterns)) == 0 && diffReason == contributorLaneReasonWorkflowPath && c.currentContributorLanePolicy().OwnerApprovalReleasesWorkflowFence { + if len(intent.HumanMergePathMatches(files, patterns)) == 0 && diffReason == contributorLaneReasonWorkflowPath && contributorLaneTestsRemovedReason(files) == "" && c.currentContributorLanePolicy().OwnerApprovalReleasesWorkflowFence { return "`/hive approve` acknowledged, but this PR edits CI workflow / action files, which the contributor lane merges only on a hive owner's explicit approval: a trusted merger submits a GitHub **Approve** review for the current head (`" + stagelabels.ShortSHA(head) + "`) or approves it from the Hive dashboard, and the lane merges once CI and the other gates are clear. Approval on an earlier head does not carry over.", nil } if len(intent.HumanMergePathMatches(files, patterns)) > 0 || diffReason != "" { diff --git a/src/pkg/github/automerge/pr_approve_command_test.go b/src/pkg/github/automerge/pr_approve_command_test.go index 2f03bb59b5..0eb446c9ea 100644 --- a/src/pkg/github/automerge/pr_approve_command_test.go +++ b/src/pkg/github/automerge/pr_approve_command_test.go @@ -104,3 +104,37 @@ func TestPRApproveReply(t *testing.T) { }) } } + +func TestPRApproveReplyWorkflowHeadThatRemovesTestsIsManualMerge(t *testing.T) { + api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/repos/acme/widget/pulls/7": + json.NewEncoder(w).Encode(&gh.PullRequest{Number: gh.Ptr(7), State: gh.Ptr("open"), User: &gh.User{Login: gh.Ptr("contributor")}, Head: &gh.PullRequestBranch{SHA: gh.Ptr("sha7")}}) + case "/repos/acme/widget/pulls/7/files": + json.NewEncoder(w).Encode([]*gh.CommitFile{ + {Filename: gh.Ptr(".github/workflows/ci.yml"), Status: gh.Ptr("modified")}, + {Filename: gh.Ptr("src/main_test.go"), Status: gh.Ptr("removed")}, + }) + default: + t.Errorf("unexpected read: %s", r.URL.Path) + w.WriteHeader(http.StatusNotFound) + } + })) + defer api.Close() + client := hgithub.NewClient("token", "acme", []string{"widget"}, nil, api.URL) + client.SetAppBotLogin(testHiveAppBotLogin) + e := New(client, Options{ + MergerAuthorizer: func(login string) bool { return login == "owner" }, + ContributorLanePolicy: func() ContributorLanePolicy { + return ContributorLanePolicy{Enabled: true, OwnerApprovalReleasesWorkflowFence: true} + }, + ContributorLaneVerdict: func(string, int, string) ContributorLaneVerdict { + return ContributorLaneVerdict{Configured: true, Verdict: "requires_human"} + }, + RepoAutoMergeEnabled: func(string) bool { return true }, + }) + reply, err := e.PRApproveReply(context.Background(), "acme/widget", 7, &gh.IssueComment{Body: gh.Ptr("/hive approve"), User: &gh.User{Login: gh.Ptr("owner"), Type: gh.Ptr("User")}}) + if err != nil || !strings.Contains(reply, "requires a person to merge manually") || strings.Contains(reply, "the lane merges once CI") { + t.Fatalf("reply=%q err=%v, want the generic manual-merge reply", reply, err) + } +}