#!/usr/bin/env php
<?php

/*
 * This file is part of Gush.
 *
 * (c) Luis Cordova <cordoval@gmail.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

require __DIR__.'/../src/bootstrap.php';

use Gush\Adapter;
use Gush\ConfigFactory;

error_reporting(-1);
ini_set('display_errors', 1);

$process = new Symfony\Component\Process\Process('git --version', getcwd());
$process->run();

if (!$process->isSuccessful()) {
    throw new \RuntimeException('Git is required.');
}

$version = trim(explode(' ', $process->getOutput())[2]);
if (version_compare($version, '1.9.1', 'lt')) {
    throw new \RuntimeException('It is advisable to upgrade your version of GIT to 1.9.1 or latest.');
}

$adapterFactory = new Gush\Factory\AdapterFactory();

$adapters = [
    'github' => ['Gush\ThirdParty\Github\GitHubFactory', 'GitHub'],
    'github_enterprise' => ['Gush\ThirdParty\Github\GitHubEnterpriseFactory', 'GitHub Enterprise'],
    'bitbucket' => ['Gush\ThirdParty\Bitbucket\BitbucketFactory', 'Bitbucket'],
    'gitlab' => ['Gush\ThirdParty\Gitlab\GitLabFactory', 'GitLab'],
    'jira' => ['Gush\ThirdParty\Jira\JiraFactory', 'Jira'],
    'jira_enterprise' => ['Gush\ThirdParty\Jira\JiraEnterpriseFactory', 'Jira Enterprise'],
];

foreach ($adapters as $adapterName => $adapter) {
    $adapterFactory->register($adapterName, $adapter[1], $adapter[0]);
}

(new Gush\Application($adapterFactory, ConfigFactory::createConfig(getcwd())))->run();
