19
19
20
20
'use strict' ;
21
21
22
- const GitHub = require ( '../build/src/lib/github.js' ) ;
22
+ const meow = require ( 'meow' ) ;
23
+ const { getConfig} = require ( '../build/src/lib/config.js' ) ;
24
+ const { GitHub} = require ( '../build/src/lib/github' ) ;
23
25
24
- async function main ( ) {
25
- const toRemove = 'ci/circleci: node7' ;
26
-
27
- const github = new GitHub ( ) ;
28
- await github . init ( ) ;
26
+ async function main ( input ) {
27
+ const config = await getConfig ( ) ;
28
+ const github = new GitHub ( config ) ;
29
29
30
30
const repos = await github . getRepositories ( ) ;
31
31
for ( const repository of repos ) {
@@ -45,8 +45,14 @@ async function main() {
45
45
}
46
46
47
47
const contexts = statusChecks [ 'contexts' ] ;
48
- const index = contexts . indexOf ( toRemove ) ;
49
- contexts . splice ( index , 1 ) ;
48
+ if ( input [ 0 ] === 'remove' ) {
49
+ const index = contexts . indexOf ( input [ 1 ] ) ;
50
+ contexts . splice ( index , 1 ) ;
51
+ } else if ( input [ 0 ] === 'add' ) {
52
+ contexts . push ( input [ 1 ] ) ;
53
+ } else {
54
+ throw Error ( `unrecognized command ${ input [ 0 ] } ` ) ;
55
+ }
50
56
51
57
try {
52
58
await repository . updateRequiredMasterBranchProtectionStatusChecks (
@@ -59,6 +65,18 @@ async function main() {
59
65
}
60
66
}
61
67
62
- main ( ) . catch ( err => {
63
- console . error ( err . toString ( ) ) ;
64
- } ) ;
68
+ const cli = meow (
69
+ `
70
+ Usage
71
+ $ node update-branch-protection.js remove "ci/kokoro: node11"
72
+ $ node update-branch-protection.js add "ci/kokoro: node12"
73
+ `
74
+ ) ;
75
+
76
+ if ( cli . input . length < 2 ) {
77
+ cli . showHelp ( - 1 ) ;
78
+ } else {
79
+ main ( cli . input ) . catch ( err => {
80
+ console . error ( err . toString ( ) ) ;
81
+ } ) ;
82
+ }
0 commit comments