support gitlab instances installed in a subdirectory
no longer checking for 'gitlab' in the hostname
This commit is contained in:
parent
ccc07e9ce3
commit
a2ca0ba0f2
|
|
@ -180,10 +180,11 @@ if ( !class_exists('Puc_v4_Factory', false) ):
|
|||
if ( isset($knownServices[$host]) ) {
|
||||
$service = $knownServices[$host];
|
||||
}
|
||||
// support gitlab subdomain for self hosting (e.g. https://gitlab.x.tld)
|
||||
else if ( strpos( $host, 'gitlab' ) !== FALSE ) {
|
||||
$service = 'GitLab';
|
||||
}
|
||||
}
|
||||
|
||||
// not self-hosted (.json) and the service host is still unknown, this looks like a custom GitLab server
|
||||
if ( ! isset( $service ) && strpos( $path, '.json' ) === FALSE ) {
|
||||
$service = 'GitLab';
|
||||
}
|
||||
|
||||
return $service;
|
||||
|
|
|
|||
|
|
@ -37,8 +37,24 @@ if ( ! class_exists( 'Puc_v4p2_Vcs_GitLabApi', false ) ) :
|
|||
if ( preg_match( '@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches ) ) {
|
||||
$this->userName = $matches['username'];
|
||||
$this->repositoryName = $matches['repository'];
|
||||
} else {
|
||||
throw new InvalidArgumentException( 'Invalid GitLab repository URL: "' . $repositoryUrl . '"' );
|
||||
}
|
||||
// this is not a traditional url, it could be gitlab is in a deeper subdirectory
|
||||
else {
|
||||
// get the path segments
|
||||
$segments = explode( '/', untrailingslashit( ltrim( $path, '/' ) ) );
|
||||
|
||||
// we need atleast /user-name/repository-name/
|
||||
if ( sizeof ( $segments ) < 2 ) {
|
||||
throw new InvalidArgumentException( 'Invalid GitLab repository URL: "' . $repositoryUrl . '"' );
|
||||
}
|
||||
|
||||
// get the username and repository name
|
||||
$usernameRepo = array_splice( $segments, -2, 2 );
|
||||
$this->userName = $usernameRepo[0];
|
||||
$this->repositoryName = $usernameRepo[1];
|
||||
|
||||
// append the remaining segments to the host
|
||||
$this->repositoryHost = trailingslashit( $this->repositoryHost ) . implode( '/', $segments );
|
||||
}
|
||||
|
||||
parent::__construct( $repositoryUrl, $accessToken );
|
||||
|
|
|
|||
Loading…
Reference in New Issue