Skip to content

Commit

Permalink
up: support branch alias for open PR
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 7, 2021
1 parent 072bb31 commit bbe1cdc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
35 changes: 34 additions & 1 deletion app/Common/GitLocal/AbstractGitLocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public function parseRemote(string $remote = ''): self
$this->setRemote($remote);
}

Color::println('find and parse remote info ...', 'normal');
$str = 'git remote get-url --push ' . $this->remote;
$run = CmdRunner::new($str, $this->workDir);
$url = $run->do()->getOutput(true);
Expand Down Expand Up @@ -339,7 +340,6 @@ public function loadCurPjInfo(string $pjName = ''): self
return $this;
}


/**
* @param string $repo
* @param bool $useGitUrl
Expand Down Expand Up @@ -371,6 +371,28 @@ public function parseRepoUrl(string $repo, bool $useGitUrl = false): string
return $repoUrl;
}

/**
* @param string $alias
*
* @return string
*/
public function getRealBranchName(string $alias): string
{
if (isset($this->config['branchAliases'])) {
return $this->config['branchAliases'][$alias] ?? $alias;
}

return $alias;
}

/**
* @return array
*/
public function getBranchAliases(): array
{
return $this->config['branchAliases'] ?? [];
}

/**
* @return string
*/
Expand Down Expand Up @@ -406,6 +428,17 @@ public function getValue(string $key, $default = null)
return $this->config[$key] ?? $default;
}

/**
* @param string $key
* @param mixed $default
*
* @return mixed
*/
public function getParam(string $key, $default = null)
{
return $this->config[$key] ?? $default;
}

/**
* @param array $config
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Common/GitLocal/GitLab.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function findPjName(): string
if (!$pjName) {
$info = $this->parseRemote()->getRemoteInfo();
$path = $info['path'] ?? '';

// \vdump($info);
if ($path && isset($this->projects[$path])) {
$pjName = $path;

Expand Down
6 changes: 4 additions & 2 deletions app/Console/Controller/GitLabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static function aliases(): array
protected function groupOptions(): array
{
return [
'-y, --yes' => 'Direct execution without confirmation',
'-y, --yes' => 'Direct execution without confirmation',
'-i, --interactive' => 'Run in an interactive environment[TODO]',
];
}

Expand Down Expand Up @@ -463,7 +464,8 @@ public function pullRequestCommand(Input $input, Output $output): void
$output->info('auto fetch current branch name');
$curBranch = GitUtil::getCurrentBranchName();
$srcBranch = $input->getSameStringOpt(['s', 'source']);
$tgtBranch = $input->getSameStringOpt(['t', 'target']);
$tgtBranch = $input->getSameStringOpt('t,target');
$tgtBranch = $gitlab->getRealBranchName($tgtBranch);

if ($fullSBranch = $input->getStringOpt('full-source')) {
$srcBranch = $fullSBranch;
Expand Down

0 comments on commit bbe1cdc

Please sign in to comment.