1
+ // Copyright 2021 Diego Lima. All rights reserved.
2
+
3
+ // Use of this source code is governed by a Apache license.
4
+ // license that can be found in the LICENSE file.
1
5
package github
2
6
3
7
import (
@@ -12,6 +16,7 @@ import (
12
16
v41 "github.com/google/go-github/v41/github"
13
17
)
14
18
19
+ // GetPullRequest get a pull request.
15
20
func (w * Worker ) GetPullRequest (owner string , repo string , number int ) (* v41.PullRequest , error ) {
16
21
resp , _ , err := w .Client .PullRequests .Get (context .TODO (), owner , repo , number )
17
22
if err != nil {
@@ -20,6 +25,7 @@ func (w *Worker) GetPullRequest(owner string, repo string, number int) (*v41.Pul
20
25
return resp , err
21
26
}
22
27
28
+ // GetPullRequestFiles list files from a pull request.
23
29
func (w * Worker ) GetPullRequestFiles (owner string , repo string , number int , opts * v41.ListOptions ) ([]* v41.CommitFile , error ) {
24
30
resp , _ , err := w .Client .PullRequests .ListFiles (context .TODO (), owner , repo , number , opts )
25
31
if err != nil {
@@ -28,6 +34,7 @@ func (w *Worker) GetPullRequestFiles(owner string, repo string, number int, opts
28
34
return resp , err
29
35
}
30
36
37
+ // MergePullRequest merge a pull request.
31
38
func (w * Worker ) MergePullRequest (owner string , repo string , number int , commitMessage string , options v41.PullRequestOptions ) (* v41.PullRequestMergeResult , error ) {
32
39
resp , _ , err := w .Client .PullRequests .Merge (context .TODO (), owner , repo , number , commitMessage , & options )
33
40
if err != nil {
@@ -36,6 +43,7 @@ func (w *Worker) MergePullRequest(owner string, repo string, number int, commitM
36
43
return resp , err
37
44
}
38
45
46
+ // PullRequestCreateReview create a pull request review.
39
47
func (w * Worker ) PullRequestCreateReview (owner string , repo string , number int , review v41.PullRequestReviewRequest ) (* v41.PullRequestReview , error ) {
40
48
resp , _ , err := w .Client .PullRequests .CreateReview (context .TODO (), owner , repo , number , & review )
41
49
if err != nil {
@@ -44,14 +52,7 @@ func (w *Worker) PullRequestCreateReview(owner string, repo string, number int,
44
52
return resp , err
45
53
}
46
54
47
- func (w * Worker ) PullRequestCreateCommentReview (owner string , repo string , number int , comment v41.PullRequestComment ) (* v41.PullRequestComment , error ) {
48
- resp , _ , err := w .Client .PullRequests .CreateComment (context .TODO (), owner , repo , number , & comment )
49
- if err != nil {
50
- log .Printf ("error creating pull request review comment: %v\n " , err )
51
- }
52
- return resp , err
53
- }
54
-
55
+ // IssueCreateComment create an issue or pull request comment.
55
56
func (w * Worker ) IssueCreateComment (owner string , repo string , number int , comment v41.IssueComment ) (* v41.IssueComment , error ) {
56
57
resp , _ , err := w .Client .Issues .CreateComment (context .TODO (), owner , repo , number , & comment )
57
58
if err != nil {
@@ -60,14 +61,16 @@ func (w *Worker) IssueCreateComment(owner string, repo string, number int, comme
60
61
return resp , err
61
62
}
62
63
63
- func (w * Worker ) IssueUpdateComment (owner string , repo string , commentId int , comment v41.IssueComment ) (* v41.IssueComment , error ) {
64
- resp , _ , err := w .Client .Issues .EditComment (context .TODO (), owner , repo , int64 (commentId ), & comment )
64
+ // IssueUpdateComment update an issue or pull request comment.
65
+ func (w * Worker ) IssueUpdateComment (owner string , repo string , commentID int , comment v41.IssueComment ) (* v41.IssueComment , error ) {
66
+ resp , _ , err := w .Client .Issues .EditComment (context .TODO (), owner , repo , int64 (commentID ), & comment )
65
67
if err != nil {
66
68
log .Printf ("error updating issue comment: %v\n " , err )
67
69
}
68
70
return resp , err
69
71
}
70
72
73
+ // IssueListComments list the comments of an issue or pull request.
71
74
func (w * Worker ) IssueListComments (owner string , repo string , number int , opts * v41.IssueListCommentsOptions ) ([]* v41.IssueComment , error ) {
72
75
resp , _ , err := w .Client .Issues .ListComments (context .TODO (), owner , repo , number , opts )
73
76
if err != nil {
@@ -76,30 +79,16 @@ func (w *Worker) IssueListComments(owner string, repo string, number int, opts *
76
79
return resp , err
77
80
}
78
81
79
- func (w * Worker ) PullRequestListReviewComments (owner string , repo string , number int , opts * v41.PullRequestListCommentsOptions ) ([]* v41.PullRequestComment , error ) {
80
- resp , _ , err := w .Client .PullRequests .ListComments (context .TODO (), owner , repo , number , opts )
81
- if err != nil {
82
- log .Printf ("error getting pull list of comments: %v\n " , err )
83
- }
84
- return resp , err
85
- }
86
-
87
- func (w * Worker ) AddLabels (owner string , repo string , number int , labels []string ) ([]* v41.Label , error ) {
88
- resp , _ , err := w .Client .Issues .AddLabelsToIssue (context .TODO (), owner , repo , number , labels )
89
- if err != nil {
90
- log .Printf ("error adding labels: %v\n " , err )
91
- }
92
- return resp , err
93
- }
94
-
95
- func (w * Worker ) GetCheckRun (owner string , repo string , checkrunId int64 ) (* v41.CheckRun , error ) {
96
- resp , _ , err := w .Client .Checks .GetCheckRun (context .TODO (), owner , repo , checkrunId )
82
+ // GetCheckRun get a check run.
83
+ func (w * Worker ) GetCheckRun (owner string , repo string , checkrunID int64 ) (* v41.CheckRun , error ) {
84
+ resp , _ , err := w .Client .Checks .GetCheckRun (context .TODO (), owner , repo , checkrunID )
97
85
if err != nil {
98
86
log .Printf ("error creating checkrun: %v\n " , err )
99
87
}
100
88
return resp , err
101
89
}
102
90
91
+ // CreateCheckRun create a check run.
103
92
func (w * Worker ) CreateCheckRun (owner string , repo string , checkrun v41.CreateCheckRunOptions ) (* v41.CheckRun , error ) {
104
93
resp , _ , err := w .Client .Checks .CreateCheckRun (context .TODO (), owner , repo , checkrun )
105
94
if err != nil {
@@ -108,14 +97,16 @@ func (w *Worker) CreateCheckRun(owner string, repo string, checkrun v41.CreateCh
108
97
return resp , err
109
98
}
110
99
111
- func (w * Worker ) UpdateCheckRun (owner string , repo string , checkRunId int64 , checkRun v41.UpdateCheckRunOptions ) (* v41.CheckRun , error ) {
112
- resp , _ , err := w .Client .Checks .UpdateCheckRun (context .TODO (), owner , repo , checkRunId , checkRun )
100
+ // UpdateCheckRun update a check run.
101
+ func (w * Worker ) UpdateCheckRun (owner string , repo string , checkrunID int64 , checkRun v41.UpdateCheckRunOptions ) (* v41.CheckRun , error ) {
102
+ resp , _ , err := w .Client .Checks .UpdateCheckRun (context .TODO (), owner , repo , checkrunID , checkRun )
113
103
if err != nil {
114
104
log .Printf ("error updating checkrun: %v\n " , err )
115
105
}
116
106
return resp , err
117
107
}
118
108
109
+ // GetRef get a reference.
119
110
func (w * Worker ) GetRef (owner string , repo string , ref string ) (* v41.Reference , error ) {
120
111
resp , _ , err := w .Client .Git .GetRef (context .TODO (), owner , repo , ref )
121
112
if err != nil {
@@ -124,6 +115,7 @@ func (w *Worker) GetRef(owner string, repo string, ref string) (*v41.Reference,
124
115
return resp , err
125
116
}
126
117
118
+ // DeleteRef delete a reference.
127
119
func (w * Worker ) DeleteRef (owner string , repo string , ref string ) (* v41.Response , error ) {
128
120
resp , err := w .Client .Git .DeleteRef (context .TODO (), owner , repo , ref )
129
121
if err != nil {
@@ -132,6 +124,7 @@ func (w *Worker) DeleteRef(owner string, repo string, ref string) (*v41.Response
132
124
return resp , err
133
125
}
134
126
127
+ // CreatePulllRequestOverviewComment create a pull request comment with the report (overview diff).
135
128
func (w * Worker ) CreatePulllRequestOverviewComment (owner * string , repo string , pullRequestNumber int ) {
136
129
if pullRequest , err := w .GetPullRequest (* owner , repo , pullRequestNumber ); err == nil {
137
130
currentIssueComment := w .GetPulllRequestOverviewComment (owner , repo , pullRequestNumber )
@@ -183,8 +176,9 @@ func (w *Worker) CreatePulllRequestOverviewComment(owner *string, repo string, p
183
176
}
184
177
}
185
178
186
- func (w * Worker ) GetPulllRequestOverviewComment (owner * string , repo string , pullrequestId int ) * v41.IssueComment {
187
- if comments , err := w .IssueListComments (* owner , repo , pullrequestId , nil ); err == nil {
179
+ // GetPulllRequestOverviewComment get a pull request comment with the report (overview diff).
180
+ func (w * Worker ) GetPulllRequestOverviewComment (owner * string , repo string , pullrequestID int ) * v41.IssueComment {
181
+ if comments , err := w .IssueListComments (* owner , repo , pullrequestID , nil ); err == nil {
188
182
for _ , comment := range comments {
189
183
if strings .HasPrefix (* comment .Body , "\u003c h3 align=\" center\" \u003e Pull request Overview :checkered_flag:" ) {
190
184
if strings .EqualFold ("Bot" , * comment .User .Type ) && strings .Contains (* comment .User .AvatarURL , strconv .Itoa (w .Config .Github .AppID )) {
0 commit comments