Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/changed-15385.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- chore(stageengine): share decision-cause prose between automerge and goldens test (#15384, #15385)
31 changes: 31 additions & 0 deletions src/pkg/github/automerge/automerge_decision_cause_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package automerge

import (
"testing"

"github.com/hivecommons/hive/pkg/stageengine/prstage"
)

// The stage goldens render the same prose from prstage; a reworded cause here
// that skips prstage would drift from them (hivecommons/hive#15384).
func TestDecisionCauseUsesSharedProse(t *testing.T) {
for _, tc := range []struct{ reason, want string }{
{contributorLaneReasonTestsRemoved, prstage.CauseTestsRemoved},
{contributorLaneReasonReporterTrustHold, prstage.CauseReporterTrustHold},
{autoMergeReasonHumanMergePath, prstage.CauseHumanMergePath},
{autoMergeReasonIntentUnauthorized, prstage.CauseIntentUnauthorized},
{"approval-desk-withheld", prstage.CauseApprovalDeskWithheld},
{contributorLaneReasonWorkflowPath, prstage.CauseWorkflowPathManual},
{workflowApprovalUntrustedPrefix, prstage.CauseWorkflowApprovalUntrusted()},
{workflowApprovalWorkflowMissingPrefix, prstage.CauseWorkflowApprovalWorkflowMissing()},
{workflowApprovalRequiredPrefix, prstage.CauseWorkflowApprovalRequired()},
{"something-new", prstage.CauseLaneReported("something-new")},
} {
if got := decisionCause(tc.reason); got != tc.want {
t.Errorf("decisionCause(%q) = %q, want %q", tc.reason, got, tc.want)
}
}
if got := decisionCauseFor(contributorLaneReasonWorkflowPath, false); got != prstage.CauseWorkflowPathAwaitingApproval {
t.Errorf("decisionCauseFor(workflow-path, false) = %q, want the awaiting-approval cause", got)
}
}
23 changes: 12 additions & 11 deletions src/pkg/github/automerge/automerge_stage_human.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
hgithub "github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/oktotest"
"github.com/hivecommons/hive/pkg/stageengine"
"github.com/hivecommons/hive/pkg/stageengine/prstage"
"github.com/hivecommons/hive/pkg/stagelabels"
)

Expand Down Expand Up @@ -364,9 +365,9 @@ func decisionCause(reason string) string {
// owner's explicit approval (hivecommons/hive#14664).
func workflowPathCause(workflowManual bool) string {
if workflowManual {
return "the PR edits CI workflow / action files, which the lane never merges unattended"
return prstage.CauseWorkflowPathManual
}
return "the PR edits CI workflow / action files: awaiting owner approval — a hive owner / trusted merger's GitHub **Approve** review on the current head (or a dashboard `/hive decision approve`) releases the fence and the hive merges it; approval on an earlier head does not count, so re-approve after a push"
return prstage.CauseWorkflowPathAwaitingApproval
}

// decisionCauseFor is decisionCause with the workflow-path fence's standing
Expand All @@ -379,37 +380,37 @@ func decisionCauseFor(reason string, workflowManual bool) string {
case reason == contributorLaneReasonWorkflowPath:
return workflowPathCause(workflowManual)
case reason == contributorLaneReasonTestsRemoved:
return "the PR removes tests, which the lane never merges unattended"
return prstage.CauseTestsRemoved
case strings.HasPrefix(reason, stageReasonForkGuard):
// RouteHuman names the fork-guard checks from the evidence.
return ""
case reason == contributorLaneReasonNoReviewer, reason == stageReasonVerdictRequiresHuman, reason == stageReasonDecisionRequested:
// RouteHuman renders the verdict itself from the evidence.
return ""
case reason == contributorLaneReasonReporterTrustHold:
return "the reporter-trust hold is in place"
return prstage.CauseReporterTrustHold
case reason == autoMergeReasonHumanMergePath, reason == autoMergeReasonHumanMergePathEvidence:
return "the PR touches a human-merge path (auto_merge.human_merge_paths)"
return prstage.CauseHumanMergePath
case reason == autoMergeReasonIntentUnauthorized, reason == autoMergeReasonIntentEvidence:
return "the merge intent could not be authorized"
return prstage.CauseIntentUnauthorized
case strings.HasPrefix(reason, workflowApprovalUntrustedPrefix):
return "GitHub Actions is holding the workflow runs for approval and Hive cannot start them: `" + workflowApprovalCommand + "` on this repository belongs to Prow, which does not trust the Hive App. A maintainer must comment `" + workflowApprovalCommand + "` (and `/lgtm` + `/approve` for tide), or install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) so the repository GITHUB_TOKEN approves trusted same-repo bot runs on Hive's command."
return prstage.CauseWorkflowApprovalUntrusted()
case strings.HasPrefix(reason, workflowApprovalWorkflowMissingPrefix):
return "GitHub Actions is still waiting after Hive posted `" + workflowApprovalCommand + "`. Install the self-contained `" + oktotest.WorkflowPath + "` below (or render it with `hivectl ok-to-test-template`) so the repository GITHUB_TOKEN can approve trusted same-repo bot runs, or manually approve the runs from the PR checks banner."
return prstage.CauseWorkflowApprovalWorkflowMissing()
case strings.HasPrefix(reason, unauthorizedReasonPrefix):
return "the hive's GitHub App is not permitted to " + strings.ReplaceAll(strings.TrimPrefix(reason, unauthorizedReasonPrefix), "-", " ") + " (GitHub answered 403 Resource not accessible by integration); the `" + unauthorizedLabel + "` note above names the permission and the step a maintainer must take"
case strings.HasPrefix(reason, workflowApprovalRequiredPrefix):
return "GitHub Actions is waiting for workflow approval. Hive posted `" + workflowApprovalCommand + "`; install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) if the runs do not start, or manually approve them from the PR checks banner."
return prstage.CauseWorkflowApprovalRequired()
case reason == "approval-desk-withheld":
return "the approval desk withheld this merge"
return prstage.CauseApprovalDeskWithheld
case reason == autoMergeReasonMergeRefusedReview:
return "GitHub refused the merge: branch protection requires an approving review from someone with write access, and the Hive App cannot give it. A GitHub **Approve** review on this head (or an App bypass in the branch rules) lets the hive merge it; the hive retries once GitHub reports the PR unblocked, or within 30 minutes"
case reason == autoMergeReasonMergeRefusedMethod:
return "GitHub refused the merge: the repository does not allow the merge method the hive chose for this PR. The hive does not switch methods on its own: a forward merge or a `" + stagelabels.MergeCommitLabel + "` PR must never be squashed. Merge it by hand with an allowed method, or allow the method in the repository settings and the hive retries within 30 minutes"
case reason == "":
return ""
}
return "the lane reported `" + reason + "`"
return prstage.CauseLaneReported(reason)
}

