Skip to content

Commit

Permalink
feat: replace commit statuses with checks
Browse files Browse the repository at this point in the history
GitHub checks are the new way to report CI status. They are more
flexible and can be used for more than just CI. They also have a
dedicated API, which is more convenient than the status API.

It allows us to show more information about commit validation.
  • Loading branch information
jamacku committed May 19, 2023
1 parent 606dd29 commit 4c4ef98
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 29 deletions.
32 changes: 23 additions & 9 deletions dist/action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/action.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 23 additions & 9 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

32 changes: 23 additions & 9 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@ const action = (probot: Probot) => {
);

const prMetadata = pullRequestMetadataSchema.parse(prMetadataUnsafe);
const commitSha = prMetadata.commits[prMetadata.commits.length - 1].sha;

await context.octokit.repos.createCommitStatus(
// Initialize check run - check in progress
// https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run
const checkRun = await context.octokit.checks.create(
context.repo({
state: 'pending',
sha: prMetadata.commits[prMetadata.commits.length - 1].sha,
description: 'validation',
context: `Advanced Commit Linter`,
name: 'Advanced Commit Linter',
head_sha: commitSha,
status: 'in_progress',
started_at: new Date().toISOString(),
output: {
title: 'Advanced Commit Linter',
summary: 'Commit validation in progress',
},
})
);

Expand All @@ -56,11 +63,18 @@ const action = (probot: Probot) => {

setOutput('validated-pr-metadata', JSON.stringify(validated, null, 2));

await context.octokit.repos.createCommitStatus(
// Update check run - check completed + conclusion
// https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#update-a-check-run
await context.octokit.checks.update(
context.repo({
state: validated.validation.status,
sha: prMetadata.commits[prMetadata.commits.length - 1].sha,
context: `Advanced Commit Linter`,
check_run_id: checkRun.data.id,
status: 'completed',
completed_at: new Date().toISOString(),
conclusion: validated.validation.status,
output: {
title: 'Advanced Commit Linter',
summary: validated.validation.message,
},
})
);
}
Expand Down

0 comments on commit 4c4ef98

Please sign in to comment.