1212use Rector \ReleaseNotesGenerator \Exception \InvalidConfigurationException ;
1313use Rector \ReleaseNotesGenerator \GithubApiCaller ;
1414use Rector \ReleaseNotesGenerator \GitResolver ;
15+ use Rector \ReleaseNotesGenerator \ValueObject \Commit ;
1516use Rector \ReleaseNotesGenerator \ValueObject \ExternalRepositoryChangelog ;
1617use Symfony \Component \Console \Command \Command ;
1718use Symfony \Component \Console \Input \InputInterface ;
@@ -45,6 +46,8 @@ protected function configure(): void
4546 InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY ,
4647 'Remote repository (use multiple values) '
4748 );
49+
50+ $ this ->addOption (Option::REMOTE_ONLY , null , InputOption::VALUE_NONE , 'Show only remote repositories ' );
4851 }
4952
5053 protected function execute (InputInterface $ input , OutputInterface $ output ): int
@@ -70,76 +73,33 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7073 return self ::FAILURE ;
7174 }
7275
73- $ externalRepositoryChangelogs = [];
74-
75- if ($ configuration ->hasRemoteRepositories ()) {
76- // process remote repositories by date first
77- $ startCommit = $ commits [array_key_first ($ commits )];
78- $ endCommit = $ commits [array_key_last ($ commits )];
79-
80- foreach ($ configuration ->getRemoteRepositories () as $ remoteRepository ) {
76+ $ externalRepositoryChangelogs = $ this ->resolveExternalRepositoryChangelogs ($ commits , $ configuration );
8177
82- $ foundPullRequests = $ this ->githubApiCaller ->findRepositoryPullRequestsBetweenDates (
83- $ remoteRepository ,
84- $ configuration ->getGithubToken (),
85- $ startCommit ->getDate (),
86- $ endCommit ->getDate ()
87- );
78+ if ($ configuration ->isRemoteOnly ()) {
79+ $ releaseChangelogContents = '' ;
80+ } else {
81+ $ i = 0 ;
8882
89- // nothing to process
90- if ($ foundPullRequests ->total_count === 0 ) {
91- continue ;
92- }
93-
94- $ externalChangelogLines = [];
83+ $ changelogLines = [];
84+ foreach ($ commits as $ commit ) {
85+ $ changelogLine = $ this ->changelogLineFactory ->create ($ commit , $ configuration );
9586
96- foreach ($ foundPullRequests ->items as $ foundPullRequest ) {
97- $ username = $ foundPullRequest ->user ->login ;
98- $ pullRequestUrl = $ foundPullRequest ->pull_request ->url ;
87+ // just to show the script is doing something :)
88+ $ this ->symfonyStyle ->writeln ($ changelogLine );
9989
100- $ changelogLine = sprintf (
101- '* %s ([#%s](%s)) ' ,
102- $ foundPullRequest ->title ,
103- $ foundPullRequest ->number ,
104- $ pullRequestUrl
105- );
90+ $ changelogLines [] = $ changelogLine ;
10691
107- if (! in_array ($ username , Configuration::EXCLUDED_THANKS_NAMES , true )) {
108- $ changelogLine .= ', Thanks @ ' . $ username ;
109- }
110-
111- $ externalChangelogLines [] = $ changelogLine ;
92+ // not to throttle the GitHub API
93+ if ($ i > 0 && $ i % 8 === 0 ) {
94+ sleep (60 );
11295 }
11396
114- $ externalRepositoryChangelogs [] = new ExternalRepositoryChangelog (
115- $ remoteRepository ,
116- $ externalChangelogLines
117- );
118- }
119- }
120-
121- $ i = 0 ;
122-
123- $ changelogLines = [];
124-
125- foreach ($ commits as $ commit ) {
126- $ changelogLine = $ this ->changelogLineFactory ->create ($ commit , $ configuration );
127-
128- // just to show the script is doing something :)
129- $ this ->symfonyStyle ->writeln ($ changelogLine );
130-
131- $ changelogLines [] = $ changelogLine ;
132-
133- // not to throttle the GitHub API
134- if ($ i > 0 && $ i % 8 === 0 ) {
135- sleep (60 );
97+ ++$ i ;
13698 }
13799
138- ++ $ i ;
100+ $ releaseChangelogContents = $ this -> changelogContentsFactory -> create ( $ changelogLines ) ;
139101 }
140102
141- $ releaseChangelogContents = $ this ->changelogContentsFactory ->create ($ changelogLines );
142-
143103 foreach ($ externalRepositoryChangelogs as $ externalRepositoryChangelog ) {
144104 $ releaseChangelogContents .= PHP_EOL . PHP_EOL ;
145105 $ releaseChangelogContents .= $ externalRepositoryChangelog ->toString ();
@@ -157,4 +117,44 @@ private function printToFile(string $releaseChangelogContents): void
157117
158118 $ this ->symfonyStyle ->writeln (sprintf ('Release notes dumped into "%s" file ' , $ filePath ));
159119 }
120+
121+ /**
122+ * @param Commit[] $commits
123+ * @return ExternalRepositoryChangelog[]
124+ */
125+ private function resolveExternalRepositoryChangelogs (array $ commits , Configuration $ configuration ): array
126+ {
127+ if (! $ configuration ->hasRemoteRepositories ()) {
128+ return [];
129+ }
130+
131+ $ externalRepositoryChangelogs = [];
132+
133+ // process remote repositories by date first
134+ $ startCommit = $ commits [array_key_first ($ commits )];
135+ $ endCommit = $ commits [array_key_last ($ commits )];
136+
137+ foreach ($ configuration ->getRemoteRepositories () as $ remoteRepository ) {
138+ $ foundPullRequests = $ this ->githubApiCaller ->findRepositoryPullRequestsBetweenDates (
139+ $ remoteRepository ,
140+ $ configuration ->getGithubToken (),
141+ $ startCommit ->getDate (),
142+ $ endCommit ->getDate ()
143+ );
144+
145+ // nothing to process
146+ if ($ foundPullRequests ->total_count === 0 ) {
147+ continue ;
148+ }
149+
150+ $ externalChangelogLines = $ this ->changelogLineFactory ->createFromPullRequests ($ foundPullRequests );
151+
152+ $ externalRepositoryChangelogs [] = new ExternalRepositoryChangelog (
153+ $ remoteRepository ,
154+ $ externalChangelogLines
155+ );
156+ }
157+
158+ return $ externalRepositoryChangelogs ;
159+ }
160160}
0 commit comments