From d1aec8cd8fe3274f652679d17a7a77e139e5cad6 Mon Sep 17 00:00:00 2001 From: Dmitriy Gaiduk <5601396+DmitriyG1@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:29:38 +0400 Subject: [PATCH 1/4] fix(scripts): stop reading the github token on the curl path Without gh, releases.py asked GitHub through curl and sent GITHUB_TOKEN from the environment as an Authorization header. The skill must not read credentials (AGENTS.md, Security rules). gh is now the only authenticated way to GitHub; without it curl runs unauthenticated (60 requests an hour) and the client status line says so. gh reads GH_TOKEN / GITHUB_TOKEN itself. Co-Authored-By: Claude Opus 5.5 --- skills/android-upstream-audit/scripts/common.py | 2 +- skills/android-upstream-audit/scripts/releases.py | 10 ++++------ skills/android-upstream-audit/scripts/slice.py | 2 +- .../scripts/tests/test_releases.py | 9 +++++++++ .../android-upstream-audit/scripts/tests/test_slice.py | 3 ++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/skills/android-upstream-audit/scripts/common.py b/skills/android-upstream-audit/scripts/common.py index 2f24c70..41a8b7b 100644 --- a/skills/android-upstream-audit/scripts/common.py +++ b/skills/android-upstream-audit/scripts/common.py @@ -33,7 +33,7 @@ def curl(url: str, path: str | None = None, headers: list[str] | None = None) -> str | None: """Downloads with curl, not urllib: the system Python may ship without CA certificates. - Headers go through stdin, so a token never shows in the process list.""" + Headers go through stdin (`-H @-`), not the command line.""" cmd = ['curl', '-sSL', '--fail', '--max-time', '90', '-A', 'android-upstream-audit/1.0', url] if path: cmd += ['-o', path] diff --git a/skills/android-upstream-audit/scripts/releases.py b/skills/android-upstream-audit/scripts/releases.py index ca52e35..a816aac 100644 --- a/skills/android-upstream-audit/scripts/releases.py +++ b/skills/android-upstream-audit/scripts/releases.py @@ -20,8 +20,8 @@ 4. config.json against the project: a vendored artifact it does not name (UNCONFIGURED VENDORED), and an entry for a path the build no longer uses (STALE CONFIG). -GitHub is asked through `gh` when it is installed, otherwise through curl (unauthenticated, -60 requests an hour, or with GITHUB_TOKEN). `--out` writes releases.json for slice.py. +GitHub is asked through `gh` when it is installed, otherwise through curl, unauthenticated +(60 requests an hour). `--out` writes releases.json for slice.py. `--body` prints the notes of one release. Anything published on or after `--since` (default: the previous run's start) is marked NEW. """ @@ -67,8 +67,6 @@ def github(path, client): raise RuntimeError((r.stderr or r.stdout).strip().split('\n')[0]) return json.loads(r.stdout) headers = ['Accept: application/vnd.github+json'] - if os.environ.get('GITHUB_TOKEN'): - headers.append(f"Authorization: Bearer {os.environ['GITHUB_TOKEN']}") return json.loads(common.curl('https://api.github.com/' + path, headers=headers)) @@ -435,8 +433,8 @@ def main(): if client == 'gh': print('## GitHub API client: gh') else: - print('## GitHub API client: curl — gh is not installed; install gh for authenticated requests ' - f"({'GITHUB_TOKEN is set' if os.environ.get('GITHUB_TOKEN') else 'unauthenticated, 60 requests an hour'})") + print('## GitHub API client: curl — gh is not installed; unauthenticated, 60 requests an hour; ' + 'install and authenticate gh for more') checked = [e for e in entries if e['version']] unique = sorted({e['coord'] for e in checked}) diff --git a/skills/android-upstream-audit/scripts/slice.py b/skills/android-upstream-audit/scripts/slice.py index b114095..ae03eb3 100644 --- a/skills/android-upstream-audit/scripts/slice.py +++ b/skills/android-upstream-audit/scripts/slice.py @@ -125,7 +125,7 @@ def upkeep_line(out): if q.get('sources_failed'): parts.append(f"{q['sources_failed']} sources failed") if q.get('github_client') == 'curl': - parts.append('GitHub queried with curl, gh is not installed — install gh for authenticated requests') + parts.append('GitHub queried with curl, unauthenticated (60 requests an hour) — install and authenticate gh') if q.get('dependencies_not_checked'): parts.append(f"{len(q['dependencies_not_checked'])} dependencies not checked") if (q.get('resolved_versions') or {}).get('status') in ('failed', 'timeout'): diff --git a/skills/android-upstream-audit/scripts/tests/test_releases.py b/skills/android-upstream-audit/scripts/tests/test_releases.py index 89f8004..f7a4d08 100644 --- a/skills/android-upstream-audit/scripts/tests/test_releases.py +++ b/skills/android-upstream-audit/scripts/tests/test_releases.py @@ -3,6 +3,7 @@ import os import tempfile import unittest +from unittest import mock import fixtures # noqa: F401 (puts the scripts on sys.path) import common # noqa: E402 @@ -271,6 +272,14 @@ def test_github_through_curl_without_gh(self): self.assertEqual(calls[0][0], 'https://api.github.com/repos/google/ksp/releases?per_page=5') self.assertIn('Accept: application/vnd.github+json', calls[0][1]) + def test_curl_sends_no_authorization_even_with_github_token(self): + calls = [] + fake_curl = lambda url, path=None, headers=None: calls.append(headers) or '[]' # noqa: E731 + with mock.patch.object(common, 'curl', fake_curl), \ + mock.patch.dict(os.environ, {'GITHUB_TOKEN': 'test-token'}): + releases.github('repos/google/ksp/releases?per_page=5', 'curl') + self.assertEqual(calls, [['Accept: application/vnd.github+json']]) + if __name__ == '__main__': unittest.main() diff --git a/skills/android-upstream-audit/scripts/tests/test_slice.py b/skills/android-upstream-audit/scripts/tests/test_slice.py index 345ce50..7dd0505 100644 --- a/skills/android-upstream-audit/scripts/tests/test_slice.py +++ b/skills/android-upstream-audit/scripts/tests/test_slice.py @@ -438,7 +438,8 @@ def test_what_a_run_could_not_see_reaches_upkeep_and_coverage(self): self.assertEqual(code, 0, out) upkeep = next(line for line in out.splitlines() if line.startswith('upkeep line:')) for phrase in ['feed gap in Kotlin blog (12 days)', 'Android blog feed silent for 72 days', - 'GitHub queried with curl, gh is not installed', '1 dependencies not checked', + 'GitHub queried with curl, unauthenticated (60 requests an hour) — install and authenticate gh', + '1 dependencies not checked', '2 build-facts problems']: self.assertIn(phrase, upkeep) for coverage_line in ['- com.example:sdk 1.0 — needs credentials [x:1]', From 8f5a56d7ca74e80f57e2a483ff24dc804a439f64 Mon Sep 17 00:00:00 2001 From: Dmitriy Gaiduk <5601396+DmitriyG1@users.noreply.github.com> Date: Tue, 17 Nov 2026 22:12:45 +0400 Subject: [PATCH 2/4] fix(scripts): fall back to curl when gh is not logged in github_client() chose gh whenever it was on PATH. A gh that is not logged in fails every `gh api` call, so the run got no GitHub data at all, while unauthenticated curl still has 60 requests an hour. Check `gh auth status --hostname github.com` (its exit code only; the output names the account and a masked token) and fall back to curl, saying why on the client status line. Co-Authored-By: Claude Opus 5.5 --- skills/android-upstream-audit/SKILL.md | 4 +-- .../scripts/releases.py | 25 +++++++++---- .../scripts/tests/test_releases.py | 35 +++++++++++++++++++ 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/skills/android-upstream-audit/SKILL.md b/skills/android-upstream-audit/SKILL.md index b712c13..b20b16a 100644 --- a/skills/android-upstream-audit/SKILL.md +++ b/skills/android-upstream-audit/SKILL.md @@ -234,8 +234,8 @@ serialization), for every pin with a suffix or on a pre-release, and for the `re `config.json`; head commits for its `commits` and for the upstream of each vendored artifact. A pin deps.dev links to no repository is printed as `PIN WITHOUT REPOSITORY`. AndroidX pins are not: AndroidX has no GitHub releases, so they share one `ANDROIDX PINS` line, and a pin -that matters is read on its group's release-notes page. Without `gh` -the script asks GitHub through curl and says so on its first line. +that matters is read on its group's release-notes page. Without `gh`, or with `gh` not logged +in, the script asks GitHub through curl and says so on its first line. What its output is for: diff --git a/skills/android-upstream-audit/scripts/releases.py b/skills/android-upstream-audit/scripts/releases.py index a816aac..a3787cd 100644 --- a/skills/android-upstream-audit/scripts/releases.py +++ b/skills/android-upstream-audit/scripts/releases.py @@ -20,8 +20,8 @@ 4. config.json against the project: a vendored artifact it does not name (UNCONFIGURED VENDORED), and an entry for a path the build no longer uses (STALE CONFIG). -GitHub is asked through `gh` when it is installed, otherwise through curl, unauthenticated -(60 requests an hour). `--out` writes releases.json for slice.py. +GitHub is asked through `gh` when it is installed and logged in, otherwise through curl, +unauthenticated (60 requests an hour). `--out` writes releases.json for slice.py. `--body` prints the notes of one release. Anything published on or after `--since` (default: the previous run's start) is marked NEW. """ @@ -57,7 +57,21 @@ def github_client(): - return 'gh' if shutil.which('gh') else 'curl' + """('gh', None) when gh is installed and logged in to github.com, else ('curl', why). + A gh that is not logged in fails every call, while curl still has 60 an hour. Only the exit + code of `gh auth status` is used: its output names the account and a masked token.""" + if not shutil.which('gh'): + return 'curl', ('gh is not installed; unauthenticated, 60 requests an hour; ' + 'install gh and run `gh auth login` for more') + try: + r = subprocess.run(['gh', 'auth', 'status', '--hostname', 'github.com'], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=30) + except (OSError, subprocess.TimeoutExpired): + return 'curl', '`gh auth status` failed; unauthenticated, 60 requests an hour' + if r.returncode != 0: + return 'curl', ('gh is installed but not logged in; unauthenticated, 60 requests an hour; ' + 'run `gh auth login` for more') + return 'gh', None def github(path, client): @@ -415,7 +429,7 @@ def main(): p.add_argument('--since') p.add_argument('--body', metavar='OWNER/REPO@TAG', help='print the notes of one GitHub release') args = p.parse_args() - client = github_client() + client, why = github_client() if args.body: repo, _, tag = args.body.partition('@') @@ -433,8 +447,7 @@ def main(): if client == 'gh': print('## GitHub API client: gh') else: - print('## GitHub API client: curl — gh is not installed; unauthenticated, 60 requests an hour; ' - 'install and authenticate gh for more') + print(f'## GitHub API client: curl — {why}') checked = [e for e in entries if e['version']] unique = sorted({e['coord'] for e in checked}) diff --git a/skills/android-upstream-audit/scripts/tests/test_releases.py b/skills/android-upstream-audit/scripts/tests/test_releases.py index f7a4d08..dfaba3c 100644 --- a/skills/android-upstream-audit/scripts/tests/test_releases.py +++ b/skills/android-upstream-audit/scripts/tests/test_releases.py @@ -1,6 +1,7 @@ """releases.py: dependency entries, version comparison, failed calls.""" import json import os +import subprocess import tempfile import unittest from unittest import mock @@ -272,6 +273,40 @@ def test_github_through_curl_without_gh(self): self.assertEqual(calls[0][0], 'https://api.github.com/repos/google/ksp/releases?per_page=5') self.assertIn('Accept: application/vnd.github+json', calls[0][1]) + def test_gh_is_used_only_when_it_is_logged_in(self): + calls = [] + + def auth_status(returncode): + def run(cmd, **kwargs): + calls.append((cmd, kwargs)) + if returncode is None: + raise subprocess.TimeoutExpired(cmd, kwargs.get('timeout')) + return subprocess.CompletedProcess(cmd, returncode) + return run + + with mock.patch.object(releases.shutil, 'which', return_value=None): + client, why = releases.github_client() + self.assertEqual((client, calls), ('curl', [])) + self.assertIn('gh is not installed', why) + + for returncode, expected, reason in [(0, 'gh', None), (1, 'curl', 'gh is installed but not logged in'), + (None, 'curl', '`gh auth status` failed')]: + with self.subTest(returncode=returncode): + calls.clear() + with mock.patch.object(releases.shutil, 'which', return_value='/usr/bin/gh'), \ + mock.patch.object(releases.subprocess, 'run', auth_status(returncode)): + client, why = releases.github_client() + self.assertEqual(client, expected) + if reason: + self.assertIn(reason, why) + self.assertIn('60 requests an hour', why) + else: + self.assertIsNone(why) + cmd, kwargs = calls[0] + self.assertEqual(cmd, ['gh', 'auth', 'status', '--hostname', 'github.com']) + # Its output names the account and a masked token: never read, never printed. + self.assertEqual((kwargs['stdout'], kwargs['stderr']), (subprocess.DEVNULL, subprocess.DEVNULL)) + def test_curl_sends_no_authorization_even_with_github_token(self): calls = [] fake_curl = lambda url, path=None, headers=None: calls.append(headers) or '[]' # noqa: E731 From d132c370aa1a1adb6af9d2a72d8aea3925674ee7 Mon Sep 17 00:00:00 2001 From: Dmitriy Gaiduk <5601396+DmitriyG1@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:29:48 +0400 Subject: [PATCH 3/4] docs(docs): describe gh as the only authenticated github access The skill no longer reads GITHUB_TOKEN. Say that gh, installed and authenticated, gives authenticated requests, and that without it the audit asks GitHub unauthenticated (60 requests an hour) and the report says so. Drop the note about a future version. Co-Authored-By: Claude Opus 5.5 --- README.md | 18 +++++++++--------- skills/android-upstream-audit/README.md | 10 ++++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a4202c3..77f49d1 100644 --- a/README.md +++ b/README.md @@ -120,17 +120,17 @@ people, never by the audit. ### GitHub access -GitHub allows 60 unauthenticated API requests an hour; a large project can need more. +GitHub allows 60 unauthenticated API requests an hour. That is usually enough for a run; a +large project, or several runs an hour from one network, can need more. -- **`gh` installed** — requests go through `gh api`, authenticated however you logged in - (`gh auth login`). The audit never sees the token. -- **No `gh`** — requests go through `curl`. If the `GITHUB_TOKEN` environment variable is set, - the audit reads it and sends it **only** to `api.github.com` as the `Authorization` header; it - is never written to a file or a report. Without it, requests are unauthenticated and the report - says so. +- **`gh` installed and logged in** — requests go through `gh api`, authenticated however you + logged in (`gh auth login`). The audit never sees the token. +- **No `gh`, or `gh` not logged in** — requests go through `curl`, unauthenticated: 60 requests + an hour. The report says so. -Installing and authenticating `gh` is the recommended way. A future version will stop reading -`GITHUB_TOKEN` and use `gh` as the only authenticated path. +Installing and authenticating `gh` is the recommended way. The audit never reads a token itself; +`gh` reads `GH_TOKEN` / `GITHUB_TOKEN` on its own, so a CI job with only a token gets +authenticated requests by installing `gh`. ## Things to know diff --git a/skills/android-upstream-audit/README.md b/skills/android-upstream-audit/README.md index a7efbcc..e7ffad7 100644 --- a/skills/android-upstream-audit/README.md +++ b/skills/android-upstream-audit/README.md @@ -22,8 +22,9 @@ with `cases.md`, `slice-format.md` and `digest.md` read at the step that needs t - **A git checkout** with an `origin` remote that has the base branch. - **Python 3.9 or later**, standard library only (the `python3` of macOS works), plus `curl` and `git`. -- **`gh`, recommended.** Without it the GitHub API is asked through curl: 60 requests an - hour, or more with `GITHUB_TOKEN` set. The report then says so in the upkeep line. +- **`gh`, recommended.** Install it and run `gh auth login` for authenticated requests. Without + it, or with `gh` not logged in, the GitHub API is asked through curl, unauthenticated: 60 requests an hour, usually enough + for a run; a large project can need more. The report then says so in the upkeep line. - Network access to `api.deps.dev`, `api.github.com`, the project's Maven repositories and the documentation sites. @@ -138,8 +139,9 @@ decisions.txt is written only by people, config.json only by --init; a run reads ## The scripts All in `scripts/`, standard library Python plus `curl` and `git`. `gh` is used for the GitHub -API when installed; without it the scripts use curl, unauthenticated (60 requests an hour, -enough for a run) or with `GITHUB_TOKEN`, and the digest's upkeep line says so. +API when installed, authenticated however `gh` is; without it the scripts use curl, +unauthenticated (60 requests an hour, usually enough for a run; a large project can need more), +and the digest's upkeep line says so. | Script | Role | What it does | |---|---|---| From e00c73a27f827ca87dfe37c38e5e4fcd302dca57 Mon Sep 17 00:00:00 2001 From: Dmitriy Gaiduk <5601396+DmitriyG1@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:30:06 +0400 Subject: [PATCH 4/4] chore(release): 1.1.0 Co-Authored-By: Claude Opus 5.5 --- .claude-plugin/plugin.json | 2 +- CHANGELOG.md | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index d8ded0d..10e9b0c 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "android-upstream-audit", - "version": "1.0.0", + "version": "1.1.0", "description": "Manually started audit of an Android project's Kotlin/Android toolchain against what was published upstream: Kotlin, AGP, Google Play requirements, Android API levels, AndroidX and Jetpack Compose.", "author": { "name": "KODE LLC", diff --git a/CHANGELOG.md b/CHANGELOG.md index 917c345..b4a2754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,15 @@ All notable changes to this plugin. Versions follow [Semantic Versioning](https://semver.org): a major version means you have to act after updating, and that is said in the entry. +## 1.1.0 — 2026-11-17 + +- The skill no longer reads `GITHUB_TOKEN`. Install and authenticate `gh` (`gh auth login`) for + authenticated GitHub requests; `gh` reads `GH_TOKEN` / `GITHUB_TOKEN` itself. Without `gh` the + audit asks GitHub unauthenticated (60 requests an hour), and the report says so. +- `gh` installed but not logged in no longer fails every GitHub call: the audit falls back to + unauthenticated curl and says why. +- No format change; no `--init` needed after updating. + ## 1.0.0 — 2026-11-16 First public release as a Claude Code plugin.