Skip to content

Commit

Permalink
update soe
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 6, 2020
1 parent 119e080 commit 1b5365d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions app/Console/Group/GitLabGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
use Inhere\Console\Exception\PromptException;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Kite\Helper\AppHelper;
use Inhere\Kite\Helper\GitUtil;
use function array_merge;
use function explode;
use function http_build_query;
use function in_array;
use function parse_str;
use function parse_url;
use function trim;
Expand Down Expand Up @@ -106,6 +108,7 @@ protected function prLinkConfigure(Input $input): void
* @options
* -s, --source The source branch
* -t, --target The target branch
* -o, --open Open the generated PR link on browser
* --sync The target branch will same source branch
*
* @argument
Expand All @@ -132,7 +135,7 @@ public function prLinkCommand(Input $input, Output $output): void
$pjInfo = $this->projects[$pjName];

$link = $this->config['hostUrl'];
$link .= "/{$pjInfo['group']}/{$pjInfo['group']}/merge_requests/new?";
$link .= "/{$pjInfo['group']}/{$pjInfo['name']}/merge_requests/new?";

$brPrefix = $this->config['branchPrefix'];
$fixedBrs = $this->config['fixedBranch'];
Expand All @@ -141,20 +144,19 @@ public function prLinkCommand(Input $input, Output $output): void
$forkPjId = $pjInfo['forkProjectId'];

$curBranch = GitUtil::getCurrentBranchName();

$srcBranch = $input->getSameStringOpt(['s', 'source']);
$tgtBranch = $input->getSameStringOpt(['t', 'target']);

if ($srcBranch ) {
if (!\in_array($srcBranch, $fixedBrs, true)) {
if (!in_array($srcBranch, $fixedBrs, true)) {
$srcBranch = $brPrefix . $srcBranch;
}
} else {
$srcBranch = $curBranch;
}

if ($tgtBranch) {
if (!\in_array($tgtBranch, $fixedBrs, true)) {
if (!in_array($tgtBranch, $fixedBrs, true)) {
$tgtBranch = $brPrefix . $tgtBranch;
}
} else {
Expand All @@ -171,15 +173,21 @@ public function prLinkCommand(Input $input, Output $output): void
$tipInfo = array_merge([
'project' => $pjName,
], $prInfo);
$output->aList($tipInfo, 'PR information', ['ucFirst' => false]);
$output->aList($tipInfo, 'information', ['ucFirst' => false]);
$query = [
'utf8' => '',
'merge_request' => $prInfo
];

$queryString = http_build_query($query, '', '&');
$link .= http_build_query($query, '', '&');

if ($input->getSameBoolOpt(['o', 'open'])) {
// $output->info('will auto open link on browser');
AppHelper::openBrowser($link);
} else {
$output->colored("PR Link:\n " . $link);
}

$output->info("PR link:\n " . $link . $queryString);
$output->success('Complete');
}

Expand Down
2 changes: 1 addition & 1 deletion app/Helper/AppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ public static function openBrowser(string $pageUrl): void
}

Show::info("Will open the page on browser: $pageUrl");
Sys::execute($cmd . ' ' . $pageUrl);
Sys::execute($cmd . " \"{$pageUrl}\"");
}
}

0 comments on commit 1b5365d

Please sign in to comment.