@@ -15,13 +15,6 @@ module.exports = (app) => {
15
15
'pull_request_review_comment' , // comment lines on diffs for reviews
16
16
] , async context => {
17
17
18
- // log helper
19
- function log ( pr , message , type = 'info' ) {
20
- if ( ENABLE_ID_LOGS ) {
21
- context . log [ type ] ( `PR ${ pr . head . repo . full_name } #${ pr . number } : ${ message } ` ) ;
22
- }
23
- }
24
-
25
18
// lookup the pr
26
19
let pr = context . payload . pull_request ;
27
20
@@ -48,13 +41,27 @@ module.exports = (app) => {
48
41
return ;
49
42
}
50
43
51
- log ( pr , `Request received [Context: ${ context . id } ]` ) ;
52
-
44
+ // pr details
45
+ let prRepo = pr . head . repo . full_name ;
46
+ let prNumber = pr . number ;
47
+ let prHeadSha = pr . head . sha ;
53
48
let prBody = pr . body ;
49
+ let prUser = pr . user . login ;
50
+ // cleanup
51
+ pr = null ;
52
+
53
+ // log helper
54
+ function log ( message , type = 'info' ) {
55
+ if ( ENABLE_ID_LOGS ) {
56
+ context . log [ type ] ( `PR ${ prRepo } #${ prNumber } : ${ message } ` ) ;
57
+ }
58
+ }
59
+
60
+ log ( `Request received [Context: ${ context . id } ]` ) ;
54
61
55
62
// if the author is a renovate bot, ignore checks
56
63
// https://www.mend.io/free-developer-tools/renovate/
57
- if ( pr . user . login . indexOf ( 'renovate[bot]' ) !== - 1 ) {
64
+ if ( prUser . indexOf ( 'renovate[bot]' ) !== - 1 ) {
58
65
prBody = null ;
59
66
}
60
67
@@ -66,7 +73,7 @@ module.exports = (app) => {
66
73
try {
67
74
comments = await context . octokit . issues . listComments ( context . repo ( {
68
75
per_page : 100 ,
69
- issue_number : pr . number
76
+ issue_number : prNumber
70
77
} ) ) ;
71
78
72
79
// bots to ignore
@@ -83,48 +90,48 @@ module.exports = (app) => {
83
90
84
91
} catch ( err ) {
85
92
if ( err . status === 403 ) { // if we don't have access to the repo, skip entirely
86
- log ( pr , `No access, skipping entirely. Error (${ err . status } ): ${ err . message } ` , 'error' ) ;
93
+ log ( `No access, skipping entirely. Error (${ err . status } ): ${ err . message } ` , 'error' ) ;
87
94
return ;
88
95
}
89
- log ( pr , `Error looking up comments, skipping. Error (${ err . status } ): ${ err . message } ` , 'error' ) ;
96
+ log ( `Error looking up comments, skipping. Error (${ err . status } ): ${ err . message } ` , 'error' ) ;
90
97
}
91
98
92
- log ( pr , 'Main comments api lookup complete' ) ;
99
+ log ( 'Main comments api lookup complete' ) ;
93
100
94
101
// as well as review comments
95
102
let reviewComments ;
96
103
try {
97
104
reviewComments = await context . octokit . pulls . listReviews ( context . repo ( {
98
105
per_page : 100 ,
99
- pull_number : pr . number
106
+ pull_number : prNumber
100
107
} ) ) ;
101
108
if ( reviewComments . data . length ) {
102
109
comments . data = comments . data . concat ( reviewComments . data ) ;
103
110
}
104
111
// cleanup
105
112
reviewComments = null ;
106
113
} catch ( err ) {
107
- log ( pr , `Error looking up review comments, skipping. Error (${ err . status } ): ${ err . message } ` , 'error' ) ;
114
+ log ( `Error looking up review comments, skipping. Error (${ err . status } ): ${ err . message } ` , 'error' ) ;
108
115
}
109
116
110
- log ( pr , 'Review comments api lookup complete' ) ;
117
+ log ( 'Review comments api lookup complete' ) ;
111
118
112
119
// and diff level comments on reviews
113
120
try {
114
121
let reviewDiffComments = await context . octokit . pulls . listReviewComments ( context . repo ( {
115
122
per_page : 100 ,
116
- pull_number : pr . number
123
+ pull_number : prNumber
117
124
} ) ) ;
118
125
if ( reviewDiffComments . data . length ) {
119
126
comments . data = comments . data . concat ( reviewDiffComments . data ) ;
120
127
}
121
128
// cleanup
122
129
reviewDiffComments = null ;
123
130
} catch ( err ) {
124
- log ( pr , `Error looking up review diff comments, skipping. Error (${ err . status } ): ${ err . message } ` , 'error' ) ;
131
+ log ( `Error looking up review diff comments, skipping. Error (${ err . status } ): ${ err . message } ` , 'error' ) ;
125
132
}
126
133
127
- log ( pr , 'Diff comments api lookup complete' ) ;
134
+ log ( 'Diff comments api lookup complete' ) ;
128
135
129
136
// & check them for tasks
130
137
if ( comments && comments . data && comments . data . length ) {
@@ -167,7 +174,7 @@ ${outstandingTasks.optionalTasks.map(task => `| ${task.task} | ${task.status} |`
167
174
let check = {
168
175
name : 'task-list-completed' ,
169
176
head_branch : '' ,
170
- head_sha : pr . head . sha ,
177
+ head_sha : prHeadSha ,
171
178
started_at : ( new Date ) . toISOString ( ) ,
172
179
status : 'in_progress' ,
173
180
output : {
@@ -192,7 +199,7 @@ ${outstandingTasks.optionalTasks.map(task => `| ${task.task} | ${task.status} |`
192
199
check . output . summary = 'All tasks have been completed' + optionalText ;
193
200
} ;
194
201
195
- log ( pr , 'Complete and sending back to GitHub' ) ;
202
+ log ( 'Complete and sending back to GitHub' ) ;
196
203
197
204
// cleanup
198
205
prBody = null ;
@@ -204,9 +211,9 @@ ${outstandingTasks.optionalTasks.map(task => `| ${task.task} | ${task.status} |`
204
211
// send check back to GitHub
205
212
try {
206
213
const response = await context . octokit . checks . create ( context . repo ( check ) ) ;
207
- log ( pr , `Check response status from GitHub ${ response . status } [X-GitHub-Request-Id: ${ response . headers [ 'x-github-request-id' ] } ]` ) ;
214
+ log ( `Check response status from GitHub ${ response . status } [X-GitHub-Request-Id: ${ response . headers [ 'x-github-request-id' ] } ]` ) ;
208
215
} catch ( err ) {
209
- log ( pr , `Error sending check back to GitHub. Error (${ err . status } ): ${ err . message } ` , 'error' ) ;
216
+ log ( `Error sending check back to GitHub. Error (${ err . status } ): ${ err . message } ` , 'error' ) ;
210
217
}
211
218
212
219
return ;
0 commit comments