Skip to content

Instantly share code, notes, and snippets.

@naturalett
Created February 23, 2020 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naturalett/96ef0af3609e58555f39a7af776a209d to your computer and use it in GitHub Desktop.
Save naturalett/96ef0af3609e58555f39a7af776a209d to your computer and use it in GitHub Desktop.
setCheckName
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