diff --git a/Puc/v4p8/Vcs/GitLabApi.php b/Puc/v4p8/Vcs/GitLabApi.php index 87ef8f9..41f29fc 100644 --- a/Puc/v4p8/Vcs/GitLabApi.php +++ b/Puc/v4p8/Vcs/GitLabApi.php @@ -28,7 +28,7 @@ if ( !class_exists('Puc_v4p8_Vcs_GitLabApi', false) ): */ protected $accessToken; - public function __construct($repositoryUrl, $accessToken = null) { + public function __construct($repositoryUrl, $accessToken = null, $subgroup = null) { //Parse the repository host to support custom hosts. $port = parse_url($repositoryUrl, PHP_URL_PORT); if ( !empty($port) ){ @@ -55,6 +55,12 @@ if ( !class_exists('Puc_v4p8_Vcs_GitLabApi', false) ): $this->userName = implode('/', $parts); $this->repositoryName = $lastPart; } else { + // there is a subgroup in the url: gitlab.domain.com/group/subgroup/repository + // maybe there nested subgroups: gitlab.domain.com/group/subgroup/subgroup2/repository + if ($subgroup !== null) { + $path = str_replace(trailingslashit($subgroup), '', $path); + } + //This is not a traditional url, it could be gitlab is in a deeper subdirectory. //Get the path segments. $segments = explode('/', untrailingslashit(ltrim($path, '/'))); @@ -69,8 +75,15 @@ if ( !class_exists('Puc_v4p8_Vcs_GitLabApi', false) ): $this->userName = $usernameRepo[0]; $this->repositoryName = $usernameRepo[1]; - //Append the remaining segments to the host. - $this->repositoryHost = trailingslashit($this->repositoryHost) . implode('/', $segments); + //Append the remaining segments to the host if there are segments left. + if (count($segments) > 0) { + $this->repositoryHost = trailingslashit($this->repositoryHost) . implode('/', $segments); + } + + // add subgroups to username + if ($subgroup !== null) { + $this->userName = $usernameRepo[0] . '/' . untrailingslashit($subgroup); + } } parent::__construct($repositoryUrl, $accessToken); diff --git a/README.md b/README.md index 7b12df7..c2cfcac 100644 --- a/README.md +++ b/README.md @@ -251,7 +251,16 @@ BitBucket doesn't have an equivalent to GitHub's releases, so the process is sli ); //Optional: Add setAuthentication(...) and setBranch(...) as shown above. ``` - + If you're using a self-hosted GitLab instance and [subgroups or nested groups](https://docs.gitlab.com/ce/user/group/subgroups/index.html) you have to tell the update checker, which folders are subgroups: + ```php + $myUpdateChecker = new Puc_v4p8_Vcs_PluginUpdateChecker( + new Puc_v4p8_Vcs_GitLabApi('https://myserver.com/group-name/subgroup-level1/subgroup-level2/subgroup-level3/repo-name/', null, 'subgroup-level1/subgroup-level2/subgroup-level3'), + __FILE__, + 'unique-plugin-or-theme-slug' + ); + + ``` + 3. Plugins only: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. The contents of this file will be shown when the user clicks the "View version 1.2.3 details" link. #### How to Release an Update