Skip to content

Commit 236b4fb

Browse files
committed
feat: improve DX of request-cves
It no longer asks for every report, I have used for the next security release and it's working pretty smooth Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
1 parent c3b9dc6 commit 236b4fb

4 files changed

Lines changed: 646 additions & 121 deletions

File tree

components/git/security.js

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ const securityOptions = {
7171

7272
let yargsInstance;
7373

74+
function isPromptInterrupted(error) {
75+
return error?.name === 'ExitPromptError' ||
76+
error?.name === 'AbortPromptError' ||
77+
error?.message?.includes('User force closed');
78+
}
79+
80+
function runSecurityAction(cli, action) {
81+
return Promise.resolve(action).catch((error) => {
82+
if (!isPromptInterrupted(error)) {
83+
throw error;
84+
}
85+
86+
if (cli.spinner.isSpinning) {
87+
cli.spinner.stop();
88+
}
89+
cli.warn('Aborted.');
90+
cli.setExitCode(1);
91+
});
92+
}
93+
7494
export function builder(yargs) {
7595
yargsInstance = yargs;
7696
return yargs.options(securityOptions)
@@ -117,40 +137,36 @@ export function builder(yargs) {
117137
export function handler(argv) {
118138
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
119139
const cli = new CLI(logStream);
140+
let action;
120141

121142
if (argv.start) {
122-
return startSecurityRelease(cli, argv);
123-
}
124-
if (argv['apply-patches']) {
125-
return applySecurityPatches(cli, argv);
143+
action = startSecurityRelease(cli, argv);
144+
} else if (argv['apply-patches']) {
145+
action = applySecurityPatches(cli, argv);
146+
} else if (argv.sync) {
147+
action = syncSecurityRelease(cli, argv);
148+
} else if (argv['update-date']) {
149+
action = updateReleaseDate(cli, argv);
150+
} else if (argv['pre-release']) {
151+
action = createPreRelease(cli, argv);
152+
} else if (argv['add-report']) {
153+
action = addReport(cli, argv);
154+
} else if (argv['remove-report']) {
155+
action = removeReport(cli, argv);
156+
} else if (argv['notify-pre-release']) {
157+
action = notifyPreRelease(cli, argv);
158+
} else if (argv['request-cve']) {
159+
action = requestCVEs(cli, argv);
160+
} else if (argv['post-release']) {
161+
action = createPostRelease(cli, argv);
162+
} else if (argv.cleanup) {
163+
action = cleanupSecurityRelease(cli, argv);
126164
}
127-
if (argv.sync) {
128-
return syncSecurityRelease(cli, argv);
129-
}
130-
if (argv['update-date']) {
131-
return updateReleaseDate(cli, argv);
132-
}
133-
if (argv['pre-release']) {
134-
return createPreRelease(cli, argv);
135-
}
136-
if (argv['add-report']) {
137-
return addReport(cli, argv);
138-
}
139-
if (argv['remove-report']) {
140-
return removeReport(cli, argv);
141-
}
142-
if (argv['notify-pre-release']) {
143-
return notifyPreRelease(cli, argv);
144-
}
145-
if (argv['request-cve']) {
146-
return requestCVEs(cli, argv);
147-
}
148-
if (argv['post-release']) {
149-
return createPostRelease(cli, argv);
150-
}
151-
if (argv.cleanup) {
152-
return cleanupSecurityRelease(cli, argv);
165+
166+
if (action) {
167+
return runSecurityAction(cli, action);
153168
}
169+
154170
yargsInstance.showHelp();
155171
}
156172

lib/security-release/security-release.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,11 @@ export class SecurityRelease {
387387
'chore: updated vulnerabilities.json',
388388
{ cli: this.cli, repository: this.repository });
389389
this.cli.stopSpinner(`Done updating vulnerabilities.json from ${vulnerabilitiesJSONPath}`);
390+
return true;
390391
} catch (error) {
391392
this.cli.error('Error updating vulnerabilities.json');
392393
this.cli.error(error);
394+
return false;
393395
}
394396
}
395397

0 commit comments

Comments
 (0)