sign.go 802 B

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