-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const CHECK_NAME = 'SCANOSS Policy Checker' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { context, getOctokit } from '@actions/github' | ||
Check failure on line 1 in src/libs/GitHubCheck.ts GitHub Actions / TypeScript Tests
|
||
import { getInput } from '@actions/core' | ||
|
||
const NO_INITIALIZATE = -1 | ||
|
||
export class GitHubCheck { | ||
private octokit // TODO: type from actions/github ? | ||
|
||
private checkName: string | ||
|
||
private checkRunId: number | ||
|
||
constructor(checkName: string) { | ||
const GITHUB_TOKEN = getInput('github-token') // TODO: move to inputs.ts file? | ||
|
||
this.octokit = getOctokit(GITHUB_TOKEN) | ||
this.checkName = checkName | ||
this.checkRunId = NO_INITIALIZATE | ||
} | ||
|
||
async present() { | ||
Check failure on line 21 in src/libs/GitHubCheck.ts GitHub Actions / TypeScript Tests
|
||
const result = await this.octokit.rest.checks.create({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: this.checkName, | ||
head_sha: context.sha | ||
}) | ||
|
||
this.checkRunId = result.data.id | ||
|
||
return result.data | ||
} | ||
|
||
async finish(conclusion: any, summary: string, text: string) { | ||
Check failure on line 34 in src/libs/GitHubCheck.ts GitHub Actions / TypeScript Tests
Check failure on line 34 in src/libs/GitHubCheck.ts GitHub Actions / TypeScript Tests
Check failure on line 34 in src/libs/GitHubCheck.ts GitHub Actions / Lint Codebase
|
||
if (this.checkRunId === NO_INITIALIZATE) | ||
throw new Error( | ||
`Error on finish. Check "${this.checkName}" is not created.` | ||
) | ||
|
||
const result = await this.octokit.rest.checks.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
check_run_id: this.checkRunId, | ||
status: 'completed', | ||
conclusion, | ||
output: { | ||
title: this.checkName, | ||
summary, | ||
text | ||
} | ||
}) | ||
|
||
return result.data | ||
} | ||
} |