Open a GitHub Issue if vulnerabilities are found (#8)
* Get GitHub access token from input * install npm package * fix TypeScript error to successfully build ref: https://github.com/actions/toolkit/issues/199 * npm i strip-ansi to remove control characters * create an issue * use template literal to pass lint * npm run format; npm run lint * use inputs.issue_title as issue title * document inputs.issue_title * add inputs.issue_title
This commit is contained in:
26
src/main.ts
26
src/main.ts
@@ -1,11 +1,14 @@
|
||||
import * as core from '@actions/core'
|
||||
import { spawnSync, SpawnSyncReturns } from 'child_process';
|
||||
import * as github from '@actions/github'
|
||||
import stripAnsi from 'strip-ansi'
|
||||
import Octokit, {IssuesCreateResponse} from '@octokit/rest'
|
||||
import {spawnSync, SpawnSyncReturns} from 'child_process'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const result: SpawnSyncReturns<string> = spawnSync('npm', ['audit'], {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
encoding: 'utf-8'
|
||||
})
|
||||
|
||||
if (result.stderr && result.stderr.length > 0) {
|
||||
throw new Error(result.stderr)
|
||||
@@ -18,8 +21,23 @@ async function run(): Promise<void> {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: open an issue
|
||||
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(result.stdout)}\n\`\`\``
|
||||
const issueOptions = {
|
||||
title: core.getInput('issue_title'),
|
||||
body: issueBody
|
||||
}
|
||||
const {
|
||||
data: issue
|
||||
}: Octokit.Response<IssuesCreateResponse> = await client.issues.create({
|
||||
...github.context.repo,
|
||||
...issueOptions
|
||||
})
|
||||
core.debug(`#${issue.number}`)
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user