From 3c2cfbd16e621cd03ffe0c08a0c4036ea21964d3 Mon Sep 17 00:00:00 2001 From: kgrizz-git <216068303+kgrizz-git@users.noreply.github.com> Date: Tue, 17 Nov 2026 22:58:02 -0500 Subject: [PATCH 1/3] Place CodeQL suppression comments on the flagged line AlertSuppression.ql covers an alert only when the comment ends on the line immediately before the reported line. Every existing comment sits above a multi-line print() call while the alert lands on the f-string inside it, so none of the six comments suppressed anything; 10 alerts are open and 99 have accumulated for this query. Move the comments onto the flagged line, add the missing ones for report_sources and report_products, and leave the already-correct placements alone. Comments only, no behavior change (the commit hook also re-sorts two pre-existing unsorted imports in report_products). --- src/github_usage/report_products.py | 8 ++++++-- src/github_usage/report_sources.py | 4 ++++ src/github_usage/report_summary.py | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/github_usage/report_products.py b/src/github_usage/report_products.py index 17d44aa..32958f5 100644 --- a/src/github_usage/report_products.py +++ b/src/github_usage/report_products.py @@ -10,8 +10,8 @@ copilot_model_detail_line, copilot_usage_summary_lines, ) -from .report_helpers import fmt_price, gb_hours_to_avg_mb from .report_data import get_copilot_usage +from .report_helpers import fmt_price, gb_hours_to_avg_mb from .report_sources import print_premium_request_model_breakdown from .terminal import print_section @@ -75,6 +75,7 @@ def _print_copilot_by_model_block(copilot: dict, premium_by_model: dict | None) for model, data in sorted( by_model.items(), key=lambda x: x[1].get("requests", 0), reverse=True ): + # codeql[py/clear-text-logging-sensitive-data] print(copilot_model_detail_line(model, data, metering="ai_credits")) print() return @@ -89,9 +90,12 @@ def _print_copilot_by_model_block(copilot: dict, premium_by_model: dict | None) for model, data in sorted( by_model.items(), key=lambda x: x[1].get("requests", 0), reverse=True ): + # codeql[py/clear-text-logging-sensitive-data] print(f" {model}:") + # codeql[py/clear-text-logging-sensitive-data] print(f" Total requests: {data.get('requests', 0):.2f}") print( + # codeql[py/clear-text-logging-sensitive-data] f" Gross: {fmt_price(data.get('gross', 0))} | " f"Discount: {fmt_price(data.get('discount', 0))} | " f"Net: {fmt_price(data.get('net', 0))}" @@ -238,8 +242,8 @@ def show_monthly_costs(repo_data, username, api): if total_discount > 0: savings_pct = (total_discount / total_gross * 100) if total_gross > 0 else 0 - # codeql[py/clear-text-logging-sensitive-data] print( + # codeql[py/clear-text-logging-sensitive-data] f" You're saving {fmt_price(total_discount)} ({savings_pct:.1f}% discount) this month!" ) print() diff --git a/src/github_usage/report_sources.py b/src/github_usage/report_sources.py index b6fbd84..d9cb461 100644 --- a/src/github_usage/report_sources.py +++ b/src/github_usage/report_sources.py @@ -24,9 +24,12 @@ def print_premium_request_model_breakdown(premium_by_model: dict) -> None: for model, data in sorted( premium_by_model.items(), key=lambda x: x[1]["total_requests"], reverse=True ): + # codeql[py/clear-text-logging-sensitive-data] print(f" {model}:") + # codeql[py/clear-text-logging-sensitive-data] print(f" Total requests: {data['total_requests']:.2f}") print( + # codeql[py/clear-text-logging-sensitive-data] f" Gross: {fmt_price(data['total_gross'])} | " f"Discount: {fmt_price(data['total_discount'])} | " f"Net: {fmt_price(data['total_net'])}" @@ -35,6 +38,7 @@ def print_premium_request_model_breakdown(premium_by_model: dict) -> None: sku = item.get("sku", "unknown") qty = item.get("grossQuantity", 0) price = item.get("pricePerUnit", 0) + # codeql[py/clear-text-logging-sensitive-data] print(f" {sku}: {qty:.2f} @ {fmt_price(price)}/ea") print() diff --git a/src/github_usage/report_summary.py b/src/github_usage/report_summary.py index efd65d7..a133fd2 100644 --- a/src/github_usage/report_summary.py +++ b/src/github_usage/report_summary.py @@ -265,6 +265,7 @@ def _print_copilot_ai_credits_by_model(copilot: dict | None) -> None: by_model.items(), key=lambda x: x[1].get("requests", 0), reverse=True ): qty = float(data.get("requests", 0.0)) + # codeql[py/clear-text-logging-sensitive-data] print(f" {model:<30} {qty:>10.2f} credits (gross qty)") print() @@ -285,8 +286,8 @@ def _print_copilot_premium_requests_by_model(premium_by_model) -> None: if pp > 0: price = pp break - # codeql[py/clear-text-logging-sensitive-data] print( + # codeql[py/clear-text-logging-sensitive-data] f" {model:<30} {data['total_requests']:>10.0f} reqs @ {fmt_price(price)}/req = {fmt_price(data['total_net'])}" ) print() From dfb7ec3a4252df90754cb979e083537007b9138e Mon Sep 17 00:00:00 2001 From: kgrizz-git <216068303+kgrizz-git@users.noreply.github.com> Date: Tue, 17 Nov 2026 23:06:25 -0500 Subject: [PATCH 2/3] List the full token permissions in setup help docs/setup.md requires Actions: Read-only (and Contents: Read-only for release inventory) on a fine-grained token, but the interactive setup text only mentioned Metadata and Plan read-only, and omitted 'user' for classic tokens. Following that text leaves private-repo Actions data inaccessible: artifact storage reports skipped (403 ...) and workflow breakdown is unavailable. Align both the option-7 help and the GH_USAGE_TOKEN description with the docs, and note the change in the changelog. --- CHANGELOG.md | 1 + src/github_usage/setup_ci.py | 7 ++++--- src/github_usage/setup_wizard.py | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3881109..337f2d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ This project follows the structure from Keep a Changelog and intends to use Sema ### Changed +- **Setup help lists the full token permissions:** the interactive secrets help and the `GH_USAGE_TOKEN` description now match `docs/setup.md` — fine-grained tokens need `Metadata: Read-only`, `Actions: Read-only`, `Contents: Read-only` for release inventory, and the account permission `Plan: Read-only`; classic tokens need `repo` + `user`. The old text omitted Actions and Contents (and `user` for classic tokens), so following it produced `skipped (403 …)` repos in artifact storage and workflow breakdown. - **Email report repo cap in GitHub Actions:** raised the scheduled workflow's `--max-repos` from 50 to 100 so repo-level sections cover more of the account (aligning with the CLI/config default). Repos beyond the previous cap were excluded from the private/public Actions split and top-repository rankings; the cap still applies above 100 repos, and repo-level sections now make roughly twice as many REST calls (about 210 of the 5,000/hr core quota with consumers + artifact storage). - **Shorter README:** focused the landing page on getting started and scheduled delivery; moved setup, email configuration, report/export reference, runs/drift, and development details into linked user guides under `docs/`. diff --git a/src/github_usage/setup_ci.py b/src/github_usage/setup_ci.py index 5907d04..7fca60b 100644 --- a/src/github_usage/setup_ci.py +++ b/src/github_usage/setup_ci.py @@ -20,9 +20,10 @@ ( "GH_USAGE_TOKEN", ( - "GitHub PAT that can read your personal repos and billing " - "(classic: `repo` scope; fine-grained: `Metadata: Read-only` + " - "`Plan: Read-only` on your user account)" + "GitHub PAT that can read your personal repos, billing, and Actions " + "data (classic: `repo` + `user`; fine-grained: `Metadata: Read-only`, " + "`Actions: Read-only`, `Contents: Read-only` for release inventory, " + "plus `Plan: Read-only` on your user account)" ), ), ("RESEND_API_KEY", "Resend API key"), diff --git a/src/github_usage/setup_wizard.py b/src/github_usage/setup_wizard.py index b3bbc4f..f1d2b88 100644 --- a/src/github_usage/setup_wizard.py +++ b/src/github_usage/setup_wizard.py @@ -349,9 +349,11 @@ def _github_actions_only(paths: SetupPaths) -> int: ( "Push secrets to this repository with `gh secret set` so the scheduled " "GitHub Actions workflow can send the report. The GitHub token must be " - "able to read your personal repos and user-billing endpoints " - "(classic `repo`, or fine-grained with `Metadata: Read-only` and the " - "account permission `Plan: Read-only`). Requires `gh` CLI auth." + "able to read your personal repos, user-billing endpoints, and Actions " + "data for the report sections you enable (classic `repo` + `user`, or " + "fine-grained with `Metadata: Read-only`, `Actions: Read-only`, the " + "account permission `Plan: Read-only`, and `Contents: Read-only` for " + "release inventory). Requires `gh` CLI auth." ), _ci_only, ), From b18a934179e348e2452a2b8bb9497e58aa4984fb Mon Sep 17 00:00:00 2001 From: kgrizz-git <216068303+kgrizz-git@users.noreply.github.com> Date: Tue, 17 Nov 2026 23:36:24 -0500 Subject: [PATCH 3/3] Mention repository selection in the token help text CodeRabbit on PR #42: the fine-grained guidance listed permissions but not the repository-selection step, so a user who grants them and selects only some repositories gets reports limited to those repositories. Both the option-7 help and the GH_USAGE_TOKEN description now say to select all repositories for account-wide coverage. Also record the report_products.py size overrun (504 lines) in TO_DO.md rather than splitting the module in a comment-placement change. --- CHANGELOG.md | 2 +- TO_DO.md | 1 + src/github_usage/setup_ci.py | 3 ++- src/github_usage/setup_wizard.py | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 337f2d2..c42c712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ This project follows the structure from Keep a Changelog and intends to use Sema ### Changed -- **Setup help lists the full token permissions:** the interactive secrets help and the `GH_USAGE_TOKEN` description now match `docs/setup.md` — fine-grained tokens need `Metadata: Read-only`, `Actions: Read-only`, `Contents: Read-only` for release inventory, and the account permission `Plan: Read-only`; classic tokens need `repo` + `user`. The old text omitted Actions and Contents (and `user` for classic tokens), so following it produced `skipped (403 …)` repos in artifact storage and workflow breakdown. +- **Setup help lists the full token permissions:** the interactive secrets help and the `GH_USAGE_TOKEN` description now match `docs/setup.md` — fine-grained tokens need `Metadata: Read-only`, `Actions: Read-only`, `Contents: Read-only` for release inventory, and the account permission `Plan: Read-only`, with all repositories selected for account-wide coverage; classic tokens need `repo` + `user`. The old text omitted Actions, Contents, the repository selection step, and `user` for classic tokens, so following it produced `skipped (403 …)` repos in artifact storage and workflow breakdown. - **Email report repo cap in GitHub Actions:** raised the scheduled workflow's `--max-repos` from 50 to 100 so repo-level sections cover more of the account (aligning with the CLI/config default). Repos beyond the previous cap were excluded from the private/public Actions split and top-repository rankings; the cap still applies above 100 repos, and repo-level sections now make roughly twice as many REST calls (about 210 of the 5,000/hr core quota with consumers + artifact storage). - **Shorter README:** focused the landing page on getting started and scheduled delivery; moved setup, email configuration, report/export reference, runs/drift, and development details into linked user guides under `docs/`. diff --git a/TO_DO.md b/TO_DO.md index f8ede70..74a823c 100644 --- a/TO_DO.md +++ b/TO_DO.md @@ -28,6 +28,7 @@ ## Code Health +- [ ] Split `src/github_usage/report_products.py` (504 lines, at the 500-line soft limit in `scripts/check-sizes`; `AGENTS.md` asks for extraction from ~400). The CodeQL suppression comments added in PR #42 took it from 500 to 504, and the check is advisory so nothing fails. Extract the legacy Copilot/product print blocks into a submodule rather than adding more to it. - [ ] Refactor `src/github_usage/setup_config.py` (507 lines, over the 500-line limit per `scripts/check-sizes`). Extract a focused submodule — e.g. profile schema/loading (`load_report_profiles`, `find_profile`, `ensure_profiles`, `_default_profile`) and/or the TOML writer helpers (`_emit_*_block`, `write_config`) — to bring the file back under the threshold. Also watch `setup_wizard.py` (461 lines) and the `_manage_profiles()`/`_run_email_report()` functions, which are approaching their limits. - [ ] Rename internal `legacy_*` modules/symbols to “local full report” naming (`legacy_report_data` → e.g. `local_report_data`, cache `kind="legacy"`, CLI/TUI internals, tests). User-facing copy already says “local full report”; this is the code rename. Keep a thin `legacy` compatibility shim if external imports still need it. - [ ] Extract the remaining API-usage tracking orchestration from the report builders (`report_data.py` 487 lines, `legacy_report_data.py` 395 lines — both at/over the early-extraction threshold). Keep the merge math in `report_api_usage.py`; move section-fetch orchestration (`_fetch_sections`, `_fetch_legacy_billing_sections`) into a focused submodule so the builders stay thin. Flagged in review on PR #39; deferred to keep that PR's diff small. diff --git a/src/github_usage/setup_ci.py b/src/github_usage/setup_ci.py index 7fca60b..a91d477 100644 --- a/src/github_usage/setup_ci.py +++ b/src/github_usage/setup_ci.py @@ -23,7 +23,8 @@ "GitHub PAT that can read your personal repos, billing, and Actions " "data (classic: `repo` + `user`; fine-grained: `Metadata: Read-only`, " "`Actions: Read-only`, `Contents: Read-only` for release inventory, " - "plus `Plan: Read-only` on your user account)" + "plus `Plan: Read-only` on your user account; select all repositories " + "for account-wide coverage)" ), ), ("RESEND_API_KEY", "Resend API key"), diff --git a/src/github_usage/setup_wizard.py b/src/github_usage/setup_wizard.py index f1d2b88..ae399e9 100644 --- a/src/github_usage/setup_wizard.py +++ b/src/github_usage/setup_wizard.py @@ -353,7 +353,8 @@ def _github_actions_only(paths: SetupPaths) -> int: "data for the report sections you enable (classic `repo` + `user`, or " "fine-grained with `Metadata: Read-only`, `Actions: Read-only`, the " "account permission `Plan: Read-only`, and `Contents: Read-only` for " - "release inventory). Requires `gh` CLI auth." + "release inventory; select all repositories for account-wide " + "coverage). Requires `gh` CLI auth." ), _ci_only, ),