Skip to content

Instantly share code, notes, and snippets.

@naturalett
Created February 23, 2020 22:52
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save naturalett/f55b7f56fa01618f034d21d013b818d1 to your computer and use it in GitHub Desktop.
buildGithubCheck
def buildGithubCheck(repository, commitID, privateKey, status, checkName) {
def currentTime = new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'")
def checkName_run_id
jsonWebToken = getJsonWebToken(privateKey)
getStatusCode = validateAuth(jsonWebToken)
if (!(getStatusCode in [200,201])) {
error "Authentication request failed, status code: ${getStatusCode}"
}
token = getToken(jsonWebToken)
try {
checkName_run_id = getPreviousCheckNameRunID(repository, commitID, token, checkName)
} catch(Exception e) {
echo "Exception: ${e}"
echo "Check name does not exist"
}
if (checkName_run_id) {
getStatusCode = setCheckName(repository, checkName, status, currentTime, "PATCH", commitID, checkName_run_id)
} else {
getStatusCode = setCheckName(repository, checkName, status, previousDay, "POST", commitID)
}
if (!(getStatusCode in [200,201])) {
error "Failed to create a check run, status code: ${getStatusCode}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment