package workflow import ( "context" "fmt" "os" "github.com/samcharles93/archie-core/internal/domain/workflow/prreview" ) type PRReviewDecision struct { Comments []prreview.ScoredFinding SkippedPhases []string } // ReviewPullRequest runs the decision stages, which have no operator gate. func ReviewPullRequest(ctx context.Context, tc *TaskContext) (PRReviewDecision, error) { ctx, cancel := context.WithTimeout(ctx, prReviewTotalBudget.WallClock) defer cancel() defer removePRSnapshot(tc) for _, stage := range prReviewDecisionStages() { if err := ctx.Err(); err != nil { return PRReviewDecision{}, err } if err := stage.Run(ctx, tc); err != nil { return PRReviewDecision{}, fmt.Errorf("pr-review %s: %w", stage.Name, err) } if tc.Outcome.Status != "" { return PRReviewDecision{}, fmt.Errorf("pr-review stopped: %s", tc.Outcome.Detail) } } if err := ctx.Err(); err != nil { return PRReviewDecision{}, err } if failed := tc.prReview.reviewerFailures.Load(); failed != 0 { return PRReviewDecision{}, fmt.Errorf("pr-review: %d reviewer(s) did not finish", failed) } return PRReviewDecision{ Comments: tc.prReview.scored, SkippedPhases: append([]string(nil), tc.prReview.skippedPhases...), }, nil } // removePRSnapshot deletes the snapshot anatomy materialized. Every runner of // the pr-review phases defers it, since any phase may end the run early. func removePRSnapshot(tc *TaskContext) { if tc.prReview != nil && tc.prReview.snapshotDir != "" { _ = os.RemoveAll(tc.prReview.snapshotDir) } }