@@ -30,7 +30,34 @@ export const PLACEHOLDERS = {
3030 downloads : '%DOWNLOADS%'
3131} ;
3232
33- export function checkRemote ( cli , repository ) {
33+ function formatCommand ( command , args ) {
34+ return [ command , ...args ] . join ( ' ' ) ;
35+ }
36+
37+ export async function confirmSecurityStep ( cli , action , detail ) {
38+ let message = `Allow action: ${ action } ?` ;
39+ if ( detail ) {
40+ message += `\n\n${ detail } ` ;
41+ }
42+
43+ const allowed = await cli . prompt ( message , { defaultAnswer : false } ) ;
44+ if ( ! allowed ) {
45+ throw new Error ( `Aborted: ${ action } .` ) ;
46+ }
47+ }
48+
49+ export async function runSecurityGitCommand ( cli , args , detail ) {
50+ const command = formatCommand ( 'git' , args ) ;
51+ await confirmSecurityStep ( cli , `run \`${ command } \`` , detail ) ;
52+ return runSync ( 'git' , args ) ;
53+ }
54+
55+ export async function writeSecurityFile ( cli , filePath , content , detail ) {
56+ await confirmSecurityStep ( cli , `write \`${ filePath } \`` , detail ) ;
57+ return fs . writeFileSync ( filePath , content ) ;
58+ }
59+
60+ export async function checkRemote ( cli , repository ) {
3461 const remote = runSync ( 'git' , [ 'ls-remote' , '--get-url' , 'origin' ] ) . trim ( ) ;
3562 const { owner, repo } = repository ;
3663 const securityReleaseOrigin = [
@@ -44,23 +71,31 @@ export function checkRemote(cli, repository) {
4471 }
4572}
4673
47- export function checkoutOnSecurityReleaseBranch ( cli , repository ) {
48- checkRemote ( cli , repository ) ;
74+ export async function checkoutOnSecurityReleaseBranch ( cli , repository ) {
75+ await checkRemote ( cli , repository ) ;
4976 const currentBranch = runSync ( 'git' , [ 'branch' , '--show-current' ] ) . trim ( ) ;
5077 cli . info ( `Current branch: ${ currentBranch } ` ) ;
5178
5279 if ( currentBranch !== NEXT_SECURITY_RELEASE_BRANCH ) {
53- runSync ( 'git' , [ 'checkout' , '-B' , NEXT_SECURITY_RELEASE_BRANCH ] ) ;
80+ await runSecurityGitCommand (
81+ cli ,
82+ [ 'checkout' , '-B' , NEXT_SECURITY_RELEASE_BRANCH ] ,
83+ `This checks out or recreates the ${ NEXT_SECURITY_RELEASE_BRANCH } branch locally.`
84+ ) ;
5485 cli . ok ( `Checkout on branch: ${ NEXT_SECURITY_RELEASE_BRANCH } ` ) ;
5586 } ;
5687}
5788
58- export function commitAndPushVulnerabilitiesJSON ( filePath , commitMessage , { cli, repository } ) {
59- checkRemote ( cli , repository ) ;
89+ export async function commitAndPushVulnerabilitiesJSON (
90+ filePath ,
91+ commitMessage ,
92+ { cli, repository }
93+ ) {
94+ await checkRemote ( cli , repository ) ;
6095
6196 if ( Array . isArray ( filePath ) ) {
62- for ( const path of filePath ) {
63- runSync ( 'git' , [ 'add' , path ] ) ;
97+ for ( const currentPath of filePath ) {
98+ runSync ( 'git' , [ 'add' , currentPath ] ) ;
6499 }
65100 } else {
66101 runSync ( 'git' , [ 'add' , filePath ] ) ;
@@ -72,15 +107,31 @@ export function commitAndPushVulnerabilitiesJSON(filePath, commitMessage, { cli,
72107 return ;
73108 }
74109
75- runSync ( 'git' , [ 'commit' , '-m' , commitMessage ] ) ;
110+ await runSecurityGitCommand (
111+ cli ,
112+ [ 'commit' , '-m' , commitMessage ] ,
113+ `This creates a local commit with message: ${ commitMessage } `
114+ ) ;
76115
77116 try {
78- runSync ( 'git' , [ 'push' , '-u' , 'origin' , NEXT_SECURITY_RELEASE_BRANCH ] ) ;
117+ await runSecurityGitCommand (
118+ cli ,
119+ [ 'push' , '-u' , 'origin' , NEXT_SECURITY_RELEASE_BRANCH ] ,
120+ `This pushes the security release branch to origin/${ NEXT_SECURITY_RELEASE_BRANCH } .`
121+ ) ;
79122 } catch ( error ) {
80123 cli . warn ( 'Rebasing...' ) ;
81124 // try to pull rebase and push again
82- runSync ( 'git' , [ 'pull' , 'origin' , NEXT_SECURITY_RELEASE_BRANCH , '--rebase' ] ) ;
83- runSync ( 'git' , [ 'push' , '-u' , 'origin' , NEXT_SECURITY_RELEASE_BRANCH ] ) ;
125+ await runSecurityGitCommand (
126+ cli ,
127+ [ 'pull' , 'origin' , NEXT_SECURITY_RELEASE_BRANCH , '--rebase' ] ,
128+ `This rebases local changes on origin/${ NEXT_SECURITY_RELEASE_BRANCH } .`
129+ ) ;
130+ await runSecurityGitCommand (
131+ cli ,
132+ [ 'push' , '-u' , 'origin' , NEXT_SECURITY_RELEASE_BRANCH ] ,
133+ `This retries pushing the security release branch to origin/${ NEXT_SECURITY_RELEASE_BRANCH } .`
134+ ) ;
84135 }
85136 cli . ok ( `Pushed commit: ${ commitMessage } to ${ NEXT_SECURITY_RELEASE_BRANCH } ` ) ;
86137}
@@ -150,6 +201,11 @@ export function promptDependencies(cli) {
150201}
151202
152203export async function createIssue ( title , content , repository , { cli, req } ) {
204+ await confirmSecurityStep (
205+ cli ,
206+ `create GitHub issue \`${ repository . owner } /${ repository . repo } : ${ title } \`` ,
207+ `This creates an issue in ${ repository . owner } /${ repository . repo } .`
208+ ) ;
153209 const data = await req . createIssue ( title , content , repository ) ;
154210 if ( data . html_url ) {
155211 cli . ok ( `Created: ${ data . html_url } ` ) ;
@@ -252,20 +308,30 @@ export class SecurityRelease {
252308 NEXT_SECURITY_RELEASE_FOLDER , 'vulnerabilities.json' ) ;
253309 }
254310
255- updateReleaseFolder ( releaseDate ) {
311+ async updateReleaseFolder ( releaseDate ) {
256312 const folder = path . join ( process . cwd ( ) ,
257313 NEXT_SECURITY_RELEASE_FOLDER ) ;
258314 const newFolder = path . join ( process . cwd ( ) , 'security-release' , releaseDate ) ;
315+ await confirmSecurityStep (
316+ this . cli ,
317+ `rename \`${ folder } \` to \`${ newFolder } \`` ,
318+ 'This moves the next-security-release folder to the dated release folder.'
319+ ) ;
259320 fs . renameSync ( folder , newFolder ) ;
260321 return newFolder ;
261322 }
262323
263- updateVulnerabilitiesJSON ( content ) {
324+ async updateVulnerabilitiesJSON ( content ) {
264325 try {
265326 const vulnerabilitiesJSONPath = this . getVulnerabilitiesJSONPath ( ) ;
266327 this . cli . startSpinner ( `Updating vulnerabilities.json from ${ vulnerabilitiesJSONPath } ...` ) ;
267- fs . writeFileSync ( vulnerabilitiesJSONPath , JSON . stringify ( content , null , 2 ) ) ;
268- commitAndPushVulnerabilitiesJSON ( vulnerabilitiesJSONPath ,
328+ await writeSecurityFile (
329+ this . cli ,
330+ vulnerabilitiesJSONPath ,
331+ JSON . stringify ( content , null , 2 ) ,
332+ 'This updates vulnerabilities.json with the latest security release data.'
333+ ) ;
334+ await commitAndPushVulnerabilitiesJSON ( vulnerabilitiesJSONPath ,
269335 'chore: updated vulnerabilities.json' ,
270336 { cli : this . cli , repository : this . repository } ) ;
271337 this . cli . stopSpinner ( `Done updating vulnerabilities.json from ${ vulnerabilitiesJSONPath } ` ) ;
0 commit comments