Skip to content

Commit 2bbab2f

Browse files
committed
Merge branch 'develop'
2 parents afbe8ce + d99b542 commit 2bbab2f

13 files changed

+143
-98
lines changed

CHANGES.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#### [unreleased]
22

3+
#### 10.1.0 / 2021-05-27
4+
* cache GitHub API response failures for rate limit timeout to avoid hammering the API
5+
* add constant `GU_MU_LOADER` to aid in mu-plugin loading of Git Updater PRO
6+
* catch API errors when GitHub personal access token is set, fixes [#947](https://github.com/afragen/git-updater/issues/947)
7+
* improved error messaging
8+
* oops, forgot to load `GU_Trait` for renaming from `develop` branch installation
9+
310
#### 10.0.2 / 2021-05-18
411
* fix to use `intval()` as `abs()` more type specific in PHP8, fixes [#952](https://github.com/afragen/git-updater/issues/952)
512
* fix to display **GitLab** subtab when only using GitLab CE, fixes [#949](https://github.com/afragen/git-updater/issues/949) thanks @AMCodeHub and @kmitch-duke-edu

git-updater.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Plugin Name: Git Updater
1313
* Plugin URI: https://git-updater.com
1414
* Description: A plugin to automatically update GitHub hosted plugins, themes, and language packs. Additional API plugins available for Bitbucket, GitLab, Gitea, and Gist.
15-
* Version: 10.0.2
15+
* Version: 10.1.0
1616
* Author: Andy Fragen
1717
* License: MIT
1818
* Domain Path: /languages

languages/git-updater.pot

+47-47
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Copyright (C) 2021 Andy Fragen
2-
# This file is distributed under the same license as the Git Updater plugin.
2+
# This file is distributed under the MIT.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: Git Updater 10.0.0\n"
5+
"Project-Id-Version: Git Updater 10.1.0\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/git-updater\n"
77
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
88
"Language-Team: LANGUAGE <[email protected]>\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"POT-Creation-Date: 2021-05-18T00:33:50+00:00\n"
12+
"POT-Creation-Date: 2021-05-27T15:23:28+00:00\n"
1313
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14-
"X-Generator: WP-CLI 2.4.0\n"
14+
"X-Generator: WP-CLI 2.5.0\n"
1515
"X-Domain: git-updater\n"
1616

1717
#. Plugin Name of the plugin
18-
#: src/Git_Updater/Settings.php:161
19-
#: src/Git_Updater/Settings.php:264
18+
#: src/Git_Updater/Settings.php:162
19+
#: src/Git_Updater/Settings.php:266
2020
msgid "Git Updater"
2121
msgstr ""
2222

@@ -32,7 +32,7 @@ msgstr ""
3232
msgid "Andy Fragen"
3333
msgstr ""
3434

35-
#: mu/gu-loader.php:105
35+
#: mu/gu-loader.php:106
3636
msgid "Activated as mu-plugin"
3737
msgstr ""
3838

@@ -110,140 +110,140 @@ msgstr ""
110110
msgid "Free Trial"
111111
msgstr ""
112112

113-
#: src/Git_Updater/API/GitHub_API.php:352
113+
#: src/Git_Updater/API/GitHub_API.php:351
114114
msgid "GitHub Personal Access Token"
115115
msgstr ""
116116

117-
#: src/Git_Updater/API/GitHub_API.php:359
117+
#: src/Git_Updater/API/GitHub_API.php:358
118118
msgid "github.com Access Token"
119119
msgstr ""
120120

121-
#: src/Git_Updater/API/GitHub_API.php:375
121+
#: src/Git_Updater/API/GitHub_API.php:374
122122
msgid "GitHub Private Settings"
123123
msgstr ""
124124

125-
#: src/Git_Updater/API/GitHub_API.php:402
125+
#: src/Git_Updater/API/GitHub_API.php:401
126126
msgid "Enter your GitHub Access Token. Leave empty for public repositories."
127127
msgstr ""
128128

129-
#: src/Git_Updater/API/GitHub_API.php:409
129+
#: src/Git_Updater/API/GitHub_API.php:408
130130
msgid "Enter your personal github.com or GitHub Enterprise Access Token to avoid API access limits."
131131
msgstr ""
132132

133-
#: src/Git_Updater/API/GitHub_API.php:420
133+
#: src/Git_Updater/API/GitHub_API.php:419
134134
msgid "GitHub Access Token"
135135
msgstr ""
136136

137-
#: src/Git_Updater/API/GitHub_API.php:434
137+
#: src/Git_Updater/API/GitHub_API.php:433
138138
msgid "GitHub"
139139
msgstr ""
140140

141-
#: src/Git_Updater/API/GitHub_API.php:448
141+
#: src/Git_Updater/API/GitHub_API.php:447
142142
msgid "Enter GitHub Access Token for private GitHub repositories."
143143
msgstr ""
144144

145145
#. translators: %s: documentation URL
146-
#: src/Git_Updater/Bootstrap.php:68
146+
#: src/Git_Updater/Bootstrap.php:72
147147
msgid "Git Updater is missing required composer dependencies. <a href=\"%s\" target=\"_blank\" rel=\"noopenernoreferer\">Learn more.</a>"
148148
msgstr ""
149149

150150
#. translators: 1: minimum PHP version required
151-
#: src/Git_Updater/Bootstrap.php:110
151+
#: src/Git_Updater/Bootstrap.php:114
152152
msgid "Git Updater cannot run on PHP versions older than %1$s."
153153
msgstr ""
154154

155-
#: src/Git_Updater/Messages.php:116
156-
#: src/Git_Updater/Messages.php:157
157-
#: src/Git_Updater/Messages.php:177
155+
#: src/Git_Updater/Messages.php:118
156+
#: src/Git_Updater/Messages.php:162
157+
#: src/Git_Updater/Messages.php:182
158158
msgid "Git Updater Error Code:"
159159
msgstr ""
160160

161-
#. translators: %s: wait time
162-
#: src/Git_Updater/Messages.php:123
163-
msgid "GitHub API&#8217;s rate limit will reset in %s minutes."
161+
#. translators: %1$s: git server, %2$s: wait time
162+
#: src/Git_Updater/Messages.php:125
163+
msgid "%1$s API&#8217;s rate limit will reset in %2$s minutes."
164164
msgstr ""
165165

166-
#. translators: %s: GitHub personal access token URL
167-
#: src/Git_Updater/Messages.php:129
168-
msgid "It looks like you are running into GitHub API rate limits. Be sure and configure a <a href=\"%s\">Personal Access Token</a> to avoid this issue."
166+
#. translators: %1$s: git server, %2$s: GitHub personal access token URL
167+
#: src/Git_Updater/Messages.php:132
168+
msgid "It looks like you are running into %1$s API rate limits. Be sure and configure a <a href=\"%2$s\">Personal Access Token</a> to avoid this issue."
169169
msgstr ""
170170

171-
#: src/Git_Updater/Messages.php:161
171+
#: src/Git_Updater/Messages.php:166
172172
msgid "There is probably an access token or password error on the Git Updater Settings page."
173173
msgstr ""
174174

175-
#: src/Git_Updater/Messages.php:192
175+
#: src/Git_Updater/Messages.php:197
176176
msgid "Git Updater Information"
177177
msgstr ""
178178

179-
#: src/Git_Updater/Messages.php:194
179+
#: src/Git_Updater/Messages.php:199
180180
msgid "Please be patient while WP-Cron finishes making API calls."
181181
msgstr ""
182182

183-
#: src/Git_Updater/Settings.php:133
184-
#: src/Git_Updater/Settings.php:799
183+
#: src/Git_Updater/Settings.php:134
184+
#: src/Git_Updater/Settings.php:801
185185
msgid "Settings"
186186
msgstr ""
187187

188-
#: src/Git_Updater/Settings.php:207
189-
#: src/Git_Updater/Settings.php:361
188+
#: src/Git_Updater/Settings.php:209
189+
#: src/Git_Updater/Settings.php:363
190190
msgid "Git Updater Settings"
191191
msgstr ""
192192

193-
#: src/Git_Updater/Settings.php:208
193+
#: src/Git_Updater/Settings.php:210
194194
msgctxt "Menu item"
195195
msgid "Git Updater"
196196
msgstr ""
197197

198-
#: src/Git_Updater/Settings.php:286
198+
#: src/Git_Updater/Settings.php:288
199199
msgid "Refresh Cache"
200200
msgstr ""
201201

202-
#: src/Git_Updater/Settings.php:329
202+
#: src/Git_Updater/Settings.php:331
203203
msgid "Settings saved."
204204
msgstr ""
205205

206-
#: src/Git_Updater/Settings.php:331
206+
#: src/Git_Updater/Settings.php:333
207207
msgid "Cache refreshed."
208208
msgstr ""
209209

210-
#: src/Git_Updater/Settings.php:374
210+
#: src/Git_Updater/Settings.php:376
211211
msgid "Enable Branch Switching"
212212
msgstr ""
213213

214-
#: src/Git_Updater/Settings.php:387
214+
#: src/Git_Updater/Settings.php:389
215215
msgid "Bypass WP-Cron Background Processing for Debugging"
216216
msgstr ""
217217

218-
#: src/Git_Updater/Settings.php:399
218+
#: src/Git_Updater/Settings.php:401
219219
msgid "Display `deprecated hook` messaging in debug.log"
220220
msgstr ""
221221

222-
#: src/Git_Updater/Settings.php:562
222+
#: src/Git_Updater/Settings.php:564
223223
msgid "Check to enable."
224224
msgstr ""
225225

226-
#: src/Git_Updater/Settings.php:594
226+
#: src/Git_Updater/Settings.php:596
227227
msgid "Overridden Plugins and Themes"
228228
msgstr ""
229229

230-
#: src/Git_Updater/Settings.php:595
230+
#: src/Git_Updater/Settings.php:597
231231
msgid "The following plugins or themes might exist on wp.org, but any updates will be downloaded from their respective git repositories."
232232
msgstr ""
233233

234-
#: src/Git_Updater/Settings.php:833
234+
#: src/Git_Updater/Settings.php:835
235235
msgid "This is a private repository."
236236
msgstr ""
237237

238-
#: src/Git_Updater/Settings.php:834
238+
#: src/Git_Updater/Settings.php:836
239239
msgid "This repository has not connected to the API or was unable to connect."
240240
msgstr ""
241241

242-
#: src/Git_Updater/Settings.php:835
242+
#: src/Git_Updater/Settings.php:837
243243
msgid "This repository is hosted on WordPress.org."
244244
msgstr ""
245245

246-
#: src/Git_Updater/Settings.php:877
246+
#: src/Git_Updater/Settings.php:879
247247
msgid "Installed Plugins and Themes"
248248
msgstr ""
249249

mu/gu-loader.php

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class MU_Loader {
4444
* @return void
4545
*/
4646
public function run() {
47+
define( 'GU_MU_LOADER', true );
4748
if ( ! class_exists( 'Bootstrap' ) ) {
4849
require trailingslashit( WP_PLUGIN_DIR ) . self::$plugin_file;
4950
}

src/Git_Updater/API/API.php

+30-16
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,17 @@ function ( $type ) use ( $git ) {
177177
* @return boolean|\stdClass
178178
*/
179179
public function api( $url ) {
180-
$url = $this->get_api_url( $url );
181-
$auth_header = $this->add_auth_header( [], $url );
182-
$type = $this->return_repo_type();
183-
$response = wp_remote_get( $url, array_merge( $this->default_http_get_args, $auth_header ) );
180+
$url = $this->get_api_url( $url );
181+
$auth_header = $this->add_auth_header( [], $url );
182+
$type = $this->return_repo_type();
183+
184+
// Use cached API failure data to avoid hammering the GitHub API.
185+
$response = $this->get_repo_cache( md5( $url ) );
186+
$response = $response ? $response['error_cache'] : $response;
187+
$response = ! $response
188+
? wp_remote_get( $url, array_merge( $this->default_http_get_args, $auth_header ) )
189+
: $response;
190+
184191
$code = (int) wp_remote_retrieve_response_code( $response );
185192
$allowed_codes = [ 200 ];
186193

@@ -190,20 +197,27 @@ public function api( $url ) {
190197
return $response;
191198
}
192199
if ( ! in_array( $code, $allowed_codes, true ) ) {
193-
static::$error_code = array_merge(
194-
static::$error_code,
200+
201+
// Cache GitHub API failure data.
202+
$wait = in_array( $type['git'], [ 'github', 'gist' ], true )
203+
? GitHub_API::ratelimit_reset( $response, $this->type->slug )
204+
: 0;
205+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
206+
$timeout = get_site_transient( 'gu_refresh_cache' )
207+
|| ( ! empty( static::$options['github_access_token'] ) && 403 !== $code )
208+
? 0 : $wait;
209+
$this->set_repo_cache( 'error_cache', $response, md5( $url ), "+{$timeout} minutes" );
210+
211+
static::$error_code[ $this->type->slug ] = isset( static::$error_code[ $this->type->slug ] ) ? static::$error_code[ $this->type->slug ] : [];
212+
static::$error_code[ $this->type->slug ] = array_merge(
213+
static::$error_code[ $this->type->slug ],
195214
[
196-
$this->type->slug => [
197-
'repo' => $this->type->slug,
198-
'code' => $code,
199-
'name' => $this->type->name,
200-
'git' => $this->type->git,
201-
],
215+
'repo' => $this->type->slug,
216+
'code' => $code,
217+
'name' => $this->type->name,
218+
'git' => $this->type->git,
202219
]
203220
);
204-
if ( in_array( $type['git'], [ 'github', 'gist' ], true ) ) {
205-
GitHub_API::ratelimit_reset( $response, $this->type->slug );
206-
}
207221
Singleton::get_instance( 'Messages', $this )->create_error_message( $type['git'] );
208222

209223
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
@@ -467,7 +481,7 @@ protected function get_local_info( $repo, $file ) {
467481
*/
468482
protected function set_file_info( $response ) {
469483
$this->type->transient = $response;
470-
$this->type->remote_version = strtolower( $response['Version'] );
484+
$this->type->remote_version = ! empty( $response['Version'] ) ? strtolower( $response['Version'] ) : $this->type->remote_version;
471485
$this->type->requires_php = ! empty( $response['RequiresPHP'] ) ? $response['RequiresPHP'] : false;
472486
$this->type->requires = ! empty( $response['RequiresWP'] ) ? $response['RequiresWP'] : null;
473487
$this->type->requires = ! empty( $response['Requires'] ) ? $response['Requires'] : $this->type->requires;

src/Git_Updater/API/GitHub_API.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,18 @@ public function add_endpoints( $git, $endpoint ) {
195195
*
196196
* @param array $response HTTP headers.
197197
* @param string $repo Repo name.
198+
*
199+
* @return void|int
198200
*/
199201
public static function ratelimit_reset( $response, $repo ) {
200202
if ( isset( $response['headers']['x-ratelimit-reset'] ) ) {
201203
$reset = (int) $response['headers']['x-ratelimit-reset'];
202204
//phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
203205
$wait = date( 'i', $reset - time() );
204-
static::$error_code[ $repo ] = array_merge(
205-
static::$error_code[ $repo ],
206-
[
207-
'git' => 'github',
208-
'wait' => $wait,
209-
]
210-
);
206+
static::$error_code[ $repo ] = isset( static::$error_code[ $repo ] ) ? static::$error_code[ $repo ] : [];
207+
static::$error_code[ $repo ] = array_merge( static::$error_code[ $repo ], [ 'wait' => $wait ] );
208+
209+
return $wait;
211210
}
212211
}
213212

src/Git_Updater/Bootstrap.php

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace Fragen\Git_Updater;
1212

13+
use Fragen\Git_Updater\Traits\GU_Trait;
14+
1315
/*
1416
* Exit if called directly.
1517
*/
@@ -29,6 +31,8 @@ function () {
2931
* Class Bootstrap
3032
*/
3133
class Bootstrap {
34+
use GU_Trait;
35+
3236
/**
3337
* Holds main plugin file.
3438
*

0 commit comments

Comments
 (0)