Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b23c2b7

Browse files
Benjamin E. CoeJustinBeckwith
authored andcommitted
feat: make samples/update-branch-protection.js is a flexible CLI (googleapis#303)
1 parent 5083df6 commit b23c2b7

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

samples/update-branch-protection.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
'use strict';
2121

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');
2325

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);
2929

3030
const repos = await github.getRepositories();
3131
for (const repository of repos) {
@@ -45,8 +45,14 @@ async function main() {
4545
}
4646

4747
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+
}
5056

5157
try {
5258
await repository.updateRequiredMasterBranchProtectionStatusChecks(
@@ -59,6 +65,18 @@ async function main() {
5965
}
6066
}
6167

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

Comments
 (0)