From f7e798b46711535251860ded654946a8e39f514b Mon Sep 17 00:00:00 2001 From: Giovanni M Guidini <99758426+giovanni-guidini@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:21:22 +0200 Subject: [PATCH] fix: fix fallback system in GH (again) (#245) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I broke the GH fallback system again 😅 Fixes this issue: https://l.codecov.dev/dEsZeK The problem is that since https://github.com/codecov/shared/pull/225 (technically https://github.com/codecov/worker/pull/470 actually) we include 1 extra piece of information in `GitHubAppInstallationInfo`, the `GitHubAppInstallation.id`. This is breaking the function that gets tokens because we are destructuring the info dict into the kwargs for the function (with the extra, unexpected `id` one). To fix that we just pop it before calling the function. --- shared/torngit/github.py | 2 ++ tests/unit/torngit/test_github.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/shared/torngit/github.py b/shared/torngit/github.py index 256f25f3..f70b66bf 100644 --- a/shared/torngit/github.py +++ b/shared/torngit/github.py @@ -739,6 +739,7 @@ def _get_next_fallback_token( installation_info = fallback_installations.pop(0) # The function arg is 'integration_id' installation_id = installation_info.pop("installation_id") + obj_id = installation_info.pop("id", None) token_to_use = get_github_integration_token( self.service, installation_id, **installation_info ) @@ -747,6 +748,7 @@ def _get_next_fallback_token( self.data["installation"] = { # Put the installation_id back into the info "installation_id": installation_id, + "id": obj_id, **installation_info, } return token_to_use diff --git a/tests/unit/torngit/test_github.py b/tests/unit/torngit/test_github.py index 169cc791..8f944d88 100644 --- a/tests/unit/torngit/test_github.py +++ b/tests/unit/torngit/test_github.py @@ -1097,7 +1097,12 @@ async def test_update_check_run_url_fallback(self, mocker): installation_id=1500, ), fallback_installations=[ - {"installation_id": 12342, "app_id": 1200, "pem_path": "some_path"} + { + "installation_id": 12342, + "app_id": 1200, + "pem_path": "some_path", + "id": 20, + } ], )