sign.go 861 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package approve_former
  2. import "fmt"
  3. const signTemplate = `- name: [[ .name ]]
  4. template: approval
  5. [[- if .depends ]]
  6. depends: "[[ .depends ]]"
  7. [[- end ]]
  8. [[- if .when ]]
  9. when: "[[ .when ]]"
  10. [[- end -]]`
  11. type Sign struct {
  12. Name string
  13. }
  14. func NewSign(name string) *Sign {
  15. return &Sign{
  16. Name: name,
  17. }
  18. }
  19. func (sign *Sign) GetDepends() string {
  20. return fmt.Sprintf("%s.Succeeded", sign.Name)
  21. }
  22. func (sign *Sign) GetWhen() string {
  23. return fmt.Sprintf(`{{ tasks.%s.outputs.parameters.approve }} == 通过`, sign.Name)
  24. }
  25. func (sign *Sign) Render(upperNode Node) (string, error) {
  26. if upperNode == nil {
  27. return render("sign", signTemplate, map[string]any{
  28. "name": sign.Name,
  29. })
  30. }
  31. return render("sign", signTemplate, map[string]any{
  32. "name": sign.Name,
  33. "depends": upperNode.GetDepends(),
  34. "when": upperNode.GetWhen(),
  35. })
  36. }