Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when same GitHub issue is referenced in multiple ways #97

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/utils/ticket/GitHubTicketStatusFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public function fetchTicketStatusByUrls(array $ticketUrls): array
$responses = $this->httpClient->getMulti($ticketUrls, $headers);

$results = [];
$urlsToKeys = array_flip($ticketUrls);

$urlsToKeys = [];
foreach ($ticketUrls as $key => $url) {
$urlsToKeys[$url][] = $key;
}

foreach ($responses as $url => [$responseCode, $response]) {
if (404 === $responseCode) {
$results[$url] = null;
Expand All @@ -94,8 +99,9 @@ public function fetchTicketStatusByUrls(array $ticketUrls): array
throw new RuntimeException("GitHub returned invalid response body with $url");
}

$ticketKey = $urlsToKeys[$url];
$results[$ticketKey] = $data['state'];
foreach ($urlsToKeys[$url] as $ticketKey) {
$results[$ticketKey] = $data['state'];
}
}

return $results;
Expand Down
11 changes: 9 additions & 2 deletions tests-e2e/github/expected-errors.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"totals": {
"errors": 0,
"file_errors": 5
"file_errors": 6
},
"files": {
"src/github-issues-and-prs.php": {
"errors": 5,
"errors": 6,
"messages": [
{
"message": "Should have been resolved in #59: fix me.",
Expand Down Expand Up @@ -41,6 +41,13 @@
"ignorable": false,
"tip": "See https://github.com/staabm/phpstan-todo-by/issues/27",
"identifier": "todoBy.ticket"
},
{
"message": "Comment should have been resolved in staabm/phpstan-todo-by#59.",
"line": 8,
"ignorable": false,
"tip": "See https://github.com/staabm/phpstan-todo-by/issues/59",
"identifier": "todoBy.ticket"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions tests-e2e/github/src/github-issues-and-prs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
// TODO: phpstan/phpstan#3
// TODO: #26 - needs https://github.com/staabm/phpstan-todo-by/pull/26
// TODO: GH-27
// TODO: staabm/phpstan-todo-by#59
Loading