Skip to content

Commit 3ca4dc2

Browse files
committed
Add release generation for non-bundled commands
1 parent afd7a08 commit 3ca4dc2

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

.maintenance/src/GitHub.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace WP_CLI\Maintenance;
22

3+
use stdClass;
34
use WP_CLI;
45
use WP_CLI\Utils;
56

@@ -385,6 +386,31 @@ public static function get_issues( $project, $args = [] ) {
385386
return $body;
386387
}
387388

389+
/**
390+
* Get all repositories of the wp-cli organization.
391+
*
392+
* @param array $args
393+
*
394+
* @return stdClass[]
395+
*/
396+
public static function get_organization_repos( $args = [] ) {
397+
$request_url = self::API_ROOT . 'orgs/wp-cli/repos';
398+
399+
$args = array_merge(
400+
[
401+
'per_page' => 100,
402+
'state' => 'all',
403+
'sort' => 'full_name',
404+
'direction' => 'asc',
405+
],
406+
$args
407+
);
408+
409+
list( $body, $headers ) = self::request( $request_url, $args );
410+
411+
return $body;
412+
}
413+
388414
/**
389415
* Makes a request to the GitHub API.
390416
*

.maintenance/src/Release_Command.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ final class Release_Command {
1717
* [--bundle]
1818
* : Close the milestones for the entire bundle.
1919
*
20+
* [--all]
21+
* : Close the milestones for all repositories in the wp-cli organization.
2022
*
2123
* @subcommand close-released
2224
* @when before_wp_load
@@ -25,7 +27,9 @@ public function close_released( $args, $assoc_args ) {
2527

2628
$repos = (array) $args;
2729

28-
if ( Utils\get_flag_value( $assoc_args, 'bundle', false ) ) {
30+
if ( Utils\get_flag_value( $assoc_args, 'all', false ) ) {
31+
$repos = array_unique( array_merge( $repos, $this->get_bundle_repos() ) );
32+
} elseif ( Utils\get_flag_value( $assoc_args, 'bundle', false ) ) {
2933
$repos = array_unique( array_merge( $repos, $this->get_bundle_repos() ) );
3034
}
3135

@@ -63,13 +67,18 @@ public function close_released( $args, $assoc_args ) {
6367
* [--bundle]
6468
* : Generate releases for the entire bundle.
6569
*
70+
* [--all]
71+
* : Generate releases for all repositories in the wp-cli organization.
72+
*
6673
* @when before_wp_load
6774
*/
6875
public function generate( $args, $assoc_args ) {
6976

7077
$repos = (array) $args;
7178

72-
if ( Utils\get_flag_value( $assoc_args, 'bundle', false ) ) {
79+
if ( Utils\get_flag_value( $assoc_args, 'all', false ) ) {
80+
$repos = array_unique( array_merge( $repos, $this->get_all_repos() ) );
81+
} elseif ( Utils\get_flag_value( $assoc_args, 'bundle', false ) ) {
7382
$repos = array_unique( array_merge( $repos, $this->get_bundle_repos() ) );
7483
}
7584

@@ -106,7 +115,12 @@ public function generate( $args, $assoc_args ) {
106115
WP_CLI::log( '-----' );
107116
WP_CLI::log( "{$title} ({$tag})\n{$release_notes}" );
108117
WP_CLI::log( '-----' );
109-
WP_CLI::confirm( 'Is the above correct?' );
118+
119+
fwrite( STDOUT, 'Is the above correct?' . ' [y/n] ' );
120+
$answer = strtolower( trim( fgets( STDIN ) ) );
121+
if ( 'y' !== $answer ) {
122+
continue 2;
123+
}
110124

111125
WP_CLI::log( "Creating release {$title} {$tag}..." );
112126
GitHub::create_release( $repo, $tag, 'master', $title, $release_notes );
@@ -245,6 +259,24 @@ private function repo_heading( $repo, $format ) {
245259
);
246260
}
247261

262+
private function get_all_repos( $exclude = null ) {
263+
return array_map(
264+
static function ( $repo ) {
265+
return $repo->full_name;
266+
},
267+
array_filter(
268+
GitHub::get_organization_repos(),
269+
static function ( $repo ) use ( $exclude ) {
270+
if ( null === $exclude ) {
271+
return $repo->archived === false && $repo->disabled === false;
272+
}
273+
274+
return ! in_array( $repo->full_name, (array) $exclude, true );
275+
}
276+
)
277+
);
278+
}
279+
248280
private function get_bundle_repos() {
249281
$repos = [];
250282
$composer_lock_url = 'https://raw.githubusercontent.com/wp-cli/wp-cli-bundle/master/composer.lock';

0 commit comments

Comments
 (0)