Skip to content

Commit

Permalink
refactor GitHub release asset parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
afragen committed Dec 18, 2024
1 parent 95935fd commit 599bb25
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion git-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 20 additions & 11 deletions src/Git_Updater/API/GitHub_API.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 599bb25

Please sign in to comment.