18
18
* - git.commitSha()
19
19
*/
20
20
21
+ // Dictionary that holds the id for each created checkrun. name => id.
22
+ @groovy.transform.Field private def checkRuns = [:]
23
+
21
24
/**
22
25
* Creates or updates the Jenkins bot issue comment for the pull request.
23
26
*
@@ -177,7 +180,7 @@ def updateIssueComment(int id, String body) {
177
180
*
178
181
* As we have an GitHub app, we use the checks API instead of using the older commit status API.
179
182
*/
180
- def createCheckRun (String name , String status , String url = ' ' ) {
183
+ def createCheckRun (String name , String status = ' ' , String conclusion = ' ' , String url = ' ' ) {
181
184
withCredentials([usernamePassword(credentialsId : ' githubapp-jenkins' ,
182
185
usernameVariable : ' GITHUB_APP' ,
183
186
passwordVariable : ' GITHUB_ACCESS_TOKEN' )]) {
@@ -187,8 +190,9 @@ def createCheckRun(String name, String status, String url = '') {
187
190
' head_sha' : sha,
188
191
' name' : name,
189
192
' external_id' : env. BUILD_NUMBER ,
190
- ' status' : status
191
193
]
194
+ if (status. length() > 0 ) payload[' status' ] = status
195
+ if (conclusion. length() > 0 ) payload[' conclusion' ] = conclusion
192
196
if (url. length() > 0 ) payload[' details_url' ] = url
193
197
String json = writeJSON returnText : true , json : payload
194
198
@@ -203,7 +207,7 @@ def createCheckRun(String name, String status, String url = '') {
203
207
)
204
208
205
209
def checkRun = readJSON text : response. content
206
- return checkRun. id
210
+ this . checkRuns[name] = checkRun. id
207
211
}
208
212
}
209
213
@@ -217,12 +221,13 @@ def createCheckRun(String name, String status, String url = '') {
217
221
*
218
222
* As we have an GitHub app, we use the checks API instead of using the older commit status API.
219
223
*/
220
- def updateCheckRun (id , String status = ' ' , String conclusion = ' ' ) {
224
+ def updateCheckRun (String name , String status = ' ' , String conclusion = ' ' ) {
221
225
withCredentials([usernamePassword(credentialsId : ' githubapp-jenkins' ,
222
226
usernameVariable : ' GITHUB_APP' ,
223
227
passwordVariable : ' GITHUB_ACCESS_TOKEN' )]) {
224
228
def sha = git. commitSha();
225
229
def ownerRepo = ownerRepo()
230
+ def id = this . checkRuns[name]
226
231
227
232
def payload = [
228
233
' head_sha' : sha
0 commit comments