Added support for GitLab subgroups as described in #241

(Untested.)
This commit is contained in:
Yahnis Elsts 2018-12-03 15:21:45 +02:00
parent 14bd39a492
commit 871c1006c5
2 changed files with 16 additions and 2 deletions

View File

@ -190,9 +190,14 @@ if ( !class_exists('Puc_v4p4_Factory', false) ):
//Which hosting service does the URL point to?
$host = @parse_url($metadataUrl, PHP_URL_HOST);
$path = @parse_url($metadataUrl, PHP_URL_PATH);
//Check if the path looks like "/user-name/repository".
$usernameRepoRegex = '@^/?([^/]+?)/([^/#?&]+?)/?$@';
if ( preg_match($usernameRepoRegex, $path) ) {
//For GitLab.com it can also be "/user/group1/group2/.../repository".
$repoRegex = '@^/?([^/]+?)/([^/#?&]+?)/?$@';
if ( $host === 'gitlab.com' ) {
$repoRegex = '@^/?(?:[^/#?&]++/){1,20}(?:[^/#?&]++)/?$@';
}
if ( preg_match($repoRegex, $path) ) {
$knownServices = array(
'github.com' => 'GitHub',
'bitbucket.org' => 'BitBucket',

View File

@ -36,6 +36,15 @@ if ( !class_exists('Puc_v4p4_Vcs_GitLabApi', false) ):
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
$this->userName = $matches['username'];
$this->repositoryName = $matches['repository'];
} elseif ( ($this->repositoryHost === 'gitlab.com') ) {
//This is probably a repository in a subgroup, e.g. "/organization/category/repo".
$parts = explode('/', trim($path, '/'));
if ( count($parts) < 3 ) {
throw new InvalidArgumentException('Invalid GitLab.com repository URL: "' . $repositoryUrl . '"');
}
$lastPart = array_pop($parts);
$this->userName = implode('/', $parts);
$this->repositoryName = $lastPart;
} else {
//This is not a traditional url, it could be gitlab is in a deeper subdirectory.
//Get the path segments.