feat(workflow): configure review precision and approval on the review.pr step
This commit is contained in:
19 files changed
+107
-267
No files matched your search
@@ -8,18 +8,13 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/prreview"
|
||||
)
|
||||
|
||||
// The caller supplies a fresh context with operator approval disabled.
|
||||
type PRReviewDecision struct {
|
||||
Comments []prreview.ScoredFinding
|
||||
SkippedPhases []string
|
||||
}
|
||||
|
||||
// ReviewPullRequest refuses operator approval outright, so the gate is left
|
||||
// out of the stage list rather than reached and skipped.
|
||||
// ReviewPullRequest runs the decision stages, which have no operator gate.
|
||||
func ReviewPullRequest(ctx context.Context, tc *TaskContext) (PRReviewDecision, error) {
|
||||
if tc.Cfg.Review.ApproveBeforePost {
|
||||
return PRReviewDecision{}, fmt.Errorf("headless review cannot wait for operator approval")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctx, prReviewTotalBudget.WallClock)
|
||||
defer cancel()
|
||||
defer func() {
|
||||
|
||||
@@ -124,25 +124,25 @@ const prReviewConcurrency = 8
|
||||
// prReviewDecisionStages are the review stages without the operator gate, so
|
||||
// the implement workflow can run them before opening its PR.
|
||||
func prReviewDecisionStages() []Stage {
|
||||
return append(prReviewPipelineStages(), stagePRMergeGate())
|
||||
return append(prReviewPipelineStages(false), stagePRMergeGate())
|
||||
}
|
||||
|
||||
func prReviewStandaloneStages() []Stage {
|
||||
pipeline := prReviewPipelineStages()
|
||||
func prReviewStandaloneStages(s reviewPRSettings) []Stage {
|
||||
pipeline := prReviewPipelineStages(s.PrecisionGate)
|
||||
stages := make([]Stage, 0, len(pipeline)+3)
|
||||
stages = append(stages, pipeline...)
|
||||
return append(stages, stagePROperatorApproval(), stagePRMergeGate(), stagePROutput())
|
||||
return append(stages, stagePROperatorApproval(s.ApproveBeforePost), stagePRMergeGate(), stagePROutput())
|
||||
}
|
||||
|
||||
// prReviewPipelineStages is phases 1 through 7: intake through synthesis, the
|
||||
// stages every pr-review trigger shares.
|
||||
func prReviewPipelineStages() []Stage {
|
||||
func prReviewPipelineStages(precisionGate bool) []Stage {
|
||||
return []Stage{
|
||||
stagePRIntake(),
|
||||
stagePRAnatomy(),
|
||||
stagePRLenses(),
|
||||
stagePRReview(),
|
||||
stagePRPrecisionGate(),
|
||||
stagePRPrecisionGate(precisionGate),
|
||||
stagePRVerification(),
|
||||
stagePRCoverageConsistency(),
|
||||
stagePRSynthesis(),
|
||||
|
||||
@@ -39,12 +39,12 @@ func stagePRVerification() Stage {
|
||||
}}
|
||||
}
|
||||
|
||||
// stagePRPrecisionGate, when review.precision_gate is set, drops nitpicks,
|
||||
// stagePRPrecisionGate, when enabled, drops nitpicks,
|
||||
// style and unverifiable claims between review and verification, keeping a
|
||||
// finding when unsure. Off by default.
|
||||
func stagePRPrecisionGate() Stage {
|
||||
func stagePRPrecisionGate(enabled bool) Stage {
|
||||
return Stage{Name: "precision-gate", Run: func(ctx context.Context, tc *TaskContext) error {
|
||||
if !tc.Cfg.Review.PrecisionGate || len(tc.prReview.findings) == 0 {
|
||||
if !enabled || len(tc.prReview.findings) == 0 {
|
||||
return nil
|
||||
}
|
||||
if budgetExhausted(tc, "precision-gate") {
|
||||
@@ -130,12 +130,12 @@ func runPrecisionGate(ctx context.Context, tc *TaskContext, findings []prreview.
|
||||
return kept
|
||||
}
|
||||
|
||||
// stagePROperatorApproval, when review.approve_before_post is set, waits for
|
||||
// stagePROperatorApproval, when enabled, waits for
|
||||
// operator approval after synthesis and before the merge gate. A review with no
|
||||
// findings never waits. Setting tc.Outcome ends the run at this stage.
|
||||
func stagePROperatorApproval() Stage {
|
||||
func stagePROperatorApproval(enabled bool) Stage {
|
||||
return Stage{Name: "operator-approval", Run: func(_ context.Context, tc *TaskContext) error {
|
||||
if !tc.Cfg.Review.ApproveBeforePost || len(tc.prReview.scored) == 0 {
|
||||
if !enabled || len(tc.prReview.scored) == 0 {
|
||||
return nil
|
||||
}
|
||||
if tc.prReview.approvedReview != nil {
|
||||
|
||||
@@ -19,21 +19,29 @@ const (
|
||||
// ReviewStepTypes contributes the review step types.
|
||||
func ReviewStepTypes() []StepType {
|
||||
return []StepType{
|
||||
{Name: ReviewPRStepName, Factory: newReviewPRStage},
|
||||
{Name: ReviewPRStepName, Factory: newReviewPRStage, Settings: reviewPRSettings{}},
|
||||
{Name: ReviewRoundStepName, Factory: newReviewRoundStage},
|
||||
{Name: ReviewReplyStepName, Factory: newReviewReplyStage, Settings: reviewReplySettings{}},
|
||||
}
|
||||
}
|
||||
|
||||
// reviewPRSettings are off by default: the pipeline is recall-first and
|
||||
// posts automatically unless the workflow opts into either.
|
||||
type reviewPRSettings struct {
|
||||
PrecisionGate bool `yaml:"precision_gate" doc:"Drop findings not worth posting before verification."`
|
||||
ApproveBeforePost bool `yaml:"approve_before_post" doc:"Wait for operator approval before posting findings."`
|
||||
}
|
||||
|
||||
// newReviewPRStage runs the whole review pipeline on the task's pull request:
|
||||
// intake, anatomy, lenses, review, precision gate, verification, coverage,
|
||||
// synthesis, operator approval, merge gate and output. Its phases share
|
||||
// private state, so they run as one step.
|
||||
func newReviewPRStage(settings yaml.Node) (Stage, error) {
|
||||
if err := noSettings(ReviewPRStepName, settings); err != nil {
|
||||
s, err := decodeSettings[reviewPRSettings](ReviewPRStepName, settings)
|
||||
if err != nil {
|
||||
return Stage{}, err
|
||||
}
|
||||
phases := prReviewStandaloneStages()
|
||||
phases := prReviewStandaloneStages(s)
|
||||
return Stage{Name: ReviewPRStepName, Run: func(ctx context.Context, tc *TaskContext) error {
|
||||
for _, phase := range phases {
|
||||
if err := phase.Run(ctx, tc); err != nil {
|
||||
|
||||
Reference in new issue
Block a user