From 2d35ff799e7b97a90e2610eea939e64dbc9d426f Mon Sep 17 00:00:00 2001 From: Draga Doncila Date: Wed, 18 Mar 2026 11:27:59 +1100 Subject: [PATCH 1/4] Reformat gql call, avoid passing None to match --- lib/pyapi/github.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pyapi/github.py b/lib/pyapi/github.py index 0fa12c7f67..8d7831c9b1 100644 --- a/lib/pyapi/github.py +++ b/lib/pyapi/github.py @@ -105,7 +105,7 @@ def _activity(owner: str, name: str) -> GithubActivity: gql_client = Client(transport=transport, fetch_schema_from_transport=False) variables = {"owner": owner, "name": name} - data = gql_client.execute(query_activity, variables)["repository"] + data = gql_client.execute(query_activity, variable_values=variables)["repository"] last_commit_node = data["defaultBranchRef"]["target"]["history"]["nodes"][0] user = last_commit_node["author"].get("user") or {} date = last_commit_node["committedDate"] @@ -168,7 +168,7 @@ def org_repo(name: PluginName) -> tuple[str, str] | None: [info.get("home_page"), info.get("package_url"), info.get("project_url")], (info.get("project_urls") or {}).values(), ): - if match := GITHUB_RE.match(link): + if link is not None and (match := GITHUB_RE.match(link)): org, repo = match.groups() if repo.endswith(".git"): repo = repo[:-4] From 79f921cc6515df3e96c5b62601aae1802dab4765 Mon Sep 17 00:00:00 2001 From: Draga Doncila Date: Wed, 18 Mar 2026 16:53:05 +1100 Subject: [PATCH 2/4] Use codecov v2 api --- lib/pyapi/github.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/pyapi/github.py b/lib/pyapi/github.py index 8d7831c9b1..341d0a1d9f 100644 --- a/lib/pyapi/github.py +++ b/lib/pyapi/github.py @@ -138,18 +138,16 @@ def codecov(name: PluginName) -> CoverageInfo | None: if CODECOV_API_TOKEN := os.environ.get("CODECOV_API_TOKEN"): headers["Authorization"] = CODECOV_API_TOKEN - url = "https://codecov.io/api/gh/{}/{}".format(*result) + url = "https://api.codecov.io/api/v2/gh/{}/repos/{}/commits/".format(*result) data = requests.get(url, headers=headers).json() - commit: dict = data.get("commit") - if not commit: - commit = next((c for c in data.get("commits", []) if c.get("merged")), {}) + commit: dict = next(iter(data.get("results", [])), {}) if not commit or not (totals := commit.get("totals")): return None return CoverageInfo( - hits=totals["h"], - lines=totals["n"], - ratio=float(totals["c"]), + hits=totals["hits"], + lines=totals["lines"], + ratio=float(totals["coverage"]), commit=commit["commitid"], date=commit["timestamp"], branch=commit["branch"], From 5c2c5c74150139ec8e5bac1da07ac42a6dc04266 Mon Sep 17 00:00:00 2001 From: Draga Doncila Date: Wed, 18 Mar 2026 18:00:52 +1100 Subject: [PATCH 3/4] Try using default branch for codecov request --- lib/pyapi/github.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pyapi/github.py b/lib/pyapi/github.py index 341d0a1d9f..476336e7e8 100644 --- a/lib/pyapi/github.py +++ b/lib/pyapi/github.py @@ -129,7 +129,7 @@ def _activity(owner: str, name: str) -> GithubActivity: ) -def codecov(name: PluginName) -> CoverageInfo | None: +def codecov(name: PluginName, default_branch: str | None = None) -> CoverageInfo | None: """Return coverage using codecov api.""" if not (result := org_repo(name)): return None @@ -139,6 +139,11 @@ def codecov(name: PluginName) -> CoverageInfo | None: headers["Authorization"] = CODECOV_API_TOKEN url = "https://api.codecov.io/api/v2/gh/{}/repos/{}/commits/".format(*result) + # only get commit coverage info for the default branch + # if we couldn't find a default branch, we don't assume + if not default_branch: + return None + url += f"?branch={default_branch}" data = requests.get(url, headers=headers).json() commit: dict = next(iter(data.get("results", [])), {}) if not commit or not (totals := commit.get("totals")): @@ -217,7 +222,8 @@ def repo_summary(name: PluginName) -> RepoSummary: if not (result := org_repo(name)): raise ValueError(f"No github repo found for {name!r}") url = "https://github.com/{}/{}".format(*result) - return RepoSummary(url=url, activity=activity(name), coverage=codecov(name)) + act = activity(name) + return RepoSummary(url=url, activity=act, coverage=codecov(name, act["default_branch"])) def _try_fetch_and_store_github_info(name: PluginName): From 63cf4fbc303551ef89daf29c879e780c60ee2334 Mon Sep 17 00:00:00 2001 From: Draga Doncila Date: Wed, 18 Mar 2026 18:14:14 +1100 Subject: [PATCH 4/4] ruff format --- lib/pyapi/github.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/pyapi/github.py b/lib/pyapi/github.py index 476336e7e8..4d3f51d335 100644 --- a/lib/pyapi/github.py +++ b/lib/pyapi/github.py @@ -223,7 +223,9 @@ def repo_summary(name: PluginName) -> RepoSummary: raise ValueError(f"No github repo found for {name!r}") url = "https://github.com/{}/{}".format(*result) act = activity(name) - return RepoSummary(url=url, activity=act, coverage=codecov(name, act["default_branch"])) + return RepoSummary( + url=url, activity=act, coverage=codecov(name, act["default_branch"]) + ) def _try_fetch_and_store_github_info(name: PluginName):