@@ -9,34 +9,36 @@ import (
9
9
v41 "github.com/google/go-github/v41/github"
10
10
)
11
11
12
+ type CheckService service
13
+
12
14
type checkRunResult struct {
13
15
title string
14
16
passed bool
15
17
body string
16
18
}
17
19
18
- func (w * Worker ) processCheckRun (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) {
20
+ func (s * CheckService ) processCheckRun (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) {
19
21
if p .Action == "created" {
20
- result , overralResults := w .runTestSuite (owner , pullRequest , p )
21
- w .updateCheckRunStatus (owner , pullRequest , p , overralResults )
22
- w .printResults (owner , pullRequest , p , result , overralResults )
22
+ result , overralResults := s .runTestSuite (owner , pullRequest , p )
23
+ s .updateCheckRunStatus (owner , pullRequest , p , overralResults )
24
+ s .printResults (owner , pullRequest , p , result , overralResults )
23
25
}
24
26
}
25
27
26
- func (w * Worker ) runTestSuite (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) ([]* checkRunResult , bool ) {
28
+ func (s * CheckService ) runTestSuite (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) ([]* checkRunResult , bool ) {
27
29
var results []* checkRunResult
28
30
overralResults := true
29
- if len (w .Config .Layout .PullRequest .TestSuite .NamePattern ) > 0 {
30
- results = append (results , w .isNamePatternValid (owner , pullRequest , p ))
31
+ if len (s . w .Config .Layout .PullRequest .TestSuite .NamePattern ) > 0 {
32
+ results = append (results , s .isNamePatternValid (owner , pullRequest , p ))
31
33
}
32
- if w .Config .Layout .PullRequest .TestSuite .Reviewers {
33
- results = append (results , w .hasReviewers (owner , pullRequest , p ))
34
+ if s . w .Config .Layout .PullRequest .TestSuite .Reviewers {
35
+ results = append (results , s .hasReviewers (owner , pullRequest , p ))
34
36
}
35
- if w .Config .Layout .PullRequest .TestSuite .Assignees {
36
- results = append (results , w .hasAssignees (owner , pullRequest , p ))
37
+ if s . w .Config .Layout .PullRequest .TestSuite .Assignees {
38
+ results = append (results , s .hasAssignees (owner , pullRequest , p ))
37
39
}
38
- if w .Config .Layout .PullRequest .TestSuite .Labels {
39
- results = append (results , w .hasLabels (owner , pullRequest , p ))
40
+ if s . w .Config .Layout .PullRequest .TestSuite .Labels {
41
+ results = append (results , s .hasLabels (owner , pullRequest , p ))
40
42
}
41
43
for _ , r := range results {
42
44
if ! r .passed {
@@ -47,11 +49,11 @@ func (w *Worker) runTestSuite(owner *string, pullRequest *v41.PullRequest, p *gh
47
49
return results , overralResults
48
50
}
49
51
50
- func (w * Worker ) isNamePatternValid (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) * checkRunResult {
51
- match , _ := regexp .MatchString (w .Config .Layout .PullRequest .TestSuite .NamePattern , * pullRequest .Title )
52
+ func (s * CheckService ) isNamePatternValid (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) * checkRunResult {
53
+ match , _ := regexp .MatchString (s . w .Config .Layout .PullRequest .TestSuite .NamePattern , * pullRequest .Title )
52
54
var body string
53
55
if ! match {
54
- body = fmt .Sprintf ("The pull request format should be: [%s]" , w .Config .Layout .PullRequest .TestSuite .NamePattern )
56
+ body = fmt .Sprintf ("The pull request format should be: [%s]" , s . w .Config .Layout .PullRequest .TestSuite .NamePattern )
55
57
}
56
58
return & checkRunResult {
57
59
title : "Pull request pattern" ,
@@ -60,7 +62,7 @@ func (w *Worker) isNamePatternValid(owner *string, pullRequest *v41.PullRequest,
60
62
}
61
63
}
62
64
63
- func (w * Worker ) hasReviewers (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) * checkRunResult {
65
+ func (s * CheckService ) hasReviewers (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) * checkRunResult {
64
66
if len (pullRequest .RequestedReviewers ) == 0 {
65
67
return & checkRunResult {
66
68
title : "Reviewers" ,
@@ -74,7 +76,7 @@ func (w *Worker) hasReviewers(owner *string, pullRequest *v41.PullRequest, p *gh
74
76
}
75
77
}
76
78
77
- func (w * Worker ) hasAssignees (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) * checkRunResult {
79
+ func (s * CheckService ) hasAssignees (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) * checkRunResult {
78
80
if len (pullRequest .Assignees ) == 0 {
79
81
return & checkRunResult {
80
82
title : "Assignees" ,
@@ -88,7 +90,7 @@ func (w *Worker) hasAssignees(owner *string, pullRequest *v41.PullRequest, p *gh
88
90
}
89
91
}
90
92
91
- func (w * Worker ) hasLabels (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) * checkRunResult {
93
+ func (s * CheckService ) hasLabels (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload ) * checkRunResult {
92
94
if len (pullRequest .Labels ) == 0 {
93
95
return & checkRunResult {
94
96
title : "Labels" ,
@@ -102,20 +104,20 @@ func (w *Worker) hasLabels(owner *string, pullRequest *v41.PullRequest, p *ghweb
102
104
}
103
105
}
104
106
105
- func (w * Worker ) updateCheckRunStatus (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload , overralResults bool ) {
107
+ func (s * CheckService ) updateCheckRunStatus (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload , overralResults bool ) {
106
108
var conclusion string
107
109
if overralResults {
108
110
conclusion = "success"
109
111
} else {
110
112
conclusion = "failure"
111
113
}
112
- w .UpdateCheckRun (* owner , p .Repository .Name , p .CheckRun .ID , v41.UpdateCheckRunOptions {
114
+ s . w .UpdateCheckRun (* owner , p .Repository .Name , p .CheckRun .ID , v41.UpdateCheckRunOptions {
113
115
Status : v41 .String ("completed" ),
114
116
Conclusion : & conclusion ,
115
117
})
116
118
}
117
119
118
- func (w * Worker ) printResults (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload , results []* checkRunResult , overralResults bool ) {
120
+ func (s * CheckService ) printResults (owner * string , pullRequest * v41.PullRequest , p * ghwebhooks.CheckRunPayload , results []* checkRunResult , overralResults bool ) {
119
121
var title string
120
122
var body bytes.Buffer
121
123
if overralResults {
@@ -137,7 +139,7 @@ func (w *Worker) printResults(owner *string, pullRequest *v41.PullRequest, p *gh
137
139
body .WriteString (fmt .Sprintf ("[:heavy_exclamation_mark:] **%s** → %s <br/>" , r .title , r .body ))
138
140
}
139
141
}
140
- w . PullRequestCreateComment (* owner , p .Repository .Name , * pullRequest .Number , v41.IssueComment {
142
+ s . w . IssueCreateComment (* owner , p .Repository .Name , * pullRequest .Number , v41.IssueComment {
141
143
Body : v41 .String (body .String ()),
142
144
})
143
145
}
0 commit comments