Skip to content

Commit

Permalink
Process input and create check-run
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Nov 17, 2020
1 parent bc70685 commit e97dbdd
Show file tree
Hide file tree
Showing 8 changed files with 13,784 additions and 48 deletions.
12,571 changes: 12,531 additions & 40 deletions dist/index.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

684 changes: 684 additions & 0 deletions dist/licenses.txt

Large diffs are not rendered by default.

506 changes: 500 additions & 6 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"github-slugger": "^1.3.0",
"xml2js": "^0.4.23"
},
"devDependencies": {
"@octokit/types": "^5.5.0",
"@octokit/webhooks": "^7.15.1",
"@types/github-slugger": "^1.3.0",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.6",
Expand Down
43 changes: 42 additions & 1 deletion src/main.ts
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()
13 changes: 13 additions & 0 deletions src/utils/file-utils.ts
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'})
}
11 changes: 11 additions & 0 deletions src/utils/github-utils.ts
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
}

0 comments on commit e97dbdd

Please sign in to comment.