Skip to content

Commit 5054889

Browse files
committed
Use default branch
1 parent fc9aaaa commit 5054889

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

.maintenance/refresh-repository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
printf( "--- Refreshing repository \033[32m{$repository}\033[0m ---\n" );
1111

12-
printf( "Switching to latest \033[33mmaster\033[0m branch...\n" );
13-
system( "git --git-dir={$path}/.git --work-tree={$path} checkout master" );
12+
printf( "Switching to latest \033[33mdefault\033[0m branch...\n" );
13+
system( "git --git-dir={$path}/.git --work-tree={$path} checkout $(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)" );
1414

1515
printf( "Pulling latest changes...\n" );
1616
system( "git --git-dir={$path}/.git --work-tree={$path} pull" );

.maintenance/src/Contrib_List_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function ( $tag, $milestone ) {
126126
return version_compare( $milestone->title, $tag, '>' ) ? $milestone->title : $tag;
127127
}
128128
);
129-
$tag = ! empty( $milestone ) ? "v{$milestone}" : 'master';
129+
$tag = ! empty( $milestone ) ? "v{$milestone}" : GitHub::get_default_branch( $bundle );
130130

131131
$composer_lock_url = sprintf( 'https://raw.githubusercontent.com/%s/%s/composer.lock', $bundle, $tag );
132132
WP_CLI::log( 'Fetching ' . $composer_lock_url );

.maintenance/src/GitHub.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,24 @@ public static function get_organization_repos( $args = [] ) {
437437
return $body;
438438
}
439439

440+
441+
/**
442+
* Get the default branch of a repository.
443+
*
444+
* @param string $project Project the get the default branch for.
445+
*
446+
* @return string Default branch of the repository.
447+
*/
448+
public static function get_default_branch( $project ) {
449+
$request_url = self::API_ROOT . "repos/{$project}";
450+
451+
list( $body, $headers ) = self::request( $request_url );
452+
453+
454+
455+
return $body->default_branch;
456+
}
457+
440458
/**
441459
* Makes a request to the GitHub API.
442460
*

.maintenance/src/Release_Command.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ public function generate( $args, $assoc_args ) {
122122
continue 2;
123123
}
124124

125+
$default_branch = GitHub::get_default_branch( $repo );
126+
125127
WP_CLI::log( "Creating release {$title} {$tag}..." );
126-
GitHub::create_release( $repo, $tag, 'master', $title, $release_notes );
128+
GitHub::create_release( $repo, $tag, $default_branch, $title, $release_notes );
127129

128130
WP_CLI::log( "Closing milestone '{$milestone->title}'" );
129131
GitHub::close_milestone( $repo, $milestone->number );
@@ -279,7 +281,8 @@ static function ( $repo ) use ( $exclude ) {
279281

280282
private function get_bundle_repos() {
281283
$repos = [];
282-
$composer_lock_url = 'https://raw.githubusercontent.com/wp-cli/wp-cli-bundle/master/composer.lock';
284+
$default_branch = GitHub::get_default_branch( 'wp-cli/wp-cli-bundle' );
285+
$composer_lock_url = "https://raw.githubusercontent.com/wp-cli/wp-cli-bundle/{$default_branch}/composer.lock";
283286
$response = Utils\http_request( 'GET', $composer_lock_url );
284287
if ( 200 !== $response->status_code ) {
285288
WP_CLI::error( sprintf( 'Could not fetch composer.json (HTTP code %d)', $response->status_code ) );

.maintenance/src/Release_Notes_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function ( $tag, $milestone ) {
119119
}
120120
);
121121

122-
$tag = ! empty( $milestone ) ? "v{$milestone}" : 'master';
122+
$tag = ! empty( $milestone ) ? "v{$milestone}" : GitHub::get_default_branch( $bundle );
123123

124124
$composer_lock_url = sprintf( 'https://raw.githubusercontent.com/%s/%s/composer.lock',
125125
$bundle, $tag );

0 commit comments

Comments
 (0)