Files
npm-audit-action/src/main.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-12-08 19:17:13 +09:00
import * as core from '@actions/core'
import * as github from '@actions/github'
import stripAnsi from 'strip-ansi'
import Octokit, {IssuesCreateResponse} from '@octokit/rest'
import {Audit} from './audit'
2019-12-08 19:17:13 +09:00
async function run(): Promise<void> {
try {
const audit = new Audit()
audit.run()
2019-12-08 19:17:13 +09:00
core.info(audit.stdout)
2019-12-08 22:10:35 +09:00
if (!audit.foundVulnerability()) {
2019-12-08 22:10:35 +09:00
// vulnerabilities are not found
return
}
core.debug('open an issue')
const token: string = core.getInput('token', {required: true})
const client: Octokit = new github.GitHub(token)
// remove control characters and create a code block
const issueBody = `\`\`\`\n${stripAnsi(audit.stdout)}\n\`\`\``
const issueOptions = {
title: core.getInput('issue_title'),
body: issueBody,
assignees: core
.getInput('issue_assignees')
.replace(/\s+/g, '')
.split(','),
labels: core
.getInput('issue_labels')
.replace(/\s+/g, '')
.split(',')
}
const {
data: issue
}: Octokit.Response<IssuesCreateResponse> = await client.issues.create({
...github.context.repo,
...issueOptions
})
core.debug(`#${issue.number}`)
2019-12-08 19:17:13 +09:00
} catch (error) {
core.setFailed(error.message)
}
}
run()