-
Notifications
You must be signed in to change notification settings - Fork 0
/
story.go
80 lines (70 loc) · 2.02 KB
/
story.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package tracker
import (
// Stdlib
"fmt"
// Internal
githubutil "github.com/salsaflow/salsaflow-daemon/internal/github"
"github.com/salsaflow/salsaflow-daemon/internal/modules/issuetracking/github/config"
"github.com/salsaflow/salsaflow-daemon/internal/modules/issuetracking/github/util"
// Vendor
"github.com/google/go-github/github"
)
type commonStory struct {
client *github.Client
issue *github.Issue
owner string
repo string
}
func (s *commonStory) OnReviewRequestOpened(rrID, rrURL string) error {
return s.addComment(fmt.Sprintf("Review request [#%v](%v) opened.", rrID, rrURL))
}
func (s *commonStory) OnReviewRequestClosed(rrID, rrURL string) error {
return nil
}
func (s *commonStory) OnReviewRequestReopened(rrID, rrURL string) error {
// Add 'implemented' unless 'qa+' or 'no qa' is there already.
var (
c = config.Get()
add []string
keep []string
)
switch {
case githubutil.LabeledWith(s.issue, c.PassedTestingLabel):
keep = []string{c.PassedTestingLabel}
case githubutil.LabeledWith(s.issue, c.SkipTestingLabel):
keep = []string{c.SkipTestingLabel}
default:
add = []string{c.ImplementedLabel}
}
return s.updateStateLabels(add, keep)
}
func (s *commonStory) MarkAsReviewed() error {
// Add 'reviewed', but also keep 'qa+' and 'no qa'.
var (
c = config.Get()
add = []string{c.ReviewedLabel}
keep []string
)
switch {
case githubutil.LabeledWith(s.issue, c.PassedTestingLabel):
keep = []string{c.PassedTestingLabel}
case githubutil.LabeledWith(s.issue, c.SkipTestingLabel):
keep = []string{c.SkipTestingLabel}
}
return s.updateStateLabels(add, keep)
}
func (s *commonStory) addComment(text string) error {
var (
client = s.client
owner = s.owner
repo = s.repo
issueNum = *s.issue.Number
)
_, _, err := client.Issues.CreateComment(owner, repo, issueNum, &github.IssueComment{
Body: &text,
})
return err
}
func (s *commonStory) updateStateLabels(add, keep []string) error {
return util.ReplaceWorkflowLabels(s.client, s.owner, s.repo, s.issue, add, keep)
}