filter vulnerabilities by audit_level (#55)
* filter vulnerabilities by audit_level * update README.md * fix test cases * restrict audit_level value * update dist/index.js
This commit is contained in:
12
src/audit.ts
12
src/audit.ts
@@ -5,11 +5,15 @@ export class Audit {
|
||||
stdout = ''
|
||||
private status: number | null = null
|
||||
|
||||
public async run(): Promise<void> {
|
||||
public async run(auditLevel: string): Promise<void> {
|
||||
try {
|
||||
const result: SpawnSyncReturns<string> = spawnSync('npm', ['audit'], {
|
||||
encoding: 'utf-8'
|
||||
})
|
||||
const result: SpawnSyncReturns<string> = spawnSync(
|
||||
'npm',
|
||||
['audit', '--audit-level', auditLevel],
|
||||
{
|
||||
encoding: 'utf-8'
|
||||
}
|
||||
)
|
||||
|
||||
if (result.error) {
|
||||
throw result.error
|
||||
|
||||
@@ -8,9 +8,15 @@ import * as pr from './pr'
|
||||
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
// get audit-level
|
||||
const auditLevel = core.getInput('audit_level', {required: true})
|
||||
if (!['critical', 'high', 'moderate', 'low'].includes(auditLevel)) {
|
||||
throw new Error('Invalid input: audit_level')
|
||||
}
|
||||
|
||||
// run `npm audit`
|
||||
const audit = new Audit()
|
||||
audit.run()
|
||||
audit.run(auditLevel)
|
||||
core.info(audit.stdout)
|
||||
|
||||
if (audit.foundVulnerability()) {
|
||||
|
||||
Reference in New Issue
Block a user