Drop workflow kinds, deliver reviews when done, rename/delete workflows
This commit is contained in:
@@ -53,26 +53,10 @@ func Validate(def api.WorkflowDefinition) error {
|
||||
if len(def.Steps) == 0 {
|
||||
problems = append(problems, "it has no steps")
|
||||
}
|
||||
if def.Kind != "" && !def.Kind.Valid() {
|
||||
problems = append(problems, fmt.Sprintf("kind must be task or review, not %q", def.Kind))
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for i, s := range def.Steps {
|
||||
problems = append(problems, stepProblems(s, fmt.Sprintf("steps[%d]", i), seen)...)
|
||||
}
|
||||
if def.Kind == api.WorkflowKindReview {
|
||||
for _, s := range Stages(def) {
|
||||
if s.Agents != nil {
|
||||
problems = append(problems, fmt.Sprintf("stage %q: a review workflow's stages are single reviewers, so agents can't be given", s.Stage))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(problems) == 0 && def.Kind != api.WorkflowKindReview {
|
||||
finals := ends(api.WorkflowStep{Order: &def.Steps})
|
||||
if len(finals) != 1 {
|
||||
problems = append(problems, fmt.Sprintf("it must end with one stage, which finishes the workflow, but ends with %d: %s", len(finals), quoteList(finals)))
|
||||
}
|
||||
}
|
||||
if len(problems) > 0 {
|
||||
return fmt.Errorf("%w: %s", ErrInvalid, strings.Join(problems, "; "))
|
||||
}
|
||||
@@ -161,6 +145,10 @@ func TeamProblems(members []api.TeamMember) []string {
|
||||
return problems
|
||||
}
|
||||
|
||||
func Ends(def api.WorkflowDefinition) []string {
|
||||
return ends(api.WorkflowStep{Order: &def.Steps})
|
||||
}
|
||||
|
||||
func ends(s api.WorkflowStep) []string {
|
||||
switch {
|
||||
case s.Order != nil:
|
||||
@@ -246,11 +234,3 @@ func Starts(def api.WorkflowDefinition) []string {
|
||||
func FromMain(def api.WorkflowDefinition, name string) bool {
|
||||
return len(After(def, name)) > 1
|
||||
}
|
||||
|
||||
func quoteList(names []string) string {
|
||||
quoted := []string{}
|
||||
for _, n := range names {
|
||||
quoted = append(quoted, fmt.Sprintf("%q", n))
|
||||
}
|
||||
return strings.Join(quoted, ", ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user