diff --git a/CHANGES.md b/CHANGES.md index e8064dc34..33247a94d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,5 @@ #### [unreleased] -* use `browser_download_url` for GitHub release asset when available otherwise get redirect url +* update GitHub release asset parsing #### 12.7.2 / 2024-12-18 * update `freemius/wordpress-sdk` diff --git a/git-updater.php b/git-updater.php index 1bde1479e..c617ff83b 100644 --- a/git-updater.php +++ b/git-updater.php @@ -12,7 +12,7 @@ * Plugin Name: Git Updater * Plugin URI: https://git-updater.com * Description: A plugin to automatically update GitHub hosted plugins, themes, and language packs. Additional API plugins available for Bitbucket, GitLab, Gitea, and Gist. - * Version: 12.7.2.1 + * Version: 12.7.2.2 * Author: Andy Fragen * License: MIT * Domain Path: /languages diff --git a/src/Git_Updater/API/GitHub_API.php b/src/Git_Updater/API/GitHub_API.php index a91c740c7..dbceca276 100644 --- a/src/Git_Updater/API/GitHub_API.php +++ b/src/Git_Updater/API/GitHub_API.php @@ -126,18 +126,11 @@ public function construct_download_link( $branch_switch = false ) { if ( $this->use_release_asset( $branch_switch ) ) { $release_asset = $this->get_release_asset(); - if ( ! isset( $this->response['release_asset_download'] ) ) { - $auth_header = $this->add_auth_header( $this->default_http_get_args, $release_asset ); - $response = wp_remote_get( $release_asset, $auth_header ); - if ( is_wp_error( $response ) ) { - return $response; - } - $response = json_decode( wp_remote_retrieve_body( $response ) ); - if ( property_exists( $response, 'browser_download_url' ) ) { - $this->set_repo_cache( 'release_asset_download', $response->browser_download_url ); - } + if ( empty( $this->response['release_asset_download'] ) ) { + $response = $this->api( $release_asset ); + $this->parse_release_asset_response( $response ); } - if ( isset( $this->response['release_asset_download'] ) ) { + if ( ! empty( $this->response['release_asset_download'] ) ) { return $this->response['release_asset_download']; } @@ -325,6 +318,22 @@ public function parse_branch_response( $response ) { return $branches; } + /** + * Parse release asset API response. + * + * @param \stdClass $response API response. + * + * @return void + */ + public function parse_release_asset_response( $response ) { + if ( $this->validate_response( $response ) ) { + return; + } + if ( property_exists( $response, 'browser_download_url' ) ) { + $this->set_repo_cache( 'release_asset_download', $response->browser_download_url ); + } + } + /** * Parse tags and create download links. *