Improved Github and Gitlab projects. Issue #163.

This commit is contained in:
Dmitry Khomutov 2018-04-11 23:28:48 +07:00
commit 0fe0249490
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
4 changed files with 227 additions and 50 deletions

View file

@ -374,10 +374,22 @@ class ProjectController extends WebController
$values['pubkey'] = $values['ssh_public_key'];
$values['environments'] = $project->getEnvironments();
if (Project::TYPE_GITLAB === $values['type']) {
$accessInfo = $project->getAccessInformation();
$reference = $accessInfo["user"] . '@' . $accessInfo["domain"] . ':' . $accessInfo["port"] . '/' . ltrim($project->getReference(), '/') . ".git";
$values['reference'] = $reference;
if (in_array($values['type'], [
Project::TYPE_GITHUB,
Project::TYPE_GITLAB
], true)) {
$originReference = $project->getAccessInformation('origin');
if ($originReference) {
$values['reference'] = $originReference;
} else {
$accessInfo = $project->getAccessInformation();
$reference = $accessInfo['user'] . '@' . $accessInfo['domain'] . ':' . ltrim($project->getReference(), '/') . '.git';
if (isset($accessInfo['port']) && $accessInfo['port']) {
$reference = $accessInfo['user'] . '@' . $accessInfo['domain'] . ':' . $accessInfo['port'] . '/' . ltrim($project->getReference(), '/') . '.git';
}
$values['reference'] = $reference;
}
}
if ($method == 'POST') {
@ -535,7 +547,8 @@ class ProjectController extends WebController
protected function getReferenceValidator($values)
{
return function ($val) use ($values) {
$type = $values['type'];
$type = $values['type'];
$gitRegex = '#^((https|http|ssh)://)?((.+)@)?(([^/:]+):?)(:?([0-9]*)/?)(.+)\.git#';
$validators = [
Project::TYPE_HG => [
@ -543,19 +556,19 @@ class ProjectController extends WebController
'message' => Lang::get('error_hg')
],
Project::TYPE_GIT => [
'regex' => '/^(git|https?):\/\//',
'regex' => $gitRegex,
'message' => Lang::get('error_git')
],
Project::TYPE_GITLAB => [
'regex' => '/^(git|https?):\/\//',
'regex' => $gitRegex,
'message' => Lang::get('error_gitlab')
],
Project::TYPE_GITHUB => [
'regex' => '/^(git|https?):\/\//',
'regex' => $gitRegex,
'message' => Lang::get('error_github')
],
Project::TYPE_BITBUCKET => [
'regex' => '/^[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-\.]+$/',
'regex' => $gitRegex,
'message' => Lang::get('error_bitbucket')
],
Project::TYPE_BITBUCKET_HG => [

View file

@ -49,8 +49,8 @@ class GitlabBuild extends GitBuild
$key = trim($this->getProject()->getSshPrivateKey());
if (!empty($key)) {
$user = $this->getProject()->getAccessInformation("user");
$domain = $this->getProject()->getAccessInformation("domain");
$user = $this->getProject()->getAccessInformation('user');
$domain = $this->getProject()->getAccessInformation('domain');
$port = $this->getProject()->getAccessInformation('port');
$url = $user . '@' . $domain . ':';

View file

@ -143,7 +143,6 @@ class ProjectService
*/
protected function processAccessInformation(Project $project)
{
$matches = [];
$reference = $project->getReference();
if (in_array($project->getType(), [
@ -152,12 +151,30 @@ class ProjectService
], true)) {
$info = [];
if (preg_match('`^(.+)@(.+):([0-9]*)\/?(.+)\.git`', $reference, $matches)) {
$info['user'] = $matches[1];
$info['domain'] = $matches[2];
$info['port'] = $matches[3];
if (preg_match(
'#^((https|http|ssh)://)?((.+)@)?(([^/:]+):?)(:?([0-9]*)/?)(.+)\.git#',
$reference,
$matches
)) {
if (isset($matches[4]) && $matches[4]) {
$info['user'] = $matches[4];
}
$project->setReference($matches[4]);
if (isset($matches[6]) && $matches[6]) {
$info['domain'] = $matches[6];
}
if (isset($matches[8]) && $matches[8]) {
$info['port'] = $matches[8];
}
if (isset($matches[9]) && $matches[9]) {
$info['reference'] = $matches[9];
$project->setReference($matches[9]);
}
$info['origin'] = $reference;
}
$project->setAccessInformation($info);