diff --git a/src/SelfManage/Update/FetchPieReleaseFromGitHub.php b/src/SelfManage/Update/FetchPieReleaseFromGitHub.php index aae223dd..9b03ee77 100644 --- a/src/SelfManage/Update/FetchPieReleaseFromGitHub.php +++ b/src/SelfManage/Update/FetchPieReleaseFromGitHub.php @@ -11,6 +11,7 @@ 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 @@ static function (array $asset): bool { $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) { diff --git a/test/unit/SelfManage/Update/FetchPieReleaseFromGitHubTest.php b/test/unit/SelfManage/Update/FetchPieReleaseFromGitHubTest.php index ea66dec0..840ec7a6 100644 --- a/test/unit/SelfManage/Update/FetchPieReleaseFromGitHubTest.php +++ b/test/unit/SelfManage/Update/FetchPieReleaseFromGitHubTest.php @@ -207,4 +207,60 @@ public function testDownloadContent(): void 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); + } }