{"size": 1616, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "RamonGebben/mergify", "max_stars_repo_stars_event_min_datetime": "2018-03-29T12:10:09.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-29T16:39:17.000Z", "max_issues_repo_path": "index.js", "max_issues_repo_name": "RamonGebben/mergify", "max_issues_repo_issues_event_min_datetime": "2018-03-29T13:38:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T15:39:35.000Z", "max_forks_repo_path": "index.js", "max_forks_repo_name": "RamonGebben/mergify", "max_forks_repo_forks_event_min_datetime": "2018-04-18T14:01:39.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-20T15:55:27.000Z"}
{"max_stars_count": 3, "max_issues_count": 44, "max_forks_count": 2, "avg_line_length": 22.4444444444, "max_line_length": 70, "alphanum_fraction": 0.6293316832}
#!/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();
  }
});
