Adding checks for the assets to ensure they are zip files which is what wordpress needs to update

This commit is contained in:
Tim Wiel 2021-09-22 12:11:37 +12:00
parent 1c63404e98
commit 824348c036
1 changed files with 22 additions and 4 deletions

View File

@ -123,22 +123,40 @@ if ( !class_exists('Puc_v4p11_Vcs_GitLabApi', false) ):
)); ));
if ( $this->isAuthenticationEnabled() ) { if ( $this->isAuthenticationEnabled() ) {
$download_url = false;
if ( $this->releasePackageEnabled && isset($release->assets, $release->assets->links) ) { 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 * @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 ) ) { if ( ! empty( $this->accessToken ) ) {
$download_url = add_query_arg('private_token', $this->accessToken, $download_url); $download_url = add_query_arg('private_token', $this->accessToken, $download_url);
} }
$reference->downloadUrl = $download_url; $reference->downloadUrl = $download_url;
} elseif ( $this->releaseAssetsEnabled && isset($release->assets) ) { } 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 ) ) { if ( ! empty( $this->accessToken ) ) {
$download_url = add_query_arg('private_token', $this->accessToken, $download_url); $download_url = add_query_arg('private_token', $this->accessToken, $download_url);
} }