// postHumanEntry writes the 085 / 090 entry comment once per stage visit,
Expand Down
47 changes: 47 additions & 0 deletions src/pkg/stageengine/prstage/causes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package prstage

import "github.com/hivecommons/hive/pkg/oktotest"

// WorkflowApprovalCommand is the comment the hive posts to have the
// repository's ok-to-test workflow approve held workflow runs.
const WorkflowApprovalCommand = "/ok-to-test"

// Decision causes: the prose the 085 comment gives for a non-trust
// human-only lane reason. The automerge sweep renders them and the stage
// goldens expect them, so the wording lives here once (hivecommons/hive#15384).
const (
CauseTestsRemoved = "the PR removes tests, which the lane never merges unattended"
CauseReporterTrustHold = "the reporter-trust hold is in place"
CauseHumanMergePath = "the PR touches a human-merge path (auto_merge.human_merge_paths)"
CauseIntentUnauthorized = "the merge intent could not be authorized"
CauseApprovalDeskWithheld = "the approval desk withheld this merge"
// CauseWorkflowPathManual is the workflow-path fence read as a rule a
// person merges around.
CauseWorkflowPathManual = "the PR edits CI workflow / action files, which the lane never merges unattended"
// CauseWorkflowPathAwaitingApproval is the same fence awaiting the
// owner's explicit approval (hivecommons/hive#14664).
CauseWorkflowPathAwaitingApproval = "the PR edits CI workflow / action files: awaiting owner approval — a hive owner / trusted merger's GitHub **Approve** review on the current head (or a dashboard `/hive decision approve`) releases the fence and the hive merges it; approval on an earlier head does not count, so re-approve after a push"
)

// CauseWorkflowApprovalUntrusted is the cause when the repository's
// ok-to-test command belongs to Prow, which does not trust the Hive App.
func CauseWorkflowApprovalUntrusted() string {
return "GitHub Actions is holding the workflow runs for approval and Hive cannot start them: `" + WorkflowApprovalCommand + "` on this repository belongs to Prow, which does not trust the Hive App. A maintainer must comment `" + WorkflowApprovalCommand + "` (and `/lgtm` + `/approve` for tide), or install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) so the repository GITHUB_TOKEN approves trusted same-repo bot runs on Hive's command."
}

