Skip to content

Commit

Permalink
Update help and behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Aug 11, 2016
1 parent cba9fda commit 640bea2
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Command/PullRequest/PullRequestMergeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function configure()
->addOption('force-squash', null, InputOption::VALUE_NONE, 'Force squashing the PR, even if there are multiple authors (this will implicitly use --squash)')
->addOption('switch', null, InputOption::VALUE_REQUIRED, 'Switch the base of the pull request before merging')
->addOption('pat', null, InputOption::VALUE_REQUIRED, 'Give the PR\'s author a pat on the back after the merge')
->addOption('remove-source-branch', null, InputOption::VALUE_NONE, 'Remove remote source branch after merging own pull request')
->addOption('remove-source-branch', null, InputOption::VALUE_REQUIRED, 'Remove remote source branch after merging own pull request', 'no')
->setHelp(
<<<'EOF'
The <info>%command.name%</info> command merges the given pull request:
Expand Down Expand Up @@ -101,10 +101,11 @@ protected function configure()
<comment>The whole pat configuration will be ignored and no pat will be placed if the pull request is authored by yourself!</comment>
If you are the author of the pull request, <comment>--remove-source-branch</comment> can be used in order to remove the remote source
branch after a successful merge:
If you are the author of the pull request, you'll be prompted if the remote source
branch will be removed after a successful merge.
Also, you can pass your choice for this action with the <comment>--remove-source-branch</comment> option:
<info>$ gush %command.name% --remove-source-branch</info>
<info>$ gush %command.name% --remove-source-branch=[yes|no]</info>
EOF
)
;
Expand Down Expand Up @@ -149,7 +150,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$authenticatedUser = $this->getParameter($input, 'authentication')['username'];
$removeSourceBranch = $input->getOption('remove-source-branch');
if ($removeSourceBranch && $pr['user'] !== $authenticatedUser) {
if ('yes' === $removeSourceBranch && $pr['user'] !== $authenticatedUser) {
throw new UserException(sprintf('`--remove-source-branch` option cannot be used with pull requests that aren\'t owned by the authenticated user (%s)', $authenticatedUser));
}

Expand Down Expand Up @@ -209,17 +210,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->addClosedPullRequestNote($pr, $mergeCommit, $squash, $input->getOption('switch'));
}

$styleHelper->success([$mergeNote, $pr['url']]);

// Post merge options
if ($pr['user'] === $authenticatedUser) {
if ($removeSourceBranch) {
if ('yes' !== $removeSourceBranch) {
$removeSourceBranch = $this->getHelper('gush_style')->choice('Delete source branch?', ['yes', 'no'], 'no');
}
if ('yes' === $removeSourceBranch) {
$adapter->removePullRequestSourceBranch($pr['number']);
$styleHelper->note(sprintf('Remote source branch %s:%s has been removed.', $sourceRemote, $sourceBranch));
}
} elseif ($patComment = $this->givePatToPullRequestAuthor($pr, $input->getOption('pat'))) {
$styleHelper->note(sprintf('Pat given to @%s at %s.', $pr['user'], $patComment));
}

$styleHelper->success([$mergeNote, $pr['url']]);

return self::COMMAND_SUCCESS;
} catch (CannotSquashMultipleAuthors $e) {
$styleHelper->error([
Expand Down

0 comments on commit 640bea2

Please sign in to comment.