1
0
mirror of https://github.com/php/pie.git synced 2026-03-23 23:12:17 +01:00

491: fix error when latest release is a draft by filtering out draft releases

This commit is contained in:
James Titcumb
2026-02-02 17:21:10 +00:00
parent a8bf21c15e
commit 2bae4de7e1
2 changed files with 61 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ use RuntimeException;
use Webmozart\Assert\Assert;
use function array_filter;
use function array_key_exists;
use function array_map;
use function count;
use function file_put_contents;
@@ -85,7 +86,10 @@ final class FetchPieReleaseFromGitHub implements FetchPieRelease
$firstAssetNamedPiePhar['browser_download_url'],
);
},
$decodedResponse,
array_filter(
$decodedResponse,
static fn (array $releaseResponse): bool => (! array_key_exists('draft', $releaseResponse) || ! $releaseResponse['draft']),
),
),
static function (ReleaseMetadata|null $releaseMetadata) use ($updateChannel): bool {
if ($releaseMetadata === null) {

View File

@@ -207,4 +207,60 @@ final class FetchPieReleaseFromGitHubTest extends TestCase
self::assertSame($pharContent, file_get_contents($file->filePath));
self::assertSame($expectedDigest, $file->checksum);
}
public function testDraftReleasesAreNotReturnedForStableChannel(): void
{
$httpDownloader = $this->createMock(HttpDownloader::class);
$url = self::TEST_GITHUB_URL . '/repos/php/pie/releases';
$httpDownloader->expects(self::once())
->method('get')
->with(
$url,
[
'retry-auth-failure' => true,
'http' => [
'method' => 'GET',
'header' => [],
],
],
)
->willReturn(
new Response(
['url' => $url],
200,
[],
(string) json_encode([
[
'draft' => true,
'tag_name' => '1.2.4',
'assets' => [
[
'name' => 'pie.phar',
'browser_download_url' => self::TEST_GITHUB_URL . '/path/to/pie.phar',
],
],
],
[
'draft' => false,
'tag_name' => '1.2.3',
'assets' => [
[
'name' => 'pie.phar',
'browser_download_url' => self::TEST_GITHUB_URL . '/path/to/pie.phar',
],
],
],
]),
),
);
$fetch = new FetchPieReleaseFromGitHub(self::TEST_GITHUB_URL, $httpDownloader);
$latestRelease = $fetch->latestReleaseMetadata(Channel::Stable);
self::assertSame('1.2.3', $latestRelease->tag);
self::assertSame(self::TEST_GITHUB_URL . '/path/to/pie.phar', $latestRelease->downloadUrl);
}
}