-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·71 lines (61 loc) · 1.58 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env node
'use strict';
const program = require('commander');
const pack = require('./package.json');
const { logger } = require('./lib/utils/logger');
const { configure } = require('./lib/commands/configure');
const { verify } = require('./lib/commands/verify');
const { getAllAssigned } = require('./lib/commands/getAllAssigned');
const { getAllSubmitted } = require('./lib/commands/getAllSubmitted');
const { readConfig } = require('./lib/utils/readConfig');
program
.name('mergify')
.version(pack.version);
const commands = [
{
trigger: 'assigned',
description: 'Get all open merge request assigned to you',
fn: getAllAssigned
},
{
trigger: 'submitted',
description: 'Get all open merge request submitted to you',
fn: getAllSubmitted
},
{
trigger: 'configure',
description: 'Setup or update required config',
fn: configure
},
{
trigger: 'verify',
description: 'Verify your config is correct',
fn: verify
}
];
const run = async() => {
let config = await readConfig();
const {
userId,
privateToken
} = config;
if (!program.version && (!userId || !privateToken)) {
await configure();
config = await readConfig();
await verify();
}
commands.forEach(({ trigger, description, fn }) => {
program
.command(trigger)
.description(description)
.action((...args) => fn(config, ...args));
});
return program;
};
run().then(p => {
p.parse(process.argv);
if (!process.argv.slice(2).length) {
logger.log('No arguments specified, showing help.');
p.outputHelp();
}
});