Skip to content

Commit

Permalink
Add Commit Input Parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottmitch committed Dec 12, 2020
1 parent b5111f0 commit c28608f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Multiple files can be processed through a [glob expression](https://github.com/a
### `name`
Optional. Name for the check run to create. Defaults to `Checkstyle`.

### `commit`
Optional. The commit sha to update the status. This is useful when you run it with `workflow_run`.

### `title`
Optional. Title for the check run to create. Defaults to `Checkstyle Source Code Analyzer report`.

Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum Inputs {
Name = 'name',
Commit = 'commit',
Title = 'title',
Path = 'path',
Token = 'token'
Expand Down
15 changes: 8 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ async function run(): Promise<void> {
const path = core.getInput(Inputs.Path, {required: true})
const name = core.getInput(Inputs.Name)
const title = core.getInput(Inputs.Title)
const commit = core.getInput(Inputs.Commit)

const searchResult = await findResults(path)
if (searchResult.filesToUpload.length === 0) {
Expand Down Expand Up @@ -45,6 +46,7 @@ async function run(): Promise<void> {
for (const annotationSet of groupedAnnotations) {
await createCheck(
name,
commit,
title,
annotationSet,
annotations.length,
Expand Down Expand Up @@ -86,6 +88,7 @@ function getConclusion(

async function createCheck(
name: string,
commit: string,
title: string,
annotations: Annotation[],
numErrors: number,
Expand All @@ -95,15 +98,13 @@ async function createCheck(
`Uploading ${annotations.length} / ${numErrors} annotations to GitHub as ${name} with conclusion ${conclusion}`
)
const octokit = getOctokit(core.getInput(Inputs.Token))
let sha = context.sha

if (context.payload.pull_request) {
sha = context.payload.pull_request.head.sha
}
const head_sha = commit ||
(context.payload.pull_request && context.payload.pull_request.head.sha) ||
context.sha;

const req = {
...context.repo,
ref: sha
ref: head_sha
}

const res = await octokit.checks.listForRef(req)
Expand All @@ -114,7 +115,7 @@ async function createCheck(
if (!existingCheckRun) {
const createRequest = {
...context.repo,
head_sha: sha,
head_sha,
conclusion,
name,
status: <const>'completed',
Expand Down

0 comments on commit c28608f

Please sign in to comment.