Skip to content

Commit e197b85

Browse files
Copilotswissspidy
andcommitted
Update get_github_latest_release_tag to fallback to default branch
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent d554d5e commit e197b85

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/Package_Command.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,23 +1357,28 @@ private function get_raw_git_version( $version ) {
13571357
/**
13581358
* Gets the release tag for the latest stable release of a GitHub repository.
13591359
*
1360+
* If there is no release, falls back to the default branch prefixed with 'dev-'.
1361+
*
13601362
* @param string $package_name Name of the repository.
1363+
* @param bool $insecure Whether to retry downloads without certificate validation if TLS handshake fails.
13611364
*
1362-
* @return string Release tag.
1365+
* @return string Release tag or 'dev-{default_branch}' if no release exists.
13631366
*/
13641367
private function get_github_latest_release_tag( $package_name, $insecure ) {
13651368
$url = "https://api.github.com/repos/{$package_name}/releases/latest";
13661369
$options = [ 'insecure' => $insecure ];
13671370
$response = Utils\http_request( 'GET', $url, null, [], $options );
13681371
if ( 20 !== (int) substr( $response->status_code, 0, 2 ) ) {
1369-
WP_CLI::warning( 'Could not guess stable version from GitHub repository, falling back to master branch' );
1370-
return 'master';
1372+
$default_branch = $this->get_github_default_branch( $package_name, $insecure );
1373+
WP_CLI::warning( "Could not guess stable version from GitHub repository, falling back to {$default_branch} branch" );
1374+
return "dev-{$default_branch}";
13711375
}
13721376

13731377
$package_data = json_decode( $response->body );
13741378
if ( JSON_ERROR_NONE !== json_last_error() ) {
1375-
WP_CLI::warning( 'Could not guess stable version from GitHub repository, falling back to master branch' );
1376-
return 'master';
1379+
$default_branch = $this->get_github_default_branch( $package_name, $insecure );
1380+
WP_CLI::warning( "Could not guess stable version from GitHub repository, falling back to {$default_branch} branch" );
1381+
return "dev-{$default_branch}";
13771382
}
13781383

13791384
$tag = $package_data->tag_name;

0 commit comments

Comments
 (0)