@@ -8,17 +8,17 @@ final class Contrib_List_Command {
88 /**
99 * Lists all contributors to this release.
1010 *
11- * Run within the main WP-CLI project repository .
11+ * Only authors of merged pull requests count; bots are left out .
1212 *
1313 * ## OPTIONS
1414 *
1515 * [<repo>]
16- * : Name of the repository to fetch the release notes for. If no user/org
17- * was provided, 'wp-cli' org is assumed. If no repo is passed, release
18- * notes for the entire org state since the last bundle release are fetched .
16+ * : Name of the repository to list the contributors for. If no user/org
17+ * was provided, 'wp-cli' org is assumed. If no repo is passed, the
18+ * contributors to the entire org since the last bundle release are listed .
1919 *
2020 * [<milestone>...]
21- * : Name of one or more milestones to fetch the release notes for. If none
21+ * : Name of one or more milestones to list the contributors for. If none
2222 * are passed, the current open one is assumed.
2323 *
2424 * [--release=<version>]
@@ -41,6 +41,7 @@ final class Contrib_List_Command {
4141 * options:
4242 * - markdown
4343 * - html
44+ * - json
4445 * ---
4546 *
4647 * @when before_wp_load
@@ -49,18 +50,15 @@ public function __invoke( $args, $assoc_args ) {
4950 $ repos = null ;
5051 $ use_bundle = false ;
5152
52- $ ignored_contributors = [
53- 'github-actions[bot] ' ,
54- ];
55-
5653 if ( count ( $ args ) > 0 ) {
57- $ repos = [ array_shift ( $ args ) ];
54+ $ repos = [ GitHub :: qualify_repo ( array_shift ( $ args ) ) ];
5855 }
5956
6057 $ milestone_names = $ args ;
6158
6259 $ release = Utils \get_flag_value ( $ assoc_args , 'release ' );
6360 $ bundle_ref = Utils \get_flag_value ( $ assoc_args , 'bundle-ref ' );
61+ $ format = Utils \get_flag_value ( $ assoc_args , 'format ' , 'markdown ' );
6462
6563 if ( empty ( $ repos ) ) {
6664 $ use_bundle = true ;
@@ -73,39 +71,7 @@ public function __invoke( $args, $assoc_args ) {
7371 // Get the contributors to the current open large project milestones
7472 foreach ( $ repos as $ repo ) {
7573 if ( $ milestone_names ) {
76- $ milestone_names = (array ) $ milestone_names ;
77-
78- $ potential_milestones = GitHub ::get_project_milestones (
79- $ repo ,
80- array ( 'state ' => 'all ' )
81- );
82-
83- $ milestones = array ();
84- foreach ( $ potential_milestones as $ potential_milestone ) {
85- if ( in_array (
86- $ potential_milestone ->title ,
87- $ milestone_names ,
88- true
89- ) ) {
90- $ milestones [] = $ potential_milestone ;
91- $ index = array_search (
92- $ potential_milestone ->title ,
93- $ milestone_names ,
94- true
95- );
96- unset( $ milestone_names [ $ index ] );
97- }
98- }
99-
100- if ( ! empty ( $ milestone_names ) ) {
101- WP_CLI ::warning (
102- sprintf (
103- "Couldn't find the requested milestone(s) '%s' in repository '%s'. " ,
104- implode ( "', ' " , $ milestone_names ),
105- $ repo
106- )
107- );
108- }
74+ $ milestones = Release_Notes ::find_milestones ( $ repo , $ milestone_names );
10975 } else {
11076 $ milestone = Bundle ::get_release_milestone ( $ repo , $ use_bundle ? $ release : null );
11177 $ milestones = $ milestone ? [ $ milestone ] : [];
@@ -159,24 +125,39 @@ static function ( $milestone ) {
159125 }
160126 }
161127
162- $ contributors = array_diff ( $ contributors , $ ignored_contributors );
128+ asort ( $ contributors , SORT_NATURAL | SORT_FLAG_CASE );
129+
130+ if ( 'json ' === $ format ) {
131+ $ list = [];
132+ foreach ( $ contributors as $ url => $ login ) {
133+ $ list [] = [
134+ 'login ' => $ login ,
135+ 'url ' => $ url ,
136+ ];
137+ }
138+
139+ WP_CLI ::line (
140+ (string ) json_encode (
141+ [
142+ 'total_contributors ' => count ( $ contributors ),
143+ 'total_pull_requests ' => $ pull_request_count ,
144+ 'contributors ' => $ list ,
145+ ],
146+ JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
147+ )
148+ );
149+ return ;
150+ }
163151
164152 WP_CLI ::log ( 'Total contributors: ' . count ( $ contributors ) );
165153 WP_CLI ::log ( 'Total pull requests: ' . $ pull_request_count );
166154
167- // Sort and render the contributor list
168- asort ( $ contributors , SORT_NATURAL | SORT_FLAG_CASE );
169- if ( in_array ( $ assoc_args ['format ' ], array ( 'markdown ' , 'html ' ), true ) ) {
170- $ contrib_list = '' ;
171- foreach ( $ contributors as $ url => $ login ) {
172- if ( 'markdown ' === $ assoc_args ['format ' ] ) {
173- $ contrib_list .= '[@ ' . $ login . ']( ' . $ url . '), ' ;
174- } elseif ( 'html ' === $ assoc_args ['format ' ] ) {
175- $ contrib_list .= '<a href=" ' . $ url . '">@ ' . $ login . '</a>, ' ;
176- }
177- }
178- $ contrib_list = rtrim ( $ contrib_list , ', ' );
179- WP_CLI ::log ( $ contrib_list );
155+ $ contrib_list = [];
156+ foreach ( $ contributors as $ url => $ login ) {
157+ $ contrib_list [] = 'html ' === $ format
158+ ? '<a href=" ' . $ url . '">@ ' . $ login . '</a> '
159+ : '[@ ' . $ login . ']( ' . $ url . ') ' ;
180160 }
161+ WP_CLI ::log ( implode ( ', ' , $ contrib_list ) );
181162 }
182163}
0 commit comments