Created
February 23, 2020 22:33
-
-
Save naturalett/96ef0af3609e58555f39a7af776a209d to your computer and use it in GitHub Desktop.
setCheckName
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ORGANIZATION_NAME = <ORGANIZATION_NAME> | |
def setCheckName(repository, checkName, status, previousDay, requestMethod, commitID=null, check_run_id=null) { | |
try { | |
def jsonCheckRun = new groovy.json.JsonBuilder() | |
updateCheckRun = ["name":"${checkName}", "status": "in_progress", "conclusion":"${status}", "completed_at": "${previousDay}"] | |
def url = "https://api.github.com/repos/${ORGANIZATION_NAME}/${repository}/check-runs" | |
if (requestMethod == "POST") { | |
updateCheckRun["head_sha"] = "${commitID}" | |
} else { | |
url += "/${check_run_id}" | |
} | |
// Cast map to json | |
jsonCheckRun updateCheckRun | |
def httpConn = new URL(url).openConnection(); | |
setRequestMethod(httpConn, requestMethod); | |
httpConn.setDoOutput(true) | |
httpConn.setRequestProperty( 'Authorization', "token ${token}" ) | |
httpConn.setRequestProperty( 'Accept', 'application/vnd.github.antiope-preview+json' ) | |
httpConn.getOutputStream().write(jsonCheckRun.toString().getBytes("UTF-8")); | |
return httpConn.getResponseCode(); | |
} catch(Exception e){ | |
echo "Exception: ${e}" | |
error "Failed to create a check run" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment