Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New styling commando's #402

Merged
merged 12 commits into from
Apr 8, 2015
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
"require": {
"php": ">=5.4",
"ext-curl": "*",
"symfony/console": "~2.5.0",
"symfony/process": "~2.5.0",
"symfony/filesystem": "~2.5.0",
"symfony/finder": "~2.5.0",
"symfony/yaml": "~2.5.0",
"symfony/event-dispatcher": "~2.5.0",
"symfony/property-access": "~2.5.0",
"symfony/console": "~2.7.0@dev",
"symfony/process": "~2.6.0",
"symfony/filesystem": "~2.6.0",
"symfony/finder": "~2.6.0",
"symfony/yaml": "~2.6.0",
"symfony/event-dispatcher": "~2.6.0",
"symfony/property-access": "~2.6.0",
"knplabs/github-api": "~1.3.1",
"ddd/slug": "~1.0.0",
"herrera-io/version": "~1.1.1",
"kherge/amend": "~3.0.0",
"rhumsaa/array_column": "~1.1.2",
"ramsey/array_column": "~1.1.2",
"gushphp/gush-github-adapter": "~1.1.10",
"gushphp/gush-bitbucket-adapter": "~1.1.4",
"gushphp/gush-gitlab-adapter": "~1.1.3",
Expand Down
10 changes: 8 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
-->

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<env name="GIT_VENDOR_NAME" value="gushphp"/>
<ini name="date.timezone" value="America/Lima"/>
<env name="GIT_VENDOR_NAME" value="gushphp"/>

<!-- WARNING These locations are only used for testing, don't use your actual Gush installation! -->
<!--
Expand All @@ -33,6 +33,12 @@
</testsuite>
</testsuites>

<groups>
<exclude>
<group>functional</group>
</exclude>
</groups>

<filter>
<whitelist>
<directory>src</directory>
Expand Down
20 changes: 19 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Gush\Command as Cmd;
use Gush\Event\CommandEvent;
use Gush\Event\GushEvents;
use Gush\Exception\UserException;
use Gush\Factory\AdapterFactory;
use Gush\Helper as Helpers;
use Gush\Helper\OutputAwareInterface;
Expand Down Expand Up @@ -93,6 +94,7 @@ public function __construct(AdapterFactory $adapterFactory, $name = 'Gush', $ver
$helperSet = $this->getDefaultHelperSet();
$helperSet->set(new Helpers\FilesystemHelper());
$helperSet->set(new Helpers\TextHelper());
$helperSet->set(new Helpers\StyleHelper());
$helperSet->set(new Helpers\TableHelper());
$helperSet->set(new Helpers\ProcessHelper());
$helperSet->set(new Helpers\EditorHelper());
Expand All @@ -104,7 +106,7 @@ public function __construct(AdapterFactory $adapterFactory, $name = 'Gush', $ver
$helperSet->get('filesystem')
)
);
$helperSet->set(new Helpers\TemplateHelper($helperSet->get('question'), $this));
$helperSet->set(new Helpers\TemplateHelper($helperSet->get('gush_style'), $this));
$helperSet->set(new Helpers\MetaHelper($this->getSupportedMetaFiles()));
$helperSet->set(new Helpers\AutocompleteHelper());
$helperSet->set(new UpdateHelper());
Expand Down Expand Up @@ -230,6 +232,22 @@ public function getAdapterFactory()
return $this->adapterFactory;
}

/**
* {@inheritdoc}
*/
public function renderException($e, $output)
{
if ($e instanceof UserException) {
$this->getHelperSet()->get('gush_style')->error($e->getMessage());

if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
parent::renderException($e, $output);
}
} else {
parent::renderException($e, $output);
}
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Branch/BranchDeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->getHelper('git')->pushToRemote($org, ':'.$currentBranchName, true);

$output->writeln(sprintf('Branch %s/%s has been deleted!', $org, $currentBranchName));
$this->getHelper('gush_style')->success(
sprintf('Branch %s/%s has been deleted!', $org, $currentBranchName)
);

return self::COMMAND_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Branch/BranchForkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$gitConfigHelper->setRemote($targetOrg, $fork['git_url']);

$output->writeln(
$this->getHelper('gush_style')->success(
sprintf(
'Forked repository %s/%s into %s/%s',
$sourceOrg,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Branch/BranchPushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->getHelper('git')->pushToRemote($org, $branchName, true);

$output->writeln(
$this->getHelper('gush_style')->success(
sprintf('Branch pushed to %s/%s', $org, $branchName)
);

Expand Down
2 changes: 1 addition & 1 deletion src/Command/Branch/BranchRemoteAddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->getHelper('git')->addRemote($remoteName, $fork['git_url']);

$output->writeln(sprintf('Added remote for %s', $org));
$this->getHelper('gush_style')->success(sprintf('Added remote for %s', $org));

return self::COMMAND_SUCCESS;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Branch/BranchSyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ protected function execute(InputInterface $input, OutputInterface $output)

$gitHelper->syncWithRemote($remote, $branchName);

$output->writeln(sprintf('Branch "%s" has been synced with remote "%s".', $branchName, $remote));
$this->getHelper('gush_style')->success(
sprintf('Branch "%s" has been synced with remote "%s".', $branchName, $remote)
);

return self::COMMAND_SUCCESS;
}
Expand Down
58 changes: 27 additions & 31 deletions src/Command/Core/CoreConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

use Gush\Command\BaseCommand;
use Gush\Exception\FileNotFoundException;
use Gush\Exception\UserException;
use Gush\Factory;
use Gush\Feature\GitRepoFeature;
use Symfony\Component\Console\Helper\QuestionHelper;
use Gush\Helper\StyleHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -72,7 +73,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
} catch (FileNotFoundException $exception) {
$this->config = Factory::createConfig(false, false);
} catch (\RuntimeException $exception) {
$output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
$this->getHelper('gush_style')->error(explode("\n", $exception->getMessage()));

$this->config = Factory::createConfig(false, false);
}
Expand All @@ -93,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<error>Configuration file cannot be saved.</error>');
}

$output->writeln('<info>Configuration file saved successfully.</info>');
$this->getHelper('gush_style')->success('Configuration file saved successfully.');

return self::COMMAND_SUCCESS;
}
Expand All @@ -112,17 +113,15 @@ protected function interact(InputInterface $input, OutputInterface $output)
$adapterName = $input->getOption('adapter');
$issueTrackerName = $input->getOption('issue_tracker');

/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getHelper('question');
/** @var StyleHelper $styleHelper */
$styleHelper = $this->getHelper('gush_style');

