@@ -16,14 +16,21 @@ import path from "path";
16
16
const commander = new Command ( ) ;
17
17
const publishRemoteKey = "publishRemote" ;
18
18
19
- commander . version ( "1.0.0" )
19
+ commander
20
+ . version ( "1.0.0" )
20
21
. usage ( "[options] ( update-open-prs | lookup-upstream-commit | annotate-commit <pr-number> <original> <git.git> )" )
21
22
. description ( "Command-line helper for GitGitGadget" )
22
- . option ( "-g, --git-work-dir [directory]" ,
23
- "Use a different git.git working directory than specified via `gitgitgadget.workDir`" , undefined )
24
- . option ( "-G, --gitgitgadget-work-dir [directory]" ,
25
- "Use a different gitgitgadget working directory than the current working directory to access the Git "
26
- + "config e.g. for `gitgitgadget.workDir`" , "." )
23
+ . option (
24
+ "-g, --git-work-dir [directory]" ,
25
+ "Use a different git.git working directory than specified via `gitgitgadget.workDir`" ,
26
+ undefined ,
27
+ )
28
+ . option (
29
+ "-G, --gitgitgadget-work-dir [directory]" ,
30
+ "Use a different gitgitgadget working directory than the current working directory to access the Git config" +
31
+ "e.g. for `gitgitgadget.workDir`" ,
32
+ "." ,
33
+ )
27
34
. option ( "-c, --config <string>" , "Use this configuration when using gitgitgadget with a project other than git" , "" )
28
35
. option ( "-s, --skip-update" , "Do not update the local refs (useful for debugging)" )
29
36
. parse ( process . argv ) ;
@@ -42,7 +49,8 @@ if (commander.args.length === 0) {
42
49
const commandOptions = commander . opts < ICommanderOptions > ( ) ;
43
50
44
51
( async ( ) : Promise < void > => {
45
- const config : IConfig = commandOptions . config ? setConfig ( await getExternalConfig ( commandOptions . config ) )
52
+ const config : IConfig = commandOptions . config
53
+ ? setConfig ( await getExternalConfig ( commandOptions . config ) )
46
54
: getConfig ( ) ;
47
55
48
56
const getGitGitWorkDir = async ( ) : Promise < string > => {
@@ -115,8 +123,11 @@ const commandOptions = commander.opts<ICommanderOptions>();
115
123
await ci . setUpstreamCommit ( originalCommit , gitGitCommit ) ;
116
124
} else if ( command === "set-tip-commit-in-git.git" ) {
117
125
if ( commander . args . length !== 3 ) {
118
- process . stderr . write ( `${ command } : needs 2 parameters:\nPR URL and tip commit in ${
119
- config . repo . baseOwner } .${ config . repo . name } `) ;
126
+ process . stderr . write (
127
+ `${ command } : needs 2 parameters:\nPR URL and tip commit in ${
128
+ config . repo . baseOwner
129
+ } .${ config . repo . name } `,
130
+ ) ;
120
131
process . exit ( 1 ) ;
121
132
}
122
133
const pullRequestURL = commander . args [ 1 ] ;
@@ -130,8 +141,10 @@ const commandOptions = commander.opts<ICommanderOptions>();
130
141
await ci . notes . set ( pullRequestURL , data , true ) ;
131
142
} else if ( command === "set-previous-iteration" ) {
132
143
if ( commander . args . length !== 9 ) {
133
- process . stderr . write ( `${ command } : needs PR URL, iteration, cover-letter Message ID, latest tag, ${
134
- "" } base commit, base label, head commit, head label\n`) ;
144
+ process . stderr . write (
145
+ `${ command } : needs PR URL, iteration, cover-letter Message ID, latest tag, ` +
146
+ "base commit, base label, head commit, head label\n" ,
147
+ ) ;
135
148
process . exit ( 1 ) ;
136
149
}
137
150
const pullRequestURL = commander . args [ 1 ] ;
@@ -172,8 +185,9 @@ const commandOptions = commander.opts<ICommanderOptions>();
172
185
console . log ( `Result: ${ result } ` ) ;
173
186
} else if ( command === "annotate-commit" ) {
174
187
if ( commander . args . length !== 3 ) {
175
- process . stderr . write ( `${ command } : needs 2 parameters: original and ${
176
- config . repo . baseOwner } .${ config . repo . name } commit\n`) ;
188
+ process . stderr . write (
189
+ `${ command } : needs 2 parameters: original and ${ config . repo . baseOwner } .${ config . repo . name } commit\n` ,
190
+ ) ;
177
191
process . exit ( 1 ) ;
178
192
}
179
193
@@ -211,16 +225,17 @@ const commandOptions = commander.opts<ICommanderOptions>();
211
225
process . stderr . write ( `${ command } : ${ config . repo . owner } /${ config . repo . name } already initialized\n` ) ;
212
226
process . exit ( 1 ) ;
213
227
} catch ( _error ) {
214
- const options : IGitGitGadgetOptions = { allowedUsers : [ commander . args [ 1 ] ] } ;
228
+ const options : IGitGitGadgetOptions = { allowedUsers : [ commander . args [ 1 ] ] } ;
215
229
await ci . notes . set ( "" , options , true ) ;
216
230
217
231
const publishTagsAndNotesToRemote = await getVar ( publishRemoteKey , commandOptions . gitgitgadgetWorkDir ) ;
218
232
219
233
if ( ! publishTagsAndNotesToRemote ) {
220
234
throw new Error ( "No remote to which to push configured" ) ;
221
235
}
222
- await git ( [ "push" , publishTagsAndNotesToRemote , "--" , `${ ci . notes . notesRef } ` ] ,
223
- { workDir : commandOptions . gitWorkDir } ) ;
236
+ await git ( [ "push" , publishTagsAndNotesToRemote , "--" , `${ ci . notes . notesRef } ` ] , {
237
+ workDir : commandOptions . gitWorkDir ,
238
+ } ) ;
224
239
}
225
240
226
241
console . log ( toPrettyJSON ( await ci . getGitGitGadgetOptions ( ) ) ) ;
@@ -243,8 +258,9 @@ const commandOptions = commander.opts<ICommanderOptions>();
243
258
if ( ! publishTagsAndNotesToRemote ) {
244
259
throw new Error ( "No remote to which to push configured" ) ;
245
260
}
246
- await git ( [ "push" , publishTagsAndNotesToRemote , "--" , `${ ci . notes . notesRef } ` ] ,
247
- { workDir : commandOptions . gitWorkDir } ) ;
261
+ await git ( [ "push" , publishTagsAndNotesToRemote , "--" , `${ ci . notes . notesRef } ` ] , {
262
+ workDir : commandOptions . gitWorkDir ,
263
+ } ) ;
248
264
249
265
console . log ( toPrettyJSON ( state ) ) ;
250
266
} else if ( command === "get-mail-meta" ) {
@@ -263,8 +279,9 @@ const commandOptions = commander.opts<ICommanderOptions>();
263
279
const repositoryOwner = commander . args . length === 3 ? commander . args [ 1 ] : config . repo . owner ;
264
280
const prNumber = commander . args [ commander . args . length === 3 ? 2 : 1 ] ;
265
281
266
- const pullRequestURL = prNumber . match ( / ^ h t t p / ) ? prNumber :
267
- `https://github.com/${ repositoryOwner } /${ config . repo . name } /pull/${ prNumber } ` ;
282
+ const pullRequestURL = prNumber . match ( / ^ h t t p / )
283
+ ? prNumber
284
+ : `https://github.com/${ repositoryOwner } /${ config . repo . name } /pull/${ prNumber } ` ;
268
285
console . log ( toPrettyJSON ( await ci . getPRMetadata ( pullRequestURL ) ) ) ;
269
286
} else if ( command === "get-pr-commits" ) {
270
287
if ( commander . args . length !== 2 && commander . args . length !== 3 ) {
@@ -317,8 +334,7 @@ const commandOptions = commander.opts<ICommanderOptions>();
317
334
if ( meta . baseCommit && meta . headCommit ) {
318
335
for ( const rev of await ci . getOriginalCommitsForPR ( meta ) ) {
319
336
const messageID = await ci . notes . getLastCommitNote ( rev ) ;
320
- if ( messageID &&
321
- options . activeMessageIDs [ messageID ] === undefined ) {
337
+ if ( messageID && options . activeMessageIDs [ messageID ] === undefined ) {
322
338
options . activeMessageIDs [ messageID ] = rev ;
323
339
optionsUpdated = true ;
324
340
if ( await ci . updateCommitMapping ( messageID ) ) {
@@ -342,19 +358,15 @@ const commandOptions = commander.opts<ICommanderOptions>();
342
358
process . stderr . write ( `${ command } : need a PR URL and a comment\n` ) ;
343
359
process . exit ( 1 ) ;
344
360
}
345
- const pullRequestURL = commander . args [ 1 ] . match ( / ^ [ 0 - 9 ] + $ / ) ?
346
- `https://github.com/gitgitgadget/${ config . repo . name } /pull/${ commander . args [ 1 ] } ` :
347
- commander . args [ 1 ] ;
361
+ const pullRequestURL = commander . args [ 1 ] . match ( / ^ [ 0 - 9 ] + $ / )
362
+ ? `https://github.com/gitgitgadget/${ config . repo . name } /pull/${ commander . args [ 1 ] } `
363
+ : commander . args [ 1 ] ;
348
364
const comment = commander . args [ 2 ] ;
349
365
350
366
const glue = new GitHubGlue ( ci . workDir , config . repo . owner , config . repo . name ) ;
351
367
await glue . addPRComment ( pullRequestURL , comment ) ;
352
368
} else if ( command === "set-app-token" ) {
353
- const set = async ( options : {
354
- appID : number ;
355
- installationID ?: number ;
356
- name : string ;
357
- } ) : Promise < void > => {
369
+ const set = async ( options : { appID : number ; installationID ?: number ; name : string } ) : Promise < void > => {
358
370
const appName = options . name === config . app . name ? config . app . name : config . app . altname ;
359
371
const appNameKey = `${ appName } .privateKey` ;
360
372
const appNameVar = appNameKey . toUpperCase ( ) . replace ( / \. / , "_" ) ;
@@ -368,21 +380,24 @@ const commandOptions = commander.opts<ICommanderOptions>();
368
380
authStrategy : createAppAuth ,
369
381
auth : {
370
382
appId : options . appID ,
371
- privateKey : key . replace ( / \\ n / g, `\n` )
383
+ privateKey : key . replace ( / \\ n / g, `\n` ) ,
372
384
} ,
373
385
} ) ;
374
386
375
387
if ( options . installationID === undefined ) {
376
- options . installationID =
377
- ( await client . rest . apps . getRepoInstallation ( {
388
+ options . installationID = (
389
+ await client . rest . apps . getRepoInstallation ( {
378
390
owner : options . name ,
379
391
repo : config . repo . name ,
380
- } ) ) . data . id ;
392
+ } )
393
+ ) . data . id ;
381
394
}
382
- const result = await client . rest . apps . createInstallationAccessToken ( {
395
+ const result = await client . rest . apps . createInstallationAccessToken ( {
383
396
installation_id : options . installationID ,
384
- } ) ;
385
- const configKey = options . name === config . app . name ? `${ config . app . name } .githubToken`
397
+ } ) ;
398
+ const configKey =
399
+ options . name === config . app . name
400
+ ? `${ config . app . name } .githubToken`
386
401
: `gitgitgadget.${ options . name } .githubToken` ;
387
402
await git ( [ "config" , configKey , result . data . token ] ) ;
388
403
} ;
0 commit comments