Created
December 15, 2020 18:26
-
-
Save SubratThakur/4ae3fb5de77d08ddd6e44b41739b3a03 to your computer and use it in GitHub Desktop.
used for medium article heroku ci and github checks
This file contains 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
//Configure app to intercept Status event | |
app.on('status', async (context) => { | |
// Check the state of | |
if(context.payload.state === 'canceled' || | |
context.payload.state === 'error' || | |
context.payload.state === 'success') { | |
//Flag to ensure if any checks get updated | |
let checkUpdated = false | |
const createCheckParams = { | |
name: commitSha, | |
owner: context.repo().owner, | |
repo: context.repo().repo, | |
head_sha: commitSha, | |
check_run_id: 0, | |
conclusion: determineCheckConclusion(context.payload.status), | |
status: determineCheckStatus(context.payload.status), | |
completed_at: new Date().toISOString(), | |
details_url: context.payload.target_url, | |
output: determineCheckSummaryWithTitleAndSummaryLog(), | |
actions: [] | |
} | |
//Fetch all the checks for specific commit | |
const checkRunList = await getCheckListForCommit(commitSha, context) | |
if (checkRunList.data.total_count > 0) { | |
checkRunList.data.check_runs.forEach(async (check: any) => { | |
if (check.status === 'in_progress') { | |
createCheckParams.check_run_id = check.id | |
checkUpdated = true | |
await context.github.checks.update(params) | |
} | |
}) | |
} | |
// If no in progress check run get updated then we create a new check run | |
else if (!checkUpdated) { | |
await context.github.checks.create(params) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment