helpers.go 781 B

12345678910111213141516171819202122232425262728293031323334
  1. package gitserver
  2. import (
  3. "strings"
  4. )
  5. // HasLabel checks if label is in the label set "issueLabels".
  6. func HasLabel(label string, issueLabels []Label) bool {
  7. for _, l := range issueLabels {
  8. if strings.ToLower(l.Name) == strings.ToLower(label) {
  9. return true
  10. }
  11. }
  12. return false
  13. }
  14. // ChangedLabels describe a gitlab PR changed labels
  15. func ChangedLabels(action PullRequestEventAction, previous, current []Label) []Label {
  16. labels := make([]Label, 0)
  17. if action == PullRequestActionLabeled {
  18. for _, l := range current {
  19. if !HasLabel(l.Name, previous) {
  20. labels = append(labels, l)
  21. }
  22. }
  23. } else if action == PullRequestActionUnlabeled {
  24. for _, l := range previous {
  25. if !HasLabel(l.Name, current) {
  26. labels = append(labels, l)
  27. }
  28. }
  29. }
  30. return labels
  31. }