mirror of
https://github.com/RamonGebben/mergify.git
synced 2026-03-10 08:51:18 +00:00
72 lines
1.6 KiB
JavaScript
Executable File
72 lines
1.6 KiB
JavaScript
Executable File
#!/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();
|
|
}
|
|
});
|