12
12
use Rector \ReleaseNotesGenerator \Exception \InvalidConfigurationException ;
13
13
use Rector \ReleaseNotesGenerator \GithubApiCaller ;
14
14
use Rector \ReleaseNotesGenerator \GitResolver ;
15
+ use Rector \ReleaseNotesGenerator \ValueObject \Commit ;
15
16
use Rector \ReleaseNotesGenerator \ValueObject \ExternalRepositoryChangelog ;
16
17
use Symfony \Component \Console \Command \Command ;
17
18
use Symfony \Component \Console \Input \InputInterface ;
@@ -45,6 +46,8 @@ protected function configure(): void
45
46
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY ,
46
47
'Remote repository (use multiple values) '
47
48
);
49
+
50
+ $ this ->addOption (Option::REMOTE_ONLY , null , InputOption::VALUE_NONE , 'Show only remote repositories ' );
48
51
}
49
52
50
53
protected function execute (InputInterface $ input , OutputInterface $ output ): int
@@ -70,76 +73,33 @@ protected function execute(InputInterface $input, OutputInterface $output): int
70
73
return self ::FAILURE ;
71
74
}
72
75
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 );
81
77
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 ;
88
82
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 );
95
86
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 );
99
89
100
- $ changelogLine = sprintf (
101
- '* %s ([#%s](%s)) ' ,
102
- $ foundPullRequest ->title ,
103
- $ foundPullRequest ->number ,
104
- $ pullRequestUrl
105
- );
90
+ $ changelogLines [] = $ changelogLine ;
106
91
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 );
112
95
}
113
96
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 ;
136
98
}
137
99
138
- ++ $ i ;
100
+ $ releaseChangelogContents = $ this -> changelogContentsFactory -> create ( $ changelogLines ) ;
139
101
}
140
102
141
- $ releaseChangelogContents = $ this ->changelogContentsFactory ->create ($ changelogLines );
142
-
143
103
foreach ($ externalRepositoryChangelogs as $ externalRepositoryChangelog ) {
144
104
$ releaseChangelogContents .= PHP_EOL . PHP_EOL ;
145
105
$ releaseChangelogContents .= $ externalRepositoryChangelog ->toString ();
@@ -157,4 +117,44 @@ private function printToFile(string $releaseChangelogContents): void
157
117
158
118
$ this ->symfonyStyle ->writeln (sprintf ('Release notes dumped into "%s" file ' , $ filePath ));
159
119
}
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
+ }
160
160
}
0 commit comments