if (null === $adapterName && null === $issueTrackerName) {
$adapterName = $questionHelper->ask(
$input,
$output,
$adapterName = $styleHelper->askQuestion(
new ChoiceQuestion('Choose adapter: ', array_keys($adapters))
);
} elseif (null !== $adapterName && !array_key_exists($adapterName, $adapters)) {
throw new \InvalidArgumentException(
throw new UserException(
sprintf(
'The adapter "%s" is invalid. Available adapters are "%s"',
$adapterName,
Expand All @@ -136,9 +135,7 @@ protected function interact(InputInterface $input, OutputInterface $output)

$currentDefault = $this->config->get('adapter');
if ($adapterName !== $currentDefault &&
$questionHelper->ask(
$input,
$output,
$styleHelper->askQuestion(
new ConfirmationQuestion(
sprintf('Would you like to make "%s" the default adapter?', $adapterName),
null === $currentDefault
Expand All @@ -150,14 +147,17 @@ protected function interact(InputInterface $input, OutputInterface $output)
}

if (null === $issueTrackerName && null === $input->getOption('adapter')) {
$selection = array_key_exists($adapterName, $issueTrackers) ? $adapterName : null;
$issueTrackerName = $questionHelper->ask(
$input,
$output,
$selection = array_search($adapterName, array_keys($issueTrackers), true);

if (false === $selection) {
$selection = null;
}

$issueTrackerName = $styleHelper->askQuestion(
new ChoiceQuestion('Choose issue tracker: ', array_keys($issueTrackers), $selection)
);
} elseif (null !== $issueTrackerName && !array_key_exists($issueTrackerName, $issueTrackers)) {
throw new \Exception(
throw new UserException(
sprintf(
'The issue tracker "%s" is invalid. Available adapters are "%s"',
$issueTrackerName,
Expand All @@ -171,9 +171,7 @@ protected function interact(InputInterface $input, OutputInterface $output)

$currentDefault = $this->config->get('issue_tracker');
if ($issueTrackerName !== $currentDefault &&
$questionHelper->ask(
$input,
$output,
$styleHelper->askQuestion(
new ConfirmationQuestion(
sprintf('Would you like to make "%s" the default issue tracker?', $issueTrackerName),
null === $currentDefault
Expand All @@ -184,9 +182,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
}
}

$cacheDir = $questionHelper->ask(
$input,
$output,
$cacheDir = $styleHelper->askQuestion(
(new Question(
"Cache folder [{$this->config->get('cache-dir')}]: ",
$this->config->get('cache-dir')
Expand All @@ -205,9 +201,7 @@ function ($dir) {
)
);

$versionEyeToken = $questionHelper->ask(
$input,
$output,
$versionEyeToken = $styleHelper->askQuestion(
(new Question('VersionEye token: ', 'NO_TOKEN'))
->setValidator(
function ($field) {
Expand Down Expand Up @@ -240,6 +234,9 @@ private function configureAdapter(
$authenticationAttempts = 0;
$config = [];

/** @var StyleHelper $styleHelper */
$styleHelper = $this->getHelper('gush_style');

if ('adapters' === $configName) {
$configurator = $application->getAdapterFactory()->createAdapterConfiguration(
$adapterName,
Expand All @@ -255,13 +252,13 @@ private function configureAdapter(
while (!$isAuthenticated) {
// Prevent endless loop with a broken test
if ($authenticationAttempts > 50) {
$output->writeln("<error>To many attempts, aborting.</error>");
$styleHelper->error('Too many attempts, aborting.');

break;
}

if ($authenticationAttempts > 0) {
$output->writeln("<error>Authentication failed please try again.</error>");
$styleHelper->error('Authentication failed please try again.');
}

$config = $configurator->interact($input, $output);
Expand All @@ -273,8 +270,7 @@ private function configureAdapter(
$isAuthenticated = $this->isAdapterCredentialsValid($adapterName, $config);
}
} catch (\Exception $e) {
$output->writeln("<error>{$e->getMessage()}</error>");
$output->writeln('');
$styleHelper->error($e->getMessage());

if ('adapters' !== $configName) {
$adapter = $this->getIssueTracker();
Expand All @@ -283,7 +279,7 @@ private function configureAdapter(
}

if (null !== $adapter && null !== $url = $adapter->getTokenGenerationUrl()) {
$output->writeln("You can create valid access tokens at {$url}.");
$styleHelper->note(['You can create valid access tokens at: ', $url]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/Issue/IssueAssignCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$adapter->updateIssue($issueNumber, ['assignee' => $username]);

$url = $adapter->getIssueUrl($issueNumber);
$output->writeln("Issue {$url} was assigned to {$username}!");
$this->getHelper('gush_style')->success("Issue {$url} was assigned to {$username}!");

return self::COMMAND_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Issue/IssueCloseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$url = $tracker->getIssueUrl($issueNumber);
$output->writeln("Closed {$url}");
$this->getHelper('gush_style')->success("Closed {$url}");

return self::COMMAND_SUCCESS;
}
Expand Down
46 changes: 28 additions & 18 deletions src/Command/Issue/IssueCopyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,40 @@ protected function execute(InputInterface $input, OutputInterface $output)
$adapter->setUsername($targetUsername);
$adapter->setRepository($targetRepository);

$output->writeln(sprintf(
' <info>%s/%s</info>: Opening issue "%s"',
$targetUsername,
$targetRepository,
$srcTitle
));

$adapter->openIssue(
$srcTitle,
$srcIssue['body'],
$srcIssue
$this->getHelper('gush_style')->success(
sprintf(
'Opened issue: %s',
$adapter->getIssueUrl(
$adapter->openIssue(
$srcTitle,
$srcIssue['body'],
$srcIssue
)
)
)
);

$adapter->setUsername($srcUsername);
$adapter->setRepository($srcRepository);

if (true === $close) {
$output->writeln(sprintf(
' <info>%s/%s</info>: Closing issue "<info>%s</info>"',
$srcUsername,
$srcRepository,
$issueNumber
));
$adapter->closeIssue($issueNumber);
if ('closed' === $srcIssue['state']) {
$this->getHelper('gush_style')->error(
sprintf(
'Issue #%d was already closed.',
$issueNumber
)
);
} else {
$adapter->closeIssue($issueNumber);

$this->getHelper('gush_style')->success(
sprintf(
'Closed issue: %s',
$adapter->getIssueUrl($issueNumber)
)
);
}
}

return self::COMMAND_SUCCESS;
Expand Down