From 4dd438b878ca6488208d087f53aa93e67582eb98 Mon Sep 17 00:00:00 2001 From: Emil Masiakowski Date: Fri, 24 May 2024 18:44:49 +0200 Subject: [PATCH] Fix bug when same GitHub issue is referenced in multiple ways --- src/utils/ticket/GitHubTicketStatusFetcher.php | 12 +++++++++--- tests-e2e/github/expected-errors.json | 11 +++++++++-- tests-e2e/github/src/github-issues-and-prs.php | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/utils/ticket/GitHubTicketStatusFetcher.php b/src/utils/ticket/GitHubTicketStatusFetcher.php index 2f822df..a8110bc 100644 --- a/src/utils/ticket/GitHubTicketStatusFetcher.php +++ b/src/utils/ticket/GitHubTicketStatusFetcher.php @@ -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; @@ -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; diff --git a/tests-e2e/github/expected-errors.json b/tests-e2e/github/expected-errors.json index 095412c..59c6661 100644 --- a/tests-e2e/github/expected-errors.json +++ b/tests-e2e/github/expected-errors.json @@ -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.", @@ -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" } ] } diff --git a/tests-e2e/github/src/github-issues-and-prs.php b/tests-e2e/github/src/github-issues-and-prs.php index b77b042..fb183c0 100644 --- a/tests-e2e/github/src/github-issues-and-prs.php +++ b/tests-e2e/github/src/github-issues-and-prs.php @@ -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