Skip to content

Commit e153fa4

Browse files
committed
Use better API to associate commit with a merged PR
1 parent 8e85850 commit e153fa4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

changelog-generator/run.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
require_once __DIR__ . '/vendor/autoload.php';
77

8+
use Github\Api\Repo;
89
use Github\Api\Search;
910
use Github\AuthMethod;
1011
use Github\Client;
@@ -54,6 +55,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
5455
/** @var Search $searchApi */
5556
$searchApi = $gitHubClient->api('search');
5657

58+
/** @var Repo $repoApi */
59+
$repoApi = $gitHubClient->api('repo');
60+
5761
$command = ['git', 'log', sprintf('%s..%s', $input->getArgument('fromCommit'), $input->getArgument('toCommit'))];
5862
$excludeBranch = $input->getOption('exclude-branch');
5963
if ($excludeBranch !== null) {
@@ -110,9 +114,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
110114
}
111115

112116
foreach ($commits as $commit) {
113-
$pullRequests = $searchApi->issues(sprintf('repo:phpstan/phpstan-src %s is:pull-request', $commit['hash']));
114-
$issues = $searchApi->issues(sprintf('repo:phpstan/phpstan %s is:issue', $commit['hash']), 'created');
115-
$items = array_merge($pullRequests['items'], $issues['items']);
117+
$pullRequests = $repoApi->commits()->pulls('phpstan', 'phpstan-src', $commit['hash']);
118+
$items = $searchApi->issues(sprintf('repo:phpstan/phpstan %s is:issue', $commit['hash']), 'created')['items'];
119+
if (count($pullRequests) > 0) {
120+
$items[] = [
121+
'pull_request' => true,
122+
'number' => $pullRequests[0]['number'],
123+
'user' => $pullRequests[0]['user'],
124+
];
125+
}
116126
$parenthesis = 'https://github.com/phpstan/phpstan-src/commit/' . $commit['hash'];
117127
$thanks = null;
118128
$issuesToReference = [];

0 commit comments

Comments
 (0)