Skip to content

Commit

Permalink
Fully upgraded to BitBucket API 2.0.
Browse files Browse the repository at this point in the history
Previously the update checker used a mix of 2.0 and 1.0. Version 1.0 was deprecated a while ago and has now stopped working for at least some users.

This should fix the errors reported in YahnisElsts#289.
  • Loading branch information
YahnisElsts committed Jun 13, 2019
1 parent 3ad92e3 commit 3f5a340
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Puc/v4p6/Vcs/BitBucketApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ protected function getDownloadUrl($ref) {
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
*/
public function getRemoteFile($path, $ref = 'master') {
$response = $this->api('src/' . $ref . '/' . ltrim($path), '1.0');
if ( is_wp_error($response) || !isset($response, $response->data) ) {
$response = $this->api('src/' . $ref . '/' . ltrim($path));
if ( is_wp_error($response) || !is_string($response) ) {
return null;
}
return $response->data;
return $response;
}

/**
Expand All @@ -186,13 +186,16 @@ public function getLatestCommitTime($ref) {
* @return mixed|WP_Error
*/
public function api($url, $version = '2.0') {
$url = ltrim($url, '/');
$isSrcResource = Puc_v4p6_Utils::startsWith($url, 'src/');

$url = implode('/', array(
'https://api.bitbucket.org',
$version,
'repositories',
$this->username,
$this->repository,
ltrim($url, '/')
$url
));
$baseUrl = $url;

Expand All @@ -213,7 +216,13 @@ public function api($url, $version = '2.0') {
$code = wp_remote_retrieve_response_code($response);
$body = wp_remote_retrieve_body($response);
if ( $code === 200 ) {
$document = json_decode($body);
if ( $isSrcResource ) {
//Most responses are JSON-encoded, but src resources just
//return raw file contents.
$document = $body;
} else {
$document = json_decode($body);
}
return $document;
}

Expand Down

0 comments on commit 3f5a340

Please sign in to comment.