diff --git a/Puc/v4/Factory.php b/Puc/v4/Factory.php index 458d4a3..efa59ac 100644 --- a/Puc/v4/Factory.php +++ b/Puc/v4/Factory.php @@ -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; diff --git a/Puc/v4p2/Vcs/GitLabApi.php b/Puc/v4p2/Vcs/GitLabApi.php index c3feb4e..2f2d25d 100644 --- a/Puc/v4p2/Vcs/GitLabApi.php +++ b/Puc/v4p2/Vcs/GitLabApi.php @@ -37,8 +37,24 @@ if ( ! class_exists( 'Puc_v4p2_Vcs_GitLabApi', false ) ) : if ( preg_match( '@^/?(?P[^/]+?)/(?P[^/#?&]+?)/?$@', $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 );