-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·59 lines (53 loc) · 1.53 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/env node
'use strict';
const syncBitbucketBranch = require('./index.js');
let dryrun;
let repo;
let sourceBranch;
let targetBranch;
let email;
let password;
// inspect the args passed at the command line and set dryrun, repo, sourceBranch, targetBranch
for (const arg of process.argv.slice(2)) {
if (dryrun === undefined && arg === '--dryrun') {
dryrun = true;
}
else if (repo === undefined) {
repo = arg;
}
else if (sourceBranch === undefined) {
sourceBranch = arg;
}
else if (targetBranch === undefined) {
targetBranch = arg;
}
else if (email === undefined) {
email = arg;
}
else if (password === undefined) {
password = arg;
}
}
if (email === undefined) {
email = process.env.BITBUCKET_ACCOUNT_EMAIL;
}
if (password === undefined) {
password = process.env.BITBUCKET_ACCOUNT_PASSWORD;
}
if (!repo || !targetBranch || !email || !password) {
console.error('sync-bitbucket-branch [--dryrun]' // eslint-disable-line no-console
+ ' <repo> <source-branch> <target-branch> [<email>] [<password>]\n'
+ 'email and password may be set using environment variables'
+ ' BITBUCKET_ACCOUNT_EMAIL and BITBUCKET_ACCOUNT_PASSWORD'
);
process.exit(); // eslint-disable-line no-process-exit
}
syncBitbucketBranch(repo, sourceBranch, targetBranch, email, password, dryrun)
.then(() => {
console.log(`${repo} ${sourceBranch} merged into ${targetBranch}`); // eslint-disable-line no-console
})
.catch((err) => {
console.error(err); // eslint-disable-line no-console
process.exit(1); // eslint-disable-line no-process-exit
})
;