@@ -65,23 +65,29 @@ private function prepareRelease(Package $package, $branch, OutputInterface $outp
6565 static ::GITHUB_GROUP ,
6666 $ repositoryName
6767 );
68+
6869 $ commitToRelease = $ this ->githubClient ->git ()->references ()->show (
6970 static ::GITHUB_GROUP ,
7071 $ repositoryName ,
7172 'heads/ ' .$ branch
7273 );
7374
74- $ pulls = $ this ->findPullRequestsSince ($ currentRelease , $ repositoryName , $ branch );
75- $ nextVersion = $ this ->determineNextVersion ($ currentRelease ['tag_name ' ], $ pulls );
76-
77- $ this ->io ->section ('Project ' );
78-
7975 $ statuses = $ this ->githubClient ->repo ()->statuses ()->combined (
8076 static ::GITHUB_GROUP ,
8177 $ repositoryName ,
8278 $ commitToRelease ['object ' ]['sha ' ]
8379 );
8480
81+ $ pulls = $ this ->findPullRequestsSince ($ currentRelease , $ repositoryName , $ branch );
82+ $ nextVersion = $ this ->determineNextVersion ($ currentRelease ['tag_name ' ], $ pulls );
83+ $ changelog = array_reduce (
84+ array_filter (array_column ($ pulls , 'changelog ' )),
85+ 'array_merge_recursive ' ,
86+ array ()
87+ );
88+
89+ $ this ->io ->section ('Project ' );
90+
8591 foreach ($ statuses ['statuses ' ] as $ status ) {
8692 $ print = $ status ['description ' ].' ' .$ status ['target_url ' ];
8793
@@ -97,7 +103,7 @@ private function prepareRelease(Package $package, $branch, OutputInterface $outp
97103 $ this ->io ->section ('Pull requests ' );
98104
99105 foreach ($ pulls as $ pull ) {
100- $ output -> writeln ( $ this ->printPullRequest ($ pull) );
106+ $ this ->printPullRequest ($ pull, $ output );
101107 }
102108
103109 $ this ->io ->section ('Release ' );
@@ -110,34 +116,11 @@ private function prepareRelease(Package $package, $branch, OutputInterface $outp
110116
111117 $ this ->io ->section ('Changelog ' );
112118
113- $ output -> writeln ( $ this ->printRelease ($ currentRelease ['tag_name ' ], $ nextVersion , $ package) );
114- $ output -> writeln ( $ this ->printChangelog ($ pulls ) );
119+ $ this ->printRelease ($ currentRelease ['tag_name ' ], $ nextVersion , $ package, $ output );
120+ $ this ->printChangelog ($ changelog , $ output );
115121 }
116122
117- private function determineNextVersion ($ currentVersion , $ pulls )
118- {
119- $ stability = 'stable ' ;
120- foreach ($ pulls as $ pull ) {
121- if (in_array ($ pull ['stability ' ], array ('minor ' , 'patch ' ))) {
122- $ stability = $ pull ['stability ' ];
123-
124- if ('minor ' === $ pull ['stability ' ]) {
125- break ;
126- }
127- }
128- }
129-
130- $ parts = explode ('. ' , $ currentVersion );
131- if ('stable ' === $ stability ) {
132- return implode (array ($ parts [0 ], $ parts [1 ], $ parts [2 ]), '. ' );
133- } elseif ('minor ' === $ stability ) {
134- return implode (array ($ parts [0 ], $ parts [1 ] + 1 , 0 ), '. ' );
135- } elseif ('patch ' === $ stability ) {
136- return implode (array ($ parts [0 ], $ parts [1 ], $ parts [2 ] + 1 ), '. ' );
137- }
138- }
139-
140- private function printPullRequest ($ pull )
123+ private function printPullRequest ($ pull , OutputInterface $ output )
141124 {
142125 $ labelColors = array (
143126 'patch ' => 'blue ' ,
@@ -152,36 +135,58 @@ private function printPullRequest($pull)
152135 'stable ' => 'yellow ' ,
153136 );
154137
155- $ print = '<fg=black;bg= ' .$ stabilityColors [$ pull ['stability ' ]].'>[ ' . strtoupper ( $ pull [ ' stability ' ]). ' ]</> ' ;
156- $ print .= ' <info> ' .$ pull ['title ' ].'</info> ' ;
138+ $ output -> write ( '<fg=black;bg= ' .$ stabilityColors [$ pull ['stability ' ]].'>[ '
139+ . strtoupper ( $ pull [ ' stability ' ]). ' ]</> <info> ' .$ pull ['title ' ].'</info> ' ) ;
157140 foreach ($ pull ['labels ' ] as $ label ) {
158141 if (!array_key_exists ($ label ['name ' ], $ labelColors )) {
159- $ print .= ' <error>[ ' .$ label ['name ' ].']</error> ' ;
142+ $ output -> write ( ' <error>[ ' .$ label ['name ' ].']</error> ' ) ;
160143 } else {
161- $ print .= ' <fg= ' .$ labelColors [$ label ['name ' ]].'>[ ' .$ label ['name ' ].']</> ' ;
144+ $ output -> write ( ' <fg= ' .$ labelColors [$ label ['name ' ]].'>[ ' .$ label ['name ' ].']</> ' ) ;
162145 }
163146 }
164147
165148 if (empty ($ pull ['labels ' ])) {
166- $ print .= ' <fg=black;bg=yellow>[No labels]</> ' ;
149+ $ output -> write ( ' <fg=black;bg=yellow>[No labels]</> ' ) ;
167150 }
168151
169152 if (!$ pull ['changelog ' ] && 'stable ' !== $ pull ['stability ' ]) {
170- $ print .= ' <error>[Changelog not found]</error> ' ;
153+ $ output -> write ( ' <error>[Changelog not found]</error> ' ) ;
171154 } elseif (!$ pull ['changelog ' ]) {
172- $ print .= ' <fg=black;bg=green>[Changelog not found]</> ' ;
155+ $ output -> write ( ' <fg=black;bg=green>[Changelog not found]</> ' ) ;
173156 } elseif ($ pull ['changelog ' ] && 'stable ' === $ pull ['stability ' ]) {
174- $ print .= ' <fg=black;bg=yellow>[Changelog found]</> ' ;
157+ $ output -> write ( ' <fg=black;bg=yellow>[Changelog found]</> ' ) ;
175158 } else {
176- $ print .= ' <fg=black;bg=green>[Changelog found]</> ' ;
159+ $ output -> write ( ' <fg=black;bg=green>[Changelog found]</> ' ) ;
177160 }
161+ $ this ->io ->newLine ();
162+ $ output ->writeln ($ pull ['html_url ' ]);
163+ $ this ->io ->newLine ();
164+ }
178165
179- $ print .= PHP_EOL .$ pull ['html_url ' ].PHP_EOL ;
166+ private function printRelease ($ currentVersion , $ nextVersion , Package $ package , OutputInterface $ output )
167+ {
168+ $ output ->writeln ('## [ ' .$ nextVersion .']( '
169+ .$ package ->getRepository ().'/compare/ ' .$ currentVersion .'... ' .$ nextVersion
170+ .') - ' .date ('Y-m-d ' ));
171+ }
180172
181- return $ print ;
173+ private function printChangelog ($ changelog , OutputInterface $ output )
174+ {
175+ foreach ($ changelog as $ type => $ changes ) {
176+ if (count ($ changes ) === 0 ) {
177+ continue ;
178+ }
179+
180+ $ output ->writeln ('### ' .$ type );
181+
182+ foreach ($ changes as $ change ) {
183+ $ output ->writeln ('- ' .$ change );
184+ }
185+ $ this ->io ->newLine ();
186+ }
182187 }
183188
184- private function generateChangelog ($ pull )
189+ private function parseChangelog ($ pull )
185190 {
186191 $ changelog = array ();
187192 $ body = preg_replace ('/<!--(.*)-->/Uis ' , '' , $ pull ['body ' ]);
@@ -210,39 +215,30 @@ private function generateChangelog($pull)
210215 return $ changelog ;
211216 }
212217
213- private function printRelease ($ currentVersion , $ nextVersion , Package $ package )
214- {
215- return '## [ ' .$ nextVersion .']( '
216- .$ package ->getRepository ().'/compare/ ' .$ currentVersion .'... ' .$ nextVersion
217- .') - ' .date ('Y-m-d ' );
218- }
219-
220- private function printChangelog ($ pulls )
218+ private function determineNextVersion ($ currentVersion , $ pulls )
221219 {
222- $ changelog = array_reduce (
223- array_filter (array_column ($ pulls , 'changelog ' )),
224- 'array_merge_recursive ' ,
225- array ()
226- );
227-
228- $ print = '' ;
229- foreach ($ changelog as $ type => $ changes ) {
230- if (count ($ changes ) === 0 ) {
231- continue ;
232- }
233-
234- $ print .= '### ' .$ type .PHP_EOL ;
220+ $ stability = 'stable ' ;
221+ foreach ($ pulls as $ pull ) {
222+ if (in_array ($ pull ['stability ' ], array ('minor ' , 'patch ' ))) {
223+ $ stability = $ pull ['stability ' ];
235224
236- foreach ($ changes as $ change ) {
237- $ print .= '- ' .$ change .PHP_EOL ;
225+ if ('minor ' === $ pull ['stability ' ]) {
226+ break ;
227+ }
238228 }
239- $ print .= PHP_EOL ;
240229 }
241230
242- return $ print ;
231+ $ parts = explode ('. ' , $ currentVersion );
232+ if ('stable ' === $ stability ) {
233+ return implode (array ($ parts [0 ], $ parts [1 ], $ parts [2 ]), '. ' );
234+ } elseif ('minor ' === $ stability ) {
235+ return implode (array ($ parts [0 ], $ parts [1 ] + 1 , 0 ), '. ' );
236+ } elseif ('patch ' === $ stability ) {
237+ return implode (array ($ parts [0 ], $ parts [1 ], $ parts [2 ] + 1 ), '. ' );
238+ }
243239 }
244240
245- private function generatePullRequestStability ($ pull )
241+ private function determinePullRequestStability ($ pull )
246242 {
247243 $ stability = 'stable ' ;
248244 foreach ($ pull ['labels ' ] as $ label ) {
@@ -281,8 +277,8 @@ private function findPullRequestsSince($currentRelease, $repositoryName, $branch
281277 $ repositoryName ,
282278 $ pull ['number ' ]
283279 );
284- $ pull ['changelog ' ] = $ this ->generateChangelog ($ pull );
285- $ pull ['stability ' ] = $ this ->generatePullRequestStability ($ pull );
280+ $ pull ['changelog ' ] = $ this ->parseChangelog ($ pull );
281+ $ pull ['stability ' ] = $ this ->determinePullRequestStability ($ pull );
286282
287283 $ filteredPulls [] = $ pull ;
288284 }
0 commit comments