From a9375cd92a0c28ff6717974de6ce9a1c2e7ddc97 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 f5fd0cc..d863836 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 97c7ac5..c0db611 100644 --- a/tests-e2e/github/expected-errors.json +++ b/tests-e2e/github/expected-errors.json @@ -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.", @@ -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" } ] } diff --git a/tests-e2e/github/src/github-issues-and-prs.php b/tests-e2e/github/src/github-issues-and-prs.php index a4c18ac..e1905a7 100644 --- a/tests-e2e/github/src/github-issues-and-prs.php +++ b/tests-e2e/github/src/github-issues-and-prs.php @@ -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