Skip to content

Commit 707d04b

Browse files
authored
Fix GitHub API response handling for Joomla Framework version 4 - Joomla CMS 6
Fix GitHub API response handling for Joomla Framework version 4
2 parents 033a4b7 + 09f5c17 commit 707d04b

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

administrator/components/com_patchtester/src/Controller/StartfetchController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function execute($task): void
5252
// Make sure we can fetch the data from GitHub - throw an error on < 10 available requests
5353
try {
5454
$rateResponse = Helper::initializeGithub()->getRateLimit();
55-
$rate = json_decode($rateResponse->body);
55+
$rate = json_decode($rateResponse->getBody());
5656
} catch (\Exception $e) {
5757
$response = new JsonResponse(new \Exception(Text::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()), $e->getCode(), $e));
5858
$this->app->sendHeaders();

administrator/components/com_patchtester/src/GitHub/GitHub.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Patch testing component for the Joomla! CMS
55
*
6-
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
6+
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2025 Open Source Matters, Inc. All rights reserved.
77
* @license GNU General Public License version 2 or later
88
*/
99

@@ -166,15 +166,15 @@ protected function processResponse(
166166
int $expectedCode = 200
167167
): Response {
168168
// Validate the response code.
169-
if ($response->code != $expectedCode) {
169+
if ($response->getStatusCode() != $expectedCode) {
170170
// Decode the error response and throw an exception.
171-
$body = json_decode($response->body);
171+
$body = json_decode((string) $response->getBody(), true);
172172
$error = $body->error ?? ($body->message ?? 'Unknown Error');
173173

174174
throw new UnexpectedResponse(
175175
$response,
176176
$error,
177-
$response->code
177+
$response->getStatusCode()
178178
);
179179
}
180180

administrator/components/com_patchtester/src/Model/PullModel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Patch testing component for the Joomla! CMS
55
*
6-
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
6+
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2025 Open Source Matters, Inc. All rights reserved.
77
* @license GNU General Public License version 2 or later
88
*/
99

@@ -319,7 +319,7 @@ private function retrieveGitHubData(GitHub $github, int $id): stdClass
319319
{
320320
try {
321321
$rateResponse = $github->getRateLimit();
322-
$rate = json_decode($rateResponse->body, false);
322+
$rate = json_decode($rateResponse->getBody(), false);
323323
} catch (UnexpectedResponse $exception) {
324324
throw new RuntimeException(
325325
Text::sprintf(
@@ -347,7 +347,7 @@ private function retrieveGitHubData(GitHub $github, int $id): stdClass
347347
$this->getState()->get('github_repo'),
348348
$id
349349
);
350-
$pull = json_decode($pullResponse->body, false);
350+
$pull = json_decode($pullResponse->getBody(), false);
351351
} catch (UnexpectedResponse $exception) {
352352
throw new RuntimeException(
353353
Text::sprintf(
@@ -587,7 +587,7 @@ private function applyWithGitHub(int $id): bool
587587
urlencode($pull->head->ref)
588588
);
589589
$contents = json_decode(
590-
$contentsResponse->body,
590+
$contentsResponse->getBody(),
591591
false
592592
);
593593
// In case encoding type ever changes

administrator/components/com_patchtester/tmpl/pulls/default_items.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,27 @@
137137
endif; ?>
138138
</td>
139139
<td class="text-center">
140-
<?php $hideButton = function($labels) {
141-
foreach ($labels as $label) {
142-
if (in_array(strtolower($label->name), ['npm resource changed', 'composer dependency changed', 'rtc'])) {
143-
return true;
144-
}
145-
}
140+
<?php $hideButton = function ($labels) {
141+
foreach ($labels as $label) {
142+
if (in_array(strtolower($label->name), ['npm resource changed', 'composer dependency changed', 'rtc'])) {
143+
return true;
144+
}
145+
}
146146

147147
return false;
148148
};?>
149149
<?php if ($this->settings->get('advanced', 0) || !$hideButton($item->labels)) : ?>
150-
<?php if ($item->applied) :
151-
?>
150+
<?php if ($item->applied) :
151+
?>
152152
<button type="button" class="btn btn-sm btn-success submitPatch"
153153
data-task="revert" data-id="<?php echo (int) $item->applied; ?>"><?php echo Text::_('COM_PATCHTESTER_REVERT_PATCH'); ?></button>
154-
<?php
155-
else :
156-
?>
154+
<?php
155+
else :
156+
?>
157157
<button type="button" class="btn btn-sm btn-primary submitPatch"
158158
data-task="apply" data-id="<?php echo (int) $item->pull_id; ?>"><?php echo Text::_('COM_PATCHTESTER_APPLY_PATCH'); ?></button>
159-
<?php
160-
endif; ?>
159+
<?php
160+
endif; ?>
161161
<?php endif; ?>
162162
</td>
163163
</tr>

0 commit comments

Comments
 (0)