diff --git a/Puc/v4p11/Vcs/GitLabApi.php b/Puc/v4p11/Vcs/GitLabApi.php index 12b3160..3b5a0c5 100644 --- a/Puc/v4p11/Vcs/GitLabApi.php +++ b/Puc/v4p11/Vcs/GitLabApi.php @@ -123,22 +123,40 @@ if ( !class_exists('Puc_v4p11_Vcs_GitLabApi', false) ): )); if ( $this->isAuthenticationEnabled() ) { + $download_url = false; if ( $this->releasePackageEnabled && isset($release->assets, $release->assets->links) ) { /** - * Use the first asset LINK file generated by a Gitlab Release Pipeline + * Use the first asset LINK that is a zip format file generated by a Gitlab Release Pipeline * * @link https://gist.github.com/timwiel/9dfd3526c768efad4973254085e065ce */ - $download_url = $release->assets->links[0]->url; + foreach ($release->assets->links as $link) { + if ( 'zip' === substr($link->url, -3) ) { + $download_url = $link->url; + break 1; + } + } + if ( empty( $download_url ) ) { + return null; + } if ( ! empty( $this->accessToken ) ) { $download_url = add_query_arg('private_token', $this->accessToken, $download_url); } + $reference->downloadUrl = $download_url; } elseif ( $this->releaseAssetsEnabled && isset($release->assets) ) { /** - * Use the first asset SOURCE file from a Gitlab Release which should be a zip file + * Use the first asset SOURCE file that is a zip format from a Gitlab Release which should be a zip file */ - $download_url = $release->assets->sources[0]->url; + foreach ($release->assets->sources as $source) { + if ( 'zip' === $source->format ) { + $download_url = $source->url; + break 1; + } + } + if ( empty( $download_url ) ) { + return null; + } if ( ! empty( $this->accessToken ) ) { $download_url = add_query_arg('private_token', $this->accessToken, $download_url); }