Skip to content

Commit

Permalink
Fix bug when same GitHub issue is referenced in multiple ways
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Masiakowski committed May 24, 2024
1 parent 2633f17 commit a9375cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
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": 4
"file_errors": 5
},
"files": {
"src/github-issues-and-prs.php": {
"errors": 4,
"errors": 5,
"messages": [
{
"message": "Should have been resolved in #59: fix me.",
Expand Down Expand Up @@ -34,6 +34,13 @@
"ignorable": false,
"tip": "See https://github.com/staabm/phpstan-todo-by/issues/26",
"identifier": "todoBy.ticket"
},
{
"message": "Comment should have been resolved in staabm/phpstan-todo-by#59.",
"line": 7,
"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 @@ -4,3 +4,4 @@
// TODO: staabm/phpstan-dba#452 - change me after https://github.com/staabm/phpstan-dba/issues/452 is closed
// TODO: phpstan/phpstan#3
// TODO: #26 - needs https://github.com/staabm/phpstan-todo-by/pull/26
// TODO: staabm/phpstan-todo-by#59

0 comments on commit a9375cd

Please sign in to comment.