55
66final class Contrib_List_Command {
77
8+ /**
9+ * Packages excluded from contributor list generation.
10+ *
11+ * @var array
12+ */
13+ private $ excluded_packages = [
14+ 'wp-cli/wp-cli-tests ' ,
15+ 'wp-cli/regenerate-readme ' ,
16+ 'wp-cli/autoload-splitter ' ,
17+ 'wp-cli/wp-config-transformer ' ,
18+ 'wp-cli/php-cli-tools ' ,
19+ 'wp-cli/spyc ' ,
20+ ];
21+
822 /**
923 * Lists all contributors to this release.
1024 *
@@ -25,40 +39,33 @@ final class Contrib_List_Command {
2539 */
2640 public function __invoke ( $ _ , $ assoc_args ) {
2741
28- $ contributors = array () ;
42+ $ contributors = [] ;
2943 $ pull_request_count = 0 ;
3044
3145 // Get the contributors to the current open large project milestones
32- foreach ( array ( 'wp-cli/wp-cli-bundle ' , 'wp-cli/wp-cli ' , 'wp-cli/handbook ' , 'wp-cli/wp-cli.github.com ' ) as $ repo ) {
46+ foreach ( [ 'wp-cli/wp-cli-bundle ' , 'wp-cli/wp-cli ' , 'wp-cli/handbook ' , 'wp-cli/wp-cli.github.com ' ] as $ repo ) {
3347 $ milestones = GitHub::get_project_milestones ( $ repo );
3448 // Cheap way to get the latest milestone
3549 $ milestone = array_shift ( $ milestones );
3650 if ( ! $ milestone ) {
3751 continue ;
3852 }
3953 WP_CLI ::log ( 'Current open ' . $ repo . ' milestone: ' . $ milestone ->title );
40- $ pull_requests = GitHub::get_project_milestone_pull_requests ( $ repo , $ milestone ->number );
54+ $ pull_requests = GitHub::get_project_milestone_pull_requests ( $ repo , $ milestone ->number );
4155 $ repo_contributors = GitHub::parse_contributors_from_pull_requests ( $ pull_requests );
4256 WP_CLI ::log ( ' - Contributors: ' . count ( $ repo_contributors ) );
4357 WP_CLI ::log ( ' - Pull requests: ' . count ( $ pull_requests ) );
4458 $ pull_request_count += count ( $ pull_requests );
45- $ contributors = array_merge ( $ contributors , $ repo_contributors );
59+ $ contributors = array_merge ( $ contributors , $ repo_contributors );
4660 }
4761
4862 // Identify all command dependencies and their contributors
63+ $ bundle = 'wp-cli/wp-cli-bundle ' ;
4964
50- // TODO: Bundle repo needs to be switched to `wp-cli/wp-cli-bundle` for next release.
51- $ bundle = 'wp-cli/wp-cli ' ;
52-
53- $ milestones = GitHub::get_project_milestones ( 'wp-cli/wp-cli ' , array ( 'state ' => 'closed ' ) );
65+ $ milestones = GitHub::get_project_milestones ( 'wp-cli/wp-cli ' , [ 'state ' => 'closed ' ] );
5466 // Cheap way to get the latest closed milestone
5567 $ milestone = array_shift ( $ milestones );
56- $ tag = is_object ( $ milestone ) ? "v {$ milestone ->title }" : 'master ' ;
57-
58- // TODO: Only needed for switch from v1 to v2.
59- if ( 'wp-cli/wp-cli ' === $ bundle ) {
60- $ tag = 'v1.5.1 ' ;
61- }
68+ $ tag = is_object ( $ milestone ) ? "v {$ milestone ->title }" : 'master ' ;
6269
6370 $ composer_lock_url = sprintf ( 'https://raw.githubusercontent.com/%s/%s/composer.lock ' , $ bundle , $ tag );
6471 WP_CLI ::log ( 'Fetching ' . $ composer_lock_url );
@@ -68,49 +75,43 @@ public function __invoke( $_, $assoc_args ) {
6875 }
6976 $ composer_json = json_decode ( $ response ->body , true );
7077
71- // TODO: Only need for initial v2.
72- $ composer_json ['packages ' ][] = array ( 'name ' => 'wp-cli/i18n-command ' , 'version ' => 'v2 ' );
73- usort ( $ composer_json ['packages ' ], function ( $ a , $ b ) {
74- return $ a ['name ' ] < $ b ['name ' ] ? -1 : 1 ;
75- } );
78+ usort (
79+ $ composer_json ['packages ' ],
80+ function ( $ a , $ b ) {
81+ return $ a ['name ' ] < $ b ['name ' ] ? -1 : 1 ;
82+ }
83+ );
7684
77- foreach ( $ composer_json ['packages ' ] as $ package ) {
78- $ package_name = $ package ['name ' ];
85+ foreach ( $ composer_json ['packages ' ] as $ package ) {
86+ $ package_name = $ package ['name ' ];
7987 $ version_constraint = str_replace ( 'v ' , '' , $ package ['version ' ] );
8088 if ( ! preg_match ( '#^wp-cli/.+-command$# ' , $ package_name )
81- && ! in_array ( $ package_name , array (
82- 'wp-cli/wp-cli-tests ' ,
83- 'wp-cli/regenerate-readme ' ,
84- 'wp-cli/autoload-splitter ' ,
85- 'wp-cli/wp-config-transformer ' ,
86- 'wp-cli/php-cli-tools ' ,
87- 'wp-cli/spyc ' ,
88- ), true ) ) {
89+ && ! in_array ( $ package_name , $ this ->excluded_packages , true ) ) {
8990 continue ;
9091 }
9192 // Closed milestones denote a tagged release
92- $ milestones = GitHub::get_project_milestones ( $ package_name , array ( 'state ' => 'closed ' ) );
93- $ milestone_ids = array () ;
94- $ milestone_titles = array () ;
95- foreach ( $ milestones as $ milestone ) {
93+ $ milestones = GitHub::get_project_milestones ( $ package_name , [ 'state ' => 'closed ' ] );
94+ $ milestone_ids = [] ;
95+ $ milestone_titles = [] ;
96+ foreach ( $ milestones as $ milestone ) {
9697 if ( ! version_compare ( $ milestone ->title , $ version_constraint , '> ' ) ) {
9798 continue ;
9899 }
99- $ milestone_ids [] = $ milestone ->number ;
100+ $ milestone_ids [] = $ milestone ->number ;
100101 $ milestone_titles [] = $ milestone ->title ;
101102 }
102103 // No shipped releases for this milestone.
103104 if ( empty ( $ milestone_ids ) ) {
104105 continue ;
105106 }
106107 WP_CLI ::log ( 'Closed ' . $ package_name . ' milestone(s): ' . implode ( ', ' , $ milestone_titles ) );
107- foreach ( $ milestone_ids as $ milestone_id ) {
108- $ pull_requests = GitHub::get_project_milestone_pull_requests ( $ package_name , $ milestone_id );
108+ foreach ( $ milestone_ids as $ milestone_id ) {
109+ $ pull_requests = GitHub::get_project_milestone_pull_requests ( $ package_name , $ milestone_id );
109110 $ repo_contributors = GitHub::parse_contributors_from_pull_requests ( $ pull_requests );
110111 WP_CLI ::log ( ' - Contributors: ' . count ( $ repo_contributors ) );
111112 WP_CLI ::log ( ' - Pull requests: ' . count ( $ pull_requests ) );
112113 $ pull_request_count += count ( $ pull_requests );
113- $ contributors = array_merge ( $ contributors , $ repo_contributors );
114+ $ contributors = array_merge ( $ contributors , $ repo_contributors );
114115 }
115116 }
116117
@@ -119,9 +120,9 @@ public function __invoke( $_, $assoc_args ) {
119120
120121 // Sort and render the contributor list
121122 asort ( $ contributors , SORT_NATURAL | SORT_FLAG_CASE );
122- if ( in_array ( $ assoc_args ['format ' ], array ( 'markdown ' , 'html ' ) ) ) {
123+ if ( in_array ( $ assoc_args ['format ' ], [ 'markdown ' , 'html ' ], true ) ) {
123124 $ contrib_list = '' ;
124- foreach ( $ contributors as $ url => $ login ) {
125+ foreach ( $ contributors as $ url => $ login ) {
125126 if ( 'markdown ' === $ assoc_args ['format ' ] ) {
126127 $ contrib_list .= '[@ ' . $ login . ']( ' . $ url . '), ' ;
127128 } elseif ( 'html ' === $ assoc_args ['format ' ] ) {
0 commit comments