Skip to content

Commit c57bfc9

Browse files
author
Patrick Lewis
committed
feat: add Copilot Budget Advisor script and validation tests
1 parent 4c16db9 commit c57bfc9

4 files changed

Lines changed: 514 additions & 1 deletion

File tree

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Each script is a self-contained utility designed for a specific task. Navigate t
142142

143143
- `org-admin/`: `github-add-repo-collaborators-by-pattern`, `github-add-repo-permissions`, `github-archive-old-repos`, `github-auto-repo-creation`, `github-close-archived-repo-security-alerts`, `github-enable-issues`, `github-get-repo-list`, `github-import-repo`, `github-migrate-internal-repos-to-private`, `github-repo-from-template`
144144
- `enterprise/`: `github-add-enterprise-team-read-permissions`, `github-dockerfile-discovery`, `github-get-consumed-licenses`, `github-get-public-repos`, `github-install-enterprise-app`
145-
- `reporting/`: `github-monthly-issues-report`, `github-repo-permissions-report`, `github-copilot-report`
145+
- `reporting/`: `github-monthly-issues-report`, `github-repo-permissions-report`, `github-copilot-report`, `github-copilot-budget-advisor`
146146
- `personal/`: `github-organize-stars`
147147

148148
### Add Repository Permissions
@@ -628,6 +628,57 @@ az login # optional; needed only for Entra ID department enrichment
628628
629629
---
630630

631+
### Copilot Budget Advisor
632+
633+
**Script:** `reporting/github-copilot-budget-advisor/github-copilot-budget-advisor.sh`
634+
635+
Analyses per-user GitHub Copilot AI credit consumption over the last 30 days and recommends a Universal per-user budget limit. The recommendation is based on the 90th-percentile of actual usage, rounded up to the nearest 100 credits, so that ~90% of users can work without hitting the cap while outlier usage is still bounded.
636+
637+
**Prerequisites:**
638+
- **[curl](https://curl.se)** — HTTP client
639+
- **[jq](https://stedolan.github.io/jq)** — JSON processor
640+
- **[awk](https://www.gnu.org/software/gawk/)** — for statistical calculations (available by default on macOS and Linux)
641+
642+
**Required variables:**
643+
```bash
644+
export GITHUB_ENTERPRISE="your-enterprise-slug"
645+
646+
# GitHub auth — use one of:
647+
export GITHUB_TOKEN=ghp_yourtoken # PAT with read:enterprise and manage_billing:enterprise scopes
648+
# OR: token is resolved automatically from an active gh auth session with the required scopes
649+
```
650+
651+
**Usage:**
652+
```bash
653+
cd reporting/github-copilot-budget-advisor
654+
655+
./github-copilot-budget-advisor.sh -e YOUR-ENTERPRISE
656+
./github-copilot-budget-advisor.sh -e YOUR-ENTERPRISE --days 14
657+
```
658+
659+
**Options:**
660+
661+
| Flag | Description | Default |
662+
|------|-------------|---------|
663+
| `-e, --enterprise SLUG` | GitHub Enterprise slug (or `$GITHUB_ENTERPRISE`) ||
664+
| `--days N` | Look-back window in days (1–60) | `30` |
665+
666+
**What it does:**
667+
- Fetches all Copilot seats across the enterprise (deduplicated by user)
668+
- Fetches per-user AI credit consumption for the current billing month and, when the look-back window extends into it, the previous month (prorated by days)
669+
- Calculates usage distribution: P50, P75, P90, P95, and max
670+
- Recommends the P90 value rounded up to the nearest 100 as the Universal baseline budget
671+
- Lists the top consumers (users above P90) so you can decide whether to adjust the suggestion up or down
672+
- Shows the exact navigation path in GitHub to create the budget
673+
674+
> [!IMPORTANT]
675+
> Requires a PAT with `read:enterprise` and `manage_billing:enterprise` scopes. Set `GITHUB_TOKEN` before executing (or have an active `gh` auth session with those scopes).
676+
677+
> [!NOTE]
678+
> 1 AI credit ≈ $0.01 USD. Code completions are **not** billed in AI credits and are not included in this analysis. The budget tracks both included and additional (overage) usage.
679+
680+
---
681+
631682
### Get Consumed Licenses
632683

633684
**Script:** `enterprise/github-get-consumed-licenses/github-get-consumed-licenses.sh`
@@ -949,6 +1000,7 @@ Each script is published as a **composite action**, so you can reference it dire
9491000
| `reporting/github-monthly-issues-report` | Generate an HTML report of issues created within a date range |
9501001
| `reporting/github-repo-permissions-report` | Export repository collaborator/team permissions and branch-approval bypass actors to CSV |
9511002
| `reporting/github-copilot-report` | GitHub Copilot Enterprise licence and AI credit usage report, optionally enriched with Entra ID department data |
1003+
| `reporting/github-copilot-budget-advisor` | Analyse per-user Copilot AI credit consumption and recommend a Universal per-user budget limit |
9521004

9531005
---
9541006

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'Copilot Budget Advisor'
2+
description: 'Analyses per-user GitHub Copilot AI credit consumption over the last 30 days and recommends a Universal budget limit'
3+
inputs:
4+
github-token:
5+
description: 'PAT with read:enterprise and manage_billing:enterprise scopes. Cannot be the built-in GITHUB_TOKEN.'
6+
required: true
7+
enterprise:
8+
description: 'GitHub Enterprise slug'
9+
required: true
10+
days:
11+
description: 'Look-back window in days (1–60)'
12+
required: false
13+
default: '30'
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Analyse Copilot usage and suggest budget
18+
shell: bash
19+
env:
20+
GITHUB_TOKEN: ${{ inputs.github-token }}
21+
GITHUB_ENTERPRISE: ${{ inputs.enterprise }}
22+
run: |
23+
ARGS=()
24+
[[ -n "${{ inputs.days }}" ]] && ARGS+=(--days "${{ inputs.days }}")
25+
"${{ github.action_path }}/github-copilot-budget-advisor.sh" "${ARGS[@]}"

0 commit comments

Comments
 (0)