Skip to content

Commit 43c1a1b

Browse files
committed
changelog-generator - extract closed issues from PR body
1 parent b73b0f5 commit 43c1a1b

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

changelog-generator/run.php

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

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

8-
use Github\Api\GraphQL;
98
use Github\Api\PullRequest;
109
use Github\Api\Repo;
1110
use Github\Api\Search;
@@ -29,6 +28,7 @@
2928
use function exec;
3029
use function explode;
3130
use function implode;
31+
use function preg_match_all;
3232
use function preg_replace;
3333
use function sprintf;
3434

@@ -67,9 +67,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767
/** @var PullRequest $pullRequestApi */
6868
$pullRequestApi = $gitHubClient->api('pull_request');
6969

70-
/** @var GraphQL $graphqlApi */
71-
$graphqlApi = $gitHubClient->api('graphql');
72-
7370
$command = ['git', 'log', sprintf('%s..%s', $input->getArgument('fromCommit'), $input->getArgument('toCommit'))];
7471
$excludeBranch = $input->getOption('exclude-branch');
7572
if ($excludeBranch !== null) {
@@ -135,31 +132,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
135132
'user' => $pullRequests[0]['user'],
136133
],
137134
];
138-
$autoclosedIssues = $graphqlApi->execute(
139-
<<<'QUERY'
140-
query ($owner:String!, $repo:String!, $pr:Int!){
141-
repository(owner:$owner, name:$repo){
142-
pullRequest(number:$pr){
143-
closingIssuesReferences(first:100){
144-
nodes { number title url repository { nameWithOwner } }
145-
}
146-
}
147-
}
148-
},
149-
QUERY,
150-
[
151-
'owner' => 'phpstan',
152-
'repo' => 'phpstan-src',
153-
'pr' => $pullRequests[0]['number'],
154-
],
155-
);
156-
foreach ($autoclosedIssues['data']['repository']['pullRequest']['closingIssuesReferences']['nodes'] as $closedIssue) {
157-
if ($closedIssue['repository']['nameWithOwner'] !== 'phpstan/phpstan') {
158-
continue;
135+
$prBody = $pullRequests[0]['body'] ?? '';
136+
if (preg_match_all('/(?:closes?|fix(?:es)?)\s+(?:https:\/\/github\.com\/phpstan\/phpstan\/issues\/|phpstan\/phpstan#)(\d+)/i', $prBody, $matches)) {
137+
foreach (array_unique($matches[1]) as $issueNumber) {
138+
$items[] = [
139+
'number' => (int) $issueNumber,
140+
];
159141
}
160-
$items[] = [
161-
'number' => $closedIssue['number'],
162-
];
163142
}
164143
} else {
165144
$items = $searchApi->issues(sprintf('repo:phpstan/phpstan %s is:issue', $commit['hash']), 'created')['items'];

0 commit comments

Comments
 (0)