-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michal Dorner
committed
Nov 17, 2020
1 parent
bc70685
commit e97dbdd
Showing
8 changed files
with
13,784 additions
and
48 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,52 @@ | ||
import * as core from '@actions/core' | ||
import * as github from '@actions/github' | ||
import {parseJestJunit} from './parsers/jest-junit/jest-junit-parser' | ||
import {ParseTestResult} from './parsers/test-parser' | ||
import {getFileContent} from './utils/file-utils' | ||
import {getCheckRunSha} from './utils/github-utils' | ||
|
||
async function run(): Promise<void> { | ||
try { | ||
core.info('TODO') | ||
await main() | ||
} catch (error) { | ||
core.setFailed(error.message) | ||
} | ||
} | ||
|
||
async function main(): Promise<void> { | ||
const name = core.getInput('name', {required: true}) | ||
const path = core.getInput('path', {required: true}) | ||
const reporter = core.getInput('reporter', {required: true}) | ||
const token = core.getInput('token', {required: true}) | ||
|
||
const octokit = github.getOctokit(token) | ||
const sha = getCheckRunSha() | ||
|
||
const parser = getParser(reporter) | ||
const content = getFileContent(path) | ||
const result = await parser(content) | ||
|
||
await octokit.checks.create({ | ||
head_sha: sha, | ||
name, | ||
status: 'completed', | ||
conclusion: result.success ? 'success' : 'failure', | ||
output: result.output, | ||
...github.context.repo | ||
}) | ||
} | ||
|
||
function getParser(reporter: string): ParseTestResult { | ||
switch (reporter) { | ||
case 'dotnet-trx': | ||
throw new Error('Not implemented yet!') | ||
case 'flutter-machine': | ||
throw new Error('Not implemented yet!') | ||
case 'jest-junit': | ||
return parseJestJunit | ||
default: | ||
throw new Error(`Input parameter 'reporter' is set to invalid value '${reporter}'`) | ||
} | ||
} | ||
|
||
run() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as fs from 'fs' | ||
|
||
export function getFileContent(path: string): string { | ||
if (!fs.existsSync(path)) { | ||
throw new Error(`File '${path}' not found`) | ||
} | ||
|
||
if (!fs.lstatSync(path).isFile()) { | ||
throw new Error(`'${path}' is not a file`) | ||
} | ||
|
||
return fs.readFileSync(path, {encoding: 'utf8'}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as github from '@actions/github' | ||
import {EventPayloads} from '@octokit/webhooks' | ||
|
||
export function getCheckRunSha(): string { | ||
if (github.context.payload.pull_request) { | ||
const pr = github.context.payload.pull_request as EventPayloads.WebhookPayloadPullRequestPullRequest | ||
return pr.head.sha | ||
} | ||
|
||
return github.context.sha | ||
} |