|
1 | 1 | import * as core from '@actions/core'; |
2 | 2 | import { Downloader } from './downloader'; |
3 | 3 | import { GitHub } from './github'; |
| 4 | +import { Inputs } from './inputs'; |
4 | 5 | import { scan } from './trivy'; |
5 | | -import { TrivyOption } from './interface'; |
6 | 6 |
|
7 | 7 | async function run(): Promise<void> { |
8 | | - const trivyVersion = core.getInput('trivy_version').replace(/^v/, ''); |
9 | | - const image = core.getInput('image') || process.env.IMAGE_NAME; |
10 | | - |
11 | | - if (!image) { |
12 | | - throw new Error('Please specify scan target image name'); |
13 | | - } |
14 | | - |
15 | | - const trivyOption: TrivyOption = { |
16 | | - severity: core.getInput('severity').replace(/\s+/g, ''), |
17 | | - vulnType: core.getInput('vuln_type').replace(/\s+/g, ''), |
18 | | - ignoreUnfixed: core.getInput('ignore_unfixed').toLowerCase() === 'true', |
19 | | - template: core.getInput('template') || `${__dirname}/template/default.tpl`, |
20 | | - }; |
| 8 | + const inputs = new Inputs(); |
| 9 | + inputs.validate(); |
21 | 10 |
|
22 | 11 | const downloader = new Downloader(); |
23 | | - const trivyCmdPath = await downloader.download(trivyVersion); |
24 | | - const result = scan(trivyCmdPath, image, trivyOption); |
| 12 | + const trivyCmdPath = await downloader.download(inputs.trivy.version); |
| 13 | + const result = scan(trivyCmdPath, inputs.image, inputs.trivy.option); |
25 | 14 |
|
26 | 15 | if (!result) { |
27 | 16 | return; |
28 | 17 | } |
29 | 18 |
|
30 | | - const issueOption = { |
31 | | - title: core.getInput('issue_title'), |
32 | | - body: result, |
33 | | - labels: core |
34 | | - .getInput('issue_label') |
35 | | - .replace(/\s+/g, '') |
36 | | - .split(','), |
37 | | - assignees: core |
38 | | - .getInput('issue_assignee') |
39 | | - .replace(/\s+/g, '') |
40 | | - .split(','), |
41 | | - }; |
42 | | - const token = core.getInput('token', { required: true }); |
43 | | - const github = new GitHub(token); |
44 | | - const output = await github.createOrUpdateIssue(image, issueOption); |
| 19 | + const github = new GitHub(inputs.token); |
| 20 | + const issueOption = { body: result, ...inputs.issue }; |
| 21 | + const output = await github.createOrUpdateIssue(inputs.image, issueOption); |
45 | 22 |
|
46 | 23 | core.setOutput('html_url', output.htmlUrl); |
47 | 24 | core.setOutput('issue_number', output.issueNumber.toString()); |
48 | 25 |
|
49 | | - if (core.getInput('fail_on_vulnerabilities') === 'true') { |
| 26 | + if (inputs.fail_on_vulnerabilities) { |
50 | 27 | throw new Error('Abnormal termination because vulnerabilities found'); |
51 | 28 | } |
52 | 29 | } |
|
0 commit comments