Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`, 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/`.

Expand Down
1 change: 1 addition & 0 deletions TO_DO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions src/github_usage/report_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
print(copilot_model_detail_line(model, data, metering="ai_credits"))
print()
return
Expand All @@ -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))}"
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/github_usage/report_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])}"
Expand All @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion src/github_usage/report_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions src/github_usage/setup_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
(
"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, "
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"plus `Plan: Read-only` on your user account; select all repositories "
"for account-wide coverage)"
),
),
("RESEND_API_KEY", "Resend API key"),
Expand Down
9 changes: 6 additions & 3 deletions src/github_usage/setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,12 @@ 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; select all repositories for account-wide "
"coverage). Requires `gh` CLI auth."
),
_ci_only,
),
Expand Down
Loading