-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues.go
64 lines (56 loc) · 1.26 KB
/
issues.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package util
import (
// Internal
"github.com/salsaflow/salsaflow-daemon/internal/modules/issuetracking/github/config"
// Vendor
"github.com/google/go-github/github"
)
func ReplaceWorkflowLabels(
client *github.Client,
owner string,
repo string,
issue *github.Issue,
add []string,
keep []string,
) error {
// Get the list of labels to be used.
shouldKeep := func(label string) bool {
for _, keepName := range keep {
if keepName == label {
return true
}
}
return false
}
c := config.Get()
labelNames := make([]string, 0, len(issue.Labels)+len(add))
labelNames = append(labelNames, add...)
for _, label := range issue.Labels {
name := *label.Name
if shouldKeep(name) {
labelNames = append(labelNames, name)
continue
}
switch name {
case c.ApprovedLabel:
case c.BeingImplementedLabel:
case c.ImplementedLabel:
case c.ReviewedLabel:
case c.SkipReviewLabel:
case c.PassedTestingLabel:
case c.FailedTestingLabel:
case c.SkipTestingLabel:
case c.StagedLabel:
case c.RejectedLabel:
default:
labelNames = append(labelNames, name)
}
}
// Replace the labels.
ls, _, err := client.Issues.ReplaceLabelsForIssue(owner, repo, *issue.Number, labelNames)
if err != nil {
return err
}
issue.Labels = ls
return nil
}