Skip to content

refactor: simplify seat probe diagnostics in copilot-report#50

Merged
locus313 merged 1 commit into
mainfrom
refactor/copilot-report-simplify-seat-probe-diagnostics
Jul 14, 2026
Merged

refactor: simplify seat probe diagnostics in copilot-report#50
locus313 merged 1 commit into
mainfrom
refactor/copilot-report-simplify-seat-probe-diagnostics

Conversation

@locus313

Copy link
Copy Markdown
Owner

Description

Ponytail audit cleanup of the zero-seat probe block added to github-copilot-report.sh. The block was correct in purpose but had two unnecessary complexity hotspots.

Changes

  • New script: <domain>/github-<name>/github-<name>.sh
  • Modified: lib/github-common.sh
  • Other: reporting/github-copilot-report/github-copilot-report.sh

Removed dead 403 branch — the code's own comment documented that GitHub returns 404 (not 403) on billing endpoints when manage_billing:enterprise scope is absent. The 403 case would never fire.

Flattened nested 404 scope-check — replaced a 3-level nested if/else (22 lines, repeated error text) with a single if/else (8 lines) that preserves all actionable guidance.

Initialised declare -A with =() — fixes empty-array expansion under bash 5.3 for _GRAPH_CACHE, USER_CREDITS_USED, USER_MODEL_CREDITS, _ALL_MODELS_SET, DEPT_USERS, DEPT_CREDITS.

Added empty-string guard in department loop — bash 5.3 emits a single empty-string element when iterating ${!assoc[@]} on an empty associative array; the [[ -z "$dept" ]] && continue guard prevents a blank row in the summary table.

Net diff: ~22 lines removed.

How to test

export GITHUB_TOKEN=ghp_REDACTED
export GITHUB_ENTERPRISE=test-enterprise
./reporting/github-copilot-report/github-copilot-report.sh

Expected: same output as before for enterprises with seats. For enterprises with 0 seats, the 404 error message now points directly to the missing scope or wrong slug without repeating itself.

Checklist

  • set -euo pipefail is the first executable line after the # === header
  • Script sources lib/github-common.sh via SCRIPT_DIR
  • All required env vars validated with require_env_var
  • Token validated with validate_github_token (or validate_token for secondary tokens)
  • User-supplied slugs validated with validate_slug
  • sleep added between repo-level operations to respect rate limits
  • README.md updated with the new/changed script (env var table + usage example) — no user-visible behaviour change, no README update needed
  • Script header comment matches README documentation
  • Tested on a non-production org before production
  • shellcheck passes (shellcheck --severity=warning --exclude=SC2034,SC1091 --shell=bash)

Remove dead 403 branch (GitHub returns 404, not 403, on billing
endpoints when manage_billing:enterprise scope is absent — documented
in the code itself). Flatten the nested 404 scope-check into a
single if/else, eliminating repeated error messages and reducing the
block by ~22 lines while preserving all actionable guidance.

Also initialise all declare -A statements with =() to fix empty-array
expansion under bash 5.3, and add a guard for the empty-string element
that bash 5.3 emits when iterating ${!assoc[@]} on an empty array.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@locus313 locus313 merged commit aff647c into main Jul 14, 2026
1 check passed
@locus313 locus313 deleted the refactor/copilot-report-simplify-seat-probe-diagnostics branch July 14, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant