From 1c1fd43a176c3a750143429450b603a0345cad08 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 18 Dec 2024 01:37:08 -0800 Subject: [PATCH 01/13] duplicate conditional --- src/Git_Updater/Traits/API_Common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Git_Updater/Traits/API_Common.php b/src/Git_Updater/Traits/API_Common.php index 64d05f70d..cb8e6ecce 100644 --- a/src/Git_Updater/Traits/API_Common.php +++ b/src/Git_Updater/Traits/API_Common.php @@ -342,7 +342,7 @@ final public function get_api_release_asset( $git, $request ) { } } - if ( $response && ( ! isset( $this->response['release_asset'] ) || ! $this->response['release_asset'] ) ) { + if ( $response && ! $this->response['release_asset'] ) { $this->set_repo_cache( 'release_asset', $response ); } From 2724ac947e5cc224a68393a23c13fc0e54c75ad7 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 18 Dec 2024 01:38:43 -0800 Subject: [PATCH 02/13] group booleans --- src/Git_Updater/REST/REST_API.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Git_Updater/REST/REST_API.php b/src/Git_Updater/REST/REST_API.php index 4c56d21a0..363bef90e 100644 --- a/src/Git_Updater/REST/REST_API.php +++ b/src/Git_Updater/REST/REST_API.php @@ -405,7 +405,8 @@ public function get_api_data( \WP_REST_Request $request ) { $repo_cache = $this->get_repo_cache( $slug ); - if ( $repo_api_data['download_link'] && $repo_api_data['is_private'] || in_array( $repo_api_data['git'], [ 'gitlab', 'gitea' ], true ) + if ( $repo_api_data['download_link'] + && ( $repo_api_data['is_private'] || in_array( $repo_api_data['git'], [ 'gitlab', 'gitea' ], true ) ) ) { $repo_api_data['auth_header'] = Singleton::get_instance( 'Fragen\Git_Updater\API\API', $this )->add_auth_header( [], $repo_api_data['download_link'] ); $repo_api_data['auth_header'] = Singleton::get_instance( 'Fragen\Git_Updater\API\API', $this )->unset_release_asset_auth( $repo_api_data['auth_header'], $repo_api_data['download_link'] ); From 6432705043bc72cc3aa6d438a8f564f4c5a6f917 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 18 Dec 2024 01:41:58 -0800 Subject: [PATCH 03/13] user browser_download_url for release asset if not available, use redirect --- CHANGES.md | 1 + git-updater.php | 2 +- src/Git_Updater/API/GitHub_API.php | 15 +++++++++++++++ src/Git_Updater/REST/REST_API.php | 4 ++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2064f9354..e8064dc34 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,5 @@ #### [unreleased] +* use `browser_download_url` for GitHub release asset when available otherwise get redirect url #### 12.7.2 / 2024-12-18 * update `freemius/wordpress-sdk` diff --git a/git-updater.php b/git-updater.php index e83451226..1bde1479e 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 + * Version: 12.7.2.1 * 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 d2af51c5f..a91c740c7 100644 --- a/src/Git_Updater/API/GitHub_API.php +++ b/src/Git_Updater/API/GitHub_API.php @@ -126,6 +126,21 @@ 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 ( isset( $this->response['release_asset_download'] ) ) { + return $this->response['release_asset_download']; + } + return $this->get_release_asset_redirect( $release_asset, true ); } diff --git a/src/Git_Updater/REST/REST_API.php b/src/Git_Updater/REST/REST_API.php index 363bef90e..253353e4c 100644 --- a/src/Git_Updater/REST/REST_API.php +++ b/src/Git_Updater/REST/REST_API.php @@ -413,8 +413,8 @@ public function get_api_data( \WP_REST_Request $request ) { } if ( $download && $repo_data->release_asset ) { - if ( isset( $repo_cache['release_asset_redirect'] ) ) { - $repo_api_data['download_link'] = $repo_cache['release_asset_redirect']; + if ( isset( $repo_cache['release_asset_download'] ) ) { + $repo_api_data['download_link'] = $repo_cache['release_asset_download']; } elseif ( $repo_cache['release_asset'] ) { $_REQUEST['override'] = true; $repo_api_data['download_link'] = Singleton::get_instance( 'Fragen\Git_Updater\API\API', $this )->get_release_asset_redirect( $repo_cache['release_asset'], true ); From 95935fd220be81168a28e90f56fa07f7fd071377 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 18 Dec 2024 09:12:05 -0800 Subject: [PATCH 04/13] release asset passed as API endpoint --- src/Git_Updater/API/API.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Git_Updater/API/API.php b/src/Git_Updater/API/API.php index 7fb3a593b..b2feb06e6 100644 --- a/src/Git_Updater/API/API.php +++ b/src/Git_Updater/API/API.php @@ -327,7 +327,10 @@ public function get_api_url( $endpoint, $download_link = false ) { */ $type = apply_filters( 'gu_api_url_type', $type, $this->type, $download_link, $endpoint ); - $base = $download_link ? $type['base_download'] : $type['base_uri']; + $base = $download_link ? $type['base_download'] : $type['base_uri']; + if ( is_string( $base ) && str_starts_with( $endpoint, $base ) ) { + return $endpoint; + } $endpoint = $repo_api->add_endpoints( $this, $endpoint ); return $base . $endpoint; From 599bb25965594b788c825ccaeb30997b4de41f40 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 18 Dec 2024 09:13:23 -0800 Subject: [PATCH 05/13] refactor GitHub release asset parsing --- CHANGES.md | 2 +- git-updater.php | 2 +- src/Git_Updater/API/GitHub_API.php | 31 +++++++++++++++++++----------- 3 files changed, 22 insertions(+), 13 deletions(-) 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. * From 0fb339fbccb9a37ca439689baae1f9cbb248fdde Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 18 Dec 2024 17:05:22 -0800 Subject: [PATCH 06/13] update for Bitbucket redirect used for updating bitbucket notes --- CHANGES.md | 1 + src/Git_Updater/REST/REST_API.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 33247a94d..1ac869dc5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ #### [unreleased] * update GitHub release asset parsing +* update REST_API for Bitbucket update link #### 12.7.2 / 2024-12-18 * update `freemius/wordpress-sdk` diff --git a/src/Git_Updater/REST/REST_API.php b/src/Git_Updater/REST/REST_API.php index 253353e4c..2365af74f 100644 --- a/src/Git_Updater/REST/REST_API.php +++ b/src/Git_Updater/REST/REST_API.php @@ -413,7 +413,9 @@ public function get_api_data( \WP_REST_Request $request ) { } if ( $download && $repo_data->release_asset ) { - if ( isset( $repo_cache['release_asset_download'] ) ) { + if ( isset( $repo_cache['release_asset_download'] ) + && 'bitbucket' !== $repo_api_data['git'] + ) { $repo_api_data['download_link'] = $repo_cache['release_asset_download']; } elseif ( $repo_cache['release_asset'] ) { $_REQUEST['override'] = true; From 7606afaf035aa0e239082836f64527b9c665eb4a Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 18 Dec 2024 17:05:50 -0800 Subject: [PATCH 07/13] update conditional --- src/Git_Updater/Traits/API_Common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Git_Updater/Traits/API_Common.php b/src/Git_Updater/Traits/API_Common.php index cb8e6ecce..766be8c8b 100644 --- a/src/Git_Updater/Traits/API_Common.php +++ b/src/Git_Updater/Traits/API_Common.php @@ -342,7 +342,7 @@ final public function get_api_release_asset( $git, $request ) { } } - if ( $response && ! $this->response['release_asset'] ) { + if ( $response && ! isset( $this->response['release_asset'] ) ) { $this->set_repo_cache( 'release_asset', $response ); } From e960203de308521d32476b99bb4f297e1b8ae2c2 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 18 Dec 2024 17:17:38 -0800 Subject: [PATCH 08/13] add $response back to API --- src/Git_Updater/REST/REST_API.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Git_Updater/REST/REST_API.php b/src/Git_Updater/REST/REST_API.php index 2365af74f..0f1f19c7a 100644 --- a/src/Git_Updater/REST/REST_API.php +++ b/src/Git_Updater/REST/REST_API.php @@ -404,6 +404,7 @@ public function get_api_data( \WP_REST_Request $request ) { ]; $repo_cache = $this->get_repo_cache( $slug ); + Singleton::get_instance( 'Fragen\Git_Updater\API\API', $this )->response = $repo_cache; if ( $repo_api_data['download_link'] && ( $repo_api_data['is_private'] || in_array( $repo_api_data['git'], [ 'gitlab', 'gitea' ], true ) ) From 88ddabdfaaf93b7514ed183171b35836f021a26e Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Fri, 20 Dec 2024 13:28:25 -0800 Subject: [PATCH 09/13] add `update-api` as REST endpoint --- CHANGES.md | 2 +- src/Git_Updater/REST/REST_API.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 1ac869dc5..6149ffb05 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ #### [unreleased] * update GitHub release asset parsing -* update REST_API for Bitbucket update link +* update `REST_API` for Bitbucket update link #### 12.7.2 / 2024-12-18 * update `freemius/wordpress-sdk` diff --git a/src/Git_Updater/REST/REST_API.php b/src/Git_Updater/REST/REST_API.php index 0f1f19c7a..5724f4216 100644 --- a/src/Git_Updater/REST/REST_API.php +++ b/src/Git_Updater/REST/REST_API.php @@ -136,6 +136,25 @@ public function register_endpoints() { ] ); + register_rest_route( + self::$namespace, + 'update-api', + [ + 'show_in_index' => true, + 'methods' => \WP_REST_Server::READABLE, + 'callback' => [ $this, 'get_api_data' ], + 'permission_callback' => '__return_true', + 'args' => [ + 'slug' => [ + 'default' => false, + 'required' => true, + 'validate_callback' => 'sanitize_title_with_dashes', + ], + ], + ] + ); + + $update_args = [ 'key' => [ 'default' => false, From 9a1c0556323a008c908ef4d009a075214b33189b Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Fri, 20 Dec 2024 14:52:18 -0800 Subject: [PATCH 10/13] use loop to register identical routes --- src/Git_Updater/REST/REST_API.php | 71 ++++++++----------------------- 1 file changed, 18 insertions(+), 53 deletions(-) diff --git a/src/Git_Updater/REST/REST_API.php b/src/Git_Updater/REST/REST_API.php index 5724f4216..63a78c7ec 100644 --- a/src/Git_Updater/REST/REST_API.php +++ b/src/Git_Updater/REST/REST_API.php @@ -100,60 +100,25 @@ public function register_endpoints() { ] ); - register_rest_route( - self::$namespace, - 'plugins-api', - [ - 'show_in_index' => true, - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $this, 'get_api_data' ], - 'permission_callback' => '__return_true', - 'args' => [ - 'slug' => [ - 'default' => false, - 'required' => true, - 'validate_callback' => 'sanitize_title_with_dashes', - ], - ], - ] - ); - - register_rest_route( - self::$namespace, - 'themes-api', - [ - 'show_in_index' => true, - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $this, 'get_api_data' ], - 'permission_callback' => '__return_true', - 'args' => [ - 'slug' => [ - 'default' => false, - 'required' => true, - 'validate_callback' => 'sanitize_title_with_dashes', - ], - ], - ] - ); - - register_rest_route( - self::$namespace, - 'update-api', - [ - 'show_in_index' => true, - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $this, 'get_api_data' ], - 'permission_callback' => '__return_true', - 'args' => [ - 'slug' => [ - 'default' => false, - 'required' => true, - 'validate_callback' => 'sanitize_title_with_dashes', + foreach ( [ 'plugins-api', 'themes-api', 'update-api' ] as $route ) { + register_rest_route( + self::$namespace, + $route, + [ + 'show_in_index' => true, + 'methods' => \WP_REST_Server::READABLE, + 'callback' => [ $this, 'get_api_data' ], + 'permission_callback' => '__return_true', + 'args' => [ + 'slug' => [ + 'default' => false, + 'required' => true, + 'validate_callback' => 'sanitize_title_with_dashes', + ], ], - ], - ] - ); - + ] + ); + } $update_args = [ 'key' => [ From 89184316779a0db89e2e9d2e8d2c1bf8dc2d9b1d Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sat, 21 Dec 2024 11:19:01 -0800 Subject: [PATCH 11/13] use my version of GA --- .github/workflows/generate-pot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-pot.yml b/.github/workflows/generate-pot.yml index 353eb7945..5a643907a 100644 --- a/.github/workflows/generate-pot.yml +++ b/.github/workflows/generate-pot.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@master - name: WordPress POT Generator - uses: varunsridharan/action-wp-pot-generator@2.0 + uses: afragen/action-wp-pot-generator@main with: save_path: "./languages" item_slug: "${{ github.event.repository.name }}" From bd9fb50642a80e0c691710973f9d4efafceb9882 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sat, 21 Dec 2024 11:19:19 -0800 Subject: [PATCH 12/13] compose update --- vendor/composer/InstalledVersions.php | 11 +++++++---- vendor/composer/installed.php | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php index 51e734a77..07b32ed6e 100644 --- a/vendor/composer/InstalledVersions.php +++ b/vendor/composer/InstalledVersions.php @@ -322,6 +322,7 @@ private static function getInstalled() } $installed = array(); + $copiedLocalDir = false; if (self::$canGetVendors) { foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { @@ -330,9 +331,11 @@ private static function getInstalled() } elseif (is_file($vendorDir.'/composer/installed.php')) { /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ $required = require $vendorDir.'/composer/installed.php'; - $installed[] = self::$installedByVendor[$vendorDir] = $required; - if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { - self::$installed = $installed[count($installed) - 1]; + self::$installedByVendor[$vendorDir] = $required; + $installed[] = $required; + if (strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { + self::$installed = $required; + $copiedLocalDir = true; } } } @@ -350,7 +353,7 @@ private static function getInstalled() } } - if (self::$installed !== array()) { + if (self::$installed !== array() && !$copiedLocalDir) { $installed[] = self::$installed; } diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index b4fb02037..db54c9831 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'afragen/git-updater', 'pretty_version' => 'dev-develop', 'version' => 'dev-develop', - 'reference' => '6eda2c2cf8a9835f4de395f8c338be67a61de9f1', + 'reference' => '9a1c0556323a008c908ef4d009a075214b33189b', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ 'afragen/git-updater' => array( 'pretty_version' => 'dev-develop', 'version' => 'dev-develop', - 'reference' => '6eda2c2cf8a9835f4de395f8c338be67a61de9f1', + 'reference' => '9a1c0556323a008c908ef4d009a075214b33189b', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), From cfaeea3a1895a0558c3917eabd5016a8eb945733 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sat, 21 Dec 2024 11:19:31 -0800 Subject: [PATCH 13/13] release --- CHANGES.md | 3 +++ git-updater.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 6149ffb05..54eccfaf4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,9 @@ #### [unreleased] + +#### 12.8.0 / 2024-12-21 * update GitHub release asset parsing * update `REST_API` for Bitbucket update link +* update `REST_API` for `update-api` route #### 12.7.2 / 2024-12-18 * update `freemius/wordpress-sdk` diff --git a/git-updater.php b/git-updater.php index c617ff83b..2c7d12d72 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.2 + * Version: 12.8.0 * Author: Andy Fragen * License: MIT * Domain Path: /languages