template.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "strings"
  4. )
  5. func JobName(template, label string) string {
  6. switch template {
  7. case "__bazel_build_job_name__":
  8. return strings.Replace(label, "/", "-", -1) + "-bazel-build"
  9. case "__bazel_test_job_name__":
  10. return strings.Replace(label, "/", "-", -1) + "-bazel-test"
  11. case "__go_linter_job_name__":
  12. return strings.Replace(label, "/", "-", -1) + "-lint"
  13. default:
  14. return strings.Replace(label, "/", "-", -1)
  15. }
  16. }
  17. func JobBazelPath(result, label string) string {
  18. if strings.Contains(label, "tool/") ||
  19. strings.Contains(label, "admin/") ||
  20. strings.Contains(label, "common/") ||
  21. strings.Contains(label, "infra/") ||
  22. strings.Contains(label, "interface/") ||
  23. strings.Contains(label, "job/") ||
  24. strings.Contains(label, "service/") ||
  25. strings.Contains(label, "tool/") {
  26. return strings.Replace(result, "<<bazel_dir_param>>", "app/"+label, -1)
  27. } else {
  28. if strings.Contains(label, "library/") {
  29. return strings.Replace(result, "<<bazel_dir_param>>", label, -1)
  30. } else {
  31. return "app"
  32. }
  33. }
  34. }
  35. func JobImage(template string) string {
  36. image, ok := GlobalStatue.Image[template]
  37. if ok {
  38. return image
  39. }
  40. return ""
  41. }
  42. func Trigger(triagger, label string) string {
  43. if strings.Contains(triagger, "__bazel_build_job_name__") {
  44. return strings.Replace(triagger, "__bazel_build_job_name__", strings.Replace(label, "/", "-", -1)+"-build", -1)
  45. }
  46. if strings.Contains(triagger, "__bazel_test_job_name__") {
  47. return strings.Replace(triagger, "__bazel_test_job_name__", strings.Replace(label, "/", "-", -1)+"-test", -1)
  48. }
  49. if strings.Contains(triagger, "__go_linter_job_name__") {
  50. return strings.Replace(triagger, "__go_linter_job_name__", strings.Replace(label, "/", "-", -1)+"-lint", -1)
  51. }
  52. return triagger
  53. }