|
6 | 6 | require_once __DIR__ . '/vendor/autoload.php'; |
7 | 7 |
|
8 | 8 | use Github\Api\GraphQL; |
| 9 | +use Github\Api\PullRequest; |
9 | 10 | use Github\Api\Repo; |
10 | 11 | use Github\Api\Search; |
11 | 12 | use Github\AuthMethod; |
|
18 | 19 | use Symfony\Component\Console\Input\InputInterface; |
19 | 20 | use Symfony\Component\Console\Input\InputOption; |
20 | 21 | use Symfony\Component\Console\Output\OutputInterface; |
| 22 | +use function array_key_exists; |
21 | 23 | use function array_map; |
| 24 | +use function array_slice; |
| 25 | +use function array_unique; |
| 26 | +use function array_values; |
22 | 27 | use function count; |
23 | 28 | use function escapeshellarg; |
24 | 29 | use function exec; |
@@ -58,6 +63,9 @@ protected function execute(InputInterface $input, OutputInterface $output) |
58 | 63 | /** @var Repo $repoApi */ |
59 | 64 | $repoApi = $gitHubClient->api('repo'); |
60 | 65 |
|
| 66 | + /** @var PullRequest $pullRequestApi */ |
| 67 | + $pullRequestApi = $gitHubClient->api('pull_request'); |
| 68 | + |
61 | 69 | /** @var GraphQL $graphqlApi */ |
62 | 70 | $graphqlApi = $gitHubClient->api('graphql'); |
63 | 71 |
|
@@ -156,21 +164,44 @@ protected function execute(InputInterface $input, OutputInterface $output) |
156 | 164 | $items = $searchApi->issues(sprintf('repo:phpstan/phpstan %s is:issue', $commit['hash']), 'created')['items']; |
157 | 165 | } |
158 | 166 | $parenthesis = 'https://github.com/phpstan/phpstan-src/commit/' . $commit['hash']; |
159 | | - $thanks = null; |
| 167 | + $thanksNames = []; |
160 | 168 | $issuesToReference = []; |
161 | 169 | foreach ($items as $responseItem) { |
162 | 170 | if (isset($responseItem['pull_request'])) { |
163 | 171 | $parenthesis = sprintf('[#%d](%s)', $responseItem['number'], 'https://github.com/phpstan/phpstan-src/pull/' . $responseItem['number']); |
164 | 172 |
|
165 | | - if ($responseItem['user']['login'] !== 'ondrejmirtes') { |
166 | | - $thanks = $responseItem['user']['login']; |
| 173 | + if ($responseItem['user']['login'] === 'phpstan-bot') { |
| 174 | + $reviews = $pullRequestApi->reviews()->all('phpstan', 'phpstan-src', $responseItem['number']); |
| 175 | + foreach ($reviews as $review) { |
| 176 | + if (!array_key_exists('user', $review) || !array_key_exists('login', $review['user'])) { |
| 177 | + continue; |
| 178 | + } |
| 179 | + $reviewerLogin = $review['user']['login']; |
| 180 | + if ($reviewerLogin === 'ondrejmirtes' || $reviewerLogin === 'phpstan-bot') { |
| 181 | + continue; |
| 182 | + } |
| 183 | + $thanksNames[] = $reviewerLogin; |
| 184 | + } |
| 185 | + $thanksNames = array_values(array_unique($thanksNames)); |
| 186 | + } elseif ($responseItem['user']['login'] !== 'ondrejmirtes') { |
| 187 | + $thanksNames = [$responseItem['user']['login']]; |
167 | 188 | } |
168 | 189 | } else { |
169 | 190 | $issuesToReference[] = sprintf('#%d', $responseItem['number']); |
170 | 191 | } |
171 | 192 | } |
172 | 193 |
|
173 | | - $output->writeln(sprintf('* %s (%s)%s%s', $commit['message'], $parenthesis, count($issuesToReference) > 0 ? ', ' . implode(', ', $issuesToReference) : '', $thanks !== null ? sprintf(', thanks @%s!', $thanks) : '')); |
| 194 | + if (count($thanksNames) === 1) { |
| 195 | + $thanksText = sprintf(', thanks @%s!', $thanksNames[0]); |
| 196 | + } elseif (count($thanksNames) > 1) { |
| 197 | + $last = $thanksNames[count($thanksNames) - 1]; |
| 198 | + $rest = implode(', ', array_map(static fn (string $name): string => '@' . $name, array_slice($thanksNames, 0, -1))); |
| 199 | + $thanksText = sprintf(', thanks %s and @%s!', $rest, $last); |
| 200 | + } else { |
| 201 | + $thanksText = ''; |
| 202 | + } |
| 203 | + |
| 204 | + $output->writeln(sprintf('* %s (%s)%s%s', $commit['message'], $parenthesis, count($issuesToReference) > 0 ? ', ' . implode(', ', $issuesToReference) : '', $thanksText)); |
174 | 205 | } |
175 | 206 |
|
176 | 207 | return 0; |
|
0 commit comments