Share review stage eligibility between advancement and completion
This commit is contained in:
+32
-26
@@ -129,22 +129,40 @@ func (m *Manager) reviewsSettled(ctx context.Context, reviews []api.Review) (boo
|
||||
if len(def.Steps) == 0 {
|
||||
continue
|
||||
}
|
||||
for _, next := range workflow.Next(def, r.Stage) {
|
||||
if _, found := byStage[next]; found {
|
||||
continue
|
||||
}
|
||||
ready := true
|
||||
for _, a := range workflow.After(def, next) {
|
||||
ready = ready && byStage[a].State == api.ReviewStateDone
|
||||
}
|
||||
if ready {
|
||||
return false, nil
|
||||
}
|
||||
if len(pendingReviewStages(def, r.Stage, byStage)) > 0 {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
type pendingReviewStage struct {
|
||||
name string
|
||||
inputs []api.Review
|
||||
}
|
||||
|
||||
func pendingReviewStages(def api.WorkflowDefinition, stage string, byStage map[string]api.Review) []pendingReviewStage {
|
||||
pending := []pendingReviewStage{}
|
||||
for _, next := range workflow.Next(def, stage) {
|
||||
if _, found := byStage[next]; found {
|
||||
continue
|
||||
}
|
||||
inputs := []api.Review{}
|
||||
after := workflow.After(def, next)
|
||||
for _, a := range after {
|
||||
in := byStage[a]
|
||||
if in.State != api.ReviewStateDone {
|
||||
break
|
||||
}
|
||||
inputs = append(inputs, in)
|
||||
}
|
||||
if len(inputs) == len(after) {
|
||||
pending = append(pending, pendingReviewStage{name: next, inputs: inputs})
|
||||
}
|
||||
}
|
||||
return pending
|
||||
}
|
||||
|
||||
func (m *Manager) snapshotReviews(ctx context.Context, taskID string, n int) ([]api.Review, error) {
|
||||
reviews, err := m.store.ListReviews(ctx, taskID)
|
||||
if err != nil {
|
||||
@@ -261,22 +279,10 @@ func (m *Manager) advanceReviews(ctx context.Context, r api.Review) bool {
|
||||
}
|
||||
|
||||
started := false
|
||||
for _, next := range workflow.Next(def, r.Stage) {
|
||||
if _, found := byStage[next]; found {
|
||||
continue
|
||||
}
|
||||
inputs := []api.Review{}
|
||||
for _, a := range workflow.After(def, next) {
|
||||
if in, found := byStage[a]; found && in.State == api.ReviewStateDone {
|
||||
inputs = append(inputs, in)
|
||||
}
|
||||
}
|
||||
if len(inputs) != len(workflow.After(def, next)) {
|
||||
continue
|
||||
}
|
||||
err = m.startReviewer(ctx, task, project, snap, defID, def, next, inputs)
|
||||
for _, next := range pendingReviewStages(def, r.Stage, byStage) {
|
||||
err = m.startReviewer(ctx, task, project, snap, defID, def, next.name, next.inputs)
|
||||
if err != nil {
|
||||
slog.Error("start review stage", "task", task.Id, "snapshot", r.SnapshotN, "stage", next, "err", err)
|
||||
slog.Error("start review stage", "task", task.Id, "snapshot", r.SnapshotN, "stage", next.name, "err", err)
|
||||
continue
|
||||
}
|
||||
started = true
|
||||
|
||||
Reference in New Issue
Block a user