Skip to content

Commit c28608f

Browse files
committed
Add Commit Input Parameter
Fixes jwgmeligmeyling#6
1 parent b5111f0 commit c28608f

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Multiple files can be processed through a [glob expression](https://github.com/a
1818
### `name`
1919
Optional. Name for the check run to create. Defaults to `Checkstyle`.
2020

21+
### `commit`
22+
Optional. The commit sha to update the status. This is useful when you run it with `workflow_run`.
23+
2124
### `title`
2225
Optional. Title for the check run to create. Defaults to `Checkstyle Source Code Analyzer report`.
2326

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export enum Inputs {
22
Name = 'name',
3+
Commit = 'commit',
34
Title = 'title',
45
Path = 'path',
56
Token = 'token'

src/main.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ async function run(): Promise<void> {
1313
const path = core.getInput(Inputs.Path, {required: true})
1414
const name = core.getInput(Inputs.Name)
1515
const title = core.getInput(Inputs.Title)
16+
const commit = core.getInput(Inputs.Commit)
1617

1718
const searchResult = await findResults(path)
1819
if (searchResult.filesToUpload.length === 0) {
@@ -45,6 +46,7 @@ async function run(): Promise<void> {
4546
for (const annotationSet of groupedAnnotations) {
4647
await createCheck(
4748
name,
49+
commit,
4850
title,
4951
annotationSet,
5052
annotations.length,
@@ -86,6 +88,7 @@ function getConclusion(
8688

8789
async function createCheck(
8890
name: string,
91+
commit: string,
8992
title: string,
9093
annotations: Annotation[],
9194
numErrors: number,
@@ -95,15 +98,13 @@ async function createCheck(
9598
`Uploading ${annotations.length} / ${numErrors} annotations to GitHub as ${name} with conclusion ${conclusion}`
9699
)
97100
const octokit = getOctokit(core.getInput(Inputs.Token))
98-
let sha = context.sha
99-
100-
if (context.payload.pull_request) {
101-
sha = context.payload.pull_request.head.sha
102-
}
101+
const head_sha = commit ||
102+
(context.payload.pull_request && context.payload.pull_request.head.sha) ||
103+
context.sha;
103104

104105
const req = {
105106
...context.repo,
106-
ref: sha
107+
ref: head_sha
107108
}
108109

109110
const res = await octokit.checks.listForRef(req)
@@ -114,7 +115,7 @@ async function createCheck(
114115
if (!existingCheckRun) {
115116
const createRequest = {
116117
...context.repo,
117-
head_sha: sha,
118+
head_sha,
118119
conclusion,
119120
name,
120121
status: <const>'completed',

0 commit comments

Comments
 (0)