// CauseWorkflowApprovalWorkflowMissing is the cause when runs stay held after
// the hive posted the command and the repository has no ok-to-test workflow.
func CauseWorkflowApprovalWorkflowMissing() string {
return "GitHub Actions is still waiting after Hive posted `" + WorkflowApprovalCommand + "`. Install the self-contained `" + oktotest.WorkflowPath + "` below (or render it with `hivectl ok-to-test-template`) so the repository GITHUB_TOKEN can approve trusted same-repo bot runs, or manually approve the runs from the PR checks banner."
}

// CauseWorkflowApprovalRequired is the cause when runs are held and the hive
// has just posted the command.
func CauseWorkflowApprovalRequired() string {
return "GitHub Actions is waiting for workflow approval. Hive posted `" + WorkflowApprovalCommand + "`; install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) if the runs do not start, or manually approve them from the PR checks banner."
}

// CauseLaneReported is the fallback cause naming an unrecognised lane reason.
func CauseLaneReported(reason string) string {
return "the lane reported `" + reason + "`"
}
23 changes: 11 additions & 12 deletions src/pkg/stageengine/stage_goldens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"time"

"github.com/hivecommons/hive/pkg/authorkind"
"github.com/hivecommons/hive/pkg/oktotest"
"github.com/hivecommons/hive/pkg/stageengine/prstage"
"github.com/hivecommons/hive/pkg/stagelabels"
)

Expand Down Expand Up @@ -1080,30 +1080,30 @@ func decisionCause(reason string) string {
strings.HasPrefix(reason, "excluded-label:"), reason == "sentinel", reason == contributorLaneReasonSentinelBlocked:
return ""
case reason == contributorLaneReasonWorkflowPath:
return "the PR edits CI workflow / action files, which the lane never merges unattended"
return prstage.CauseWorkflowPathManual
case reason == contributorLaneReasonTestsRemoved:
return "the PR removes tests, which the lane never merges unattended"
return prstage.CauseTestsRemoved
case reason == contributorLaneReasonNoReviewer, reason == StageReasonVerdictRequiresHuman, reason == StageReasonDecisionRequested:
// RouteHuman renders the verdict itself from the evidence.
return ""
case reason == contributorLaneReasonReporterTrustHold:
return "the reporter-trust hold is in place"
return prstage.CauseReporterTrustHold
case reason == autoMergeReasonHumanMergePath, reason == autoMergeReasonHumanMergePathEvidence:
return "the PR touches a human-merge path (auto_merge.human_merge_paths)"
return prstage.CauseHumanMergePath
case reason == autoMergeReasonIntentUnauthorized, reason == autoMergeReasonIntentEvidence:
return "the merge intent could not be authorized"
return prstage.CauseIntentUnauthorized
case strings.HasPrefix(reason, workflowApprovalUntrustedPrefix):
return "GitHub Actions is holding the workflow runs for approval and Hive cannot start them: `" + workflowApprovalCommand + "` on this repository belongs to Prow, which does not trust the Hive App. A maintainer must comment `" + workflowApprovalCommand + "` (and `/lgtm` + `/approve` for tide), or install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) so the repository GITHUB_TOKEN approves trusted same-repo bot runs on Hive's command."
return prstage.CauseWorkflowApprovalUntrusted()
case strings.HasPrefix(reason, workflowApprovalWorkflowMissingPrefix):
return "GitHub Actions is still waiting after Hive posted `" + workflowApprovalCommand + "`. Install the self-contained `" + oktotest.WorkflowPath + "` below (or render it with `hivectl ok-to-test-template`) so the repository GITHUB_TOKEN can approve trusted same-repo bot runs, or manually approve the runs from the PR checks banner."
return prstage.CauseWorkflowApprovalWorkflowMissing()
case strings.HasPrefix(reason, workflowApprovalRequiredPrefix):
return "GitHub Actions is waiting for workflow approval. Hive posted `" + workflowApprovalCommand + "`; install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) if the runs do not start, or manually approve them from the PR checks banner."
return prstage.CauseWorkflowApprovalRequired()
case reason == "approval-desk-withheld":
return "the approval desk withheld this merge"
return prstage.CauseApprovalDeskWithheld
case reason == "":
return ""
}
return "the lane reported `" + reason + "`"
return prstage.CauseLaneReported(reason)
}

var humanConflictReasons = map[string]bool{"conflicting": true, "not-mergeable": true, "label:needs-rebase": true}
Expand Down Expand Up @@ -1131,4 +1131,3 @@ func dcoState(total, unsigned int) stagelabels.DCOState {
const contributorLaneReasonRegistryTrusted = "contributor-lane:" + "registry-trusted"
const workflowApprovalUntrustedPrefix = "workflow-approval-required:untrusted-commenter:"
const workflowApprovalWorkflowMissingPrefix = "workflow-approval-required:missing-workflow:"
const workflowApprovalCommand = "/ok-to-test"
Loading