package approve_former import "fmt" const signTemplate = ` [[- if .parallel -]] - name: [[ .name ]] template: approval [[- if .when ]] when: "[[ .when ]]" [[- end -]] [[ else -]] - - name: [[ .name ]] template: approval [[- if .when ]] when: "[[ .when ]]" [[- end -]] [[- end -]] ` type Sign struct { Parallel bool // 如果为true,认为和上个节点并行执行,模板渲染为-。如果为false,和上个节点顺序执行,模板渲染为- - Name string } func NewParallelSign(name string) *Sign { return &Sign{ Parallel: true, Name: name, } } func NewSequenceSign(name string) *Sign { return &Sign{ Parallel: false, Name: name, } } func (sign *Sign) GetWhen() string { return fmt.Sprintf(`{{ steps.%s.outputs.parameters.front-json }} == 通过`, sign.Name) } func (sign *Sign) Render(upperNode Noder) (string, error) { if upperNode == nil { return render("sign", signTemplate, map[string]any{ "name": sign.Name, }) } return render("sign", signTemplate, map[string]any{ "parallel": sign.Parallel, "name": sign.Name, "when": upperNode.GetWhen(), }) }