1212namespace Sonata \DevKit \Console \Command ;
1313
1414use Github \Exception \ExceptionInterface ;
15+ use Github \Exception \RuntimeException ;
1516use Packagist \Api \Result \Package ;
1617use Symfony \Component \Console \Input \InputInterface ;
1718use Symfony \Component \Console \Output \OutputInterface ;
@@ -113,10 +114,14 @@ private function prepareRelease(Package $package, $branch, OutputInterface $outp
113114 {
114115 $ repositoryName = $ this ->getRepositoryName ($ package );
115116
116- $ currentRelease = $ this ->githubClient ->repo ()->releases ()->latest (
117- static ::GITHUB_GROUP ,
118- $ repositoryName
119- );
117+ try {
118+ $ currentRelease = $ this ->githubClient ->repo ()->releases ()->latest (
119+ static ::GITHUB_GROUP ,
120+ $ repositoryName
121+ );
122+ } catch (ExceptionInterface $ e ) {
123+ throw new RuntimeException ('Current release not found ' );
124+ }
120125
121126 $ branchToRelease = $ this ->githubClient ->repo ()->branches (
122127 static ::GITHUB_GROUP ,
@@ -130,7 +135,7 @@ private function prepareRelease(Package $package, $branch, OutputInterface $outp
130135 $ branchToRelease ['commit ' ]['sha ' ]
131136 );
132137
133- $ pulls = $ this ->findPullRequestsSince ($ currentRelease , $ repositoryName , $ branch );
138+ $ pulls = $ this ->findPullRequestsSince ($ currentRelease[ ' published_at ' ] , $ repositoryName , $ branch );
134139 $ nextVersion = $ this ->determineNextVersion ($ currentRelease ['tag_name ' ], $ pulls );
135140 $ changelog = array_reduce (
136141 array_filter (array_column ($ pulls , 'changelog ' )),
@@ -289,11 +294,11 @@ private function determinePullRequestStability($pull)
289294 }
290295 }
291296
292- private function findPullRequestsSince ($ currentRelease , $ repositoryName , $ branch )
297+ private function findPullRequestsSince ($ date , $ repositoryName , $ branch )
293298 {
294299 $ pulls = $ this ->githubPaginator ->fetchAll ($ this ->githubClient ->search (), 'issues ' , array (
295300 'repo: ' .static ::GITHUB_GROUP .'/ ' .$ repositoryName .
296- ' type:pr is:merged base: ' .$ branch .' merged:> ' .$ currentRelease [ ' published_at ' ] ,
301+ ' type:pr is:merged base: ' .$ branch .' merged:> ' .$ date ,
297302 ));
298303
299304 $ filteredPulls = array ();
0 commit comments