Skip to content

Commit 5c07c2e

Browse files
locus313Patrick LewisCopilot
authored
feat: add github-increase-copilot-user-budget script (#63)
Lets an enterprise admin raise a single user's Copilot AI credit budget interactively (preset, custom, or absolute amount) or non-interactively, creating a user budget when only the Universal budget applies. Co-authored-by: Patrick Lewis <plewis@ontinue.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 79210b3 commit 5c07c2e

5 files changed

Lines changed: 474 additions & 1 deletion

File tree

‎GLOSSARY.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# GitHub API Scripts
2+
3+
Standalone automation scripts for administering GitHub organizations and enterprises, including Copilot billing.
4+
5+
## Copilot budgets
6+
7+
**AI credit budget**:
8+
A dollar-denominated monthly spending limit on Copilot AI credits, enforced by blocking further usage once reached.
9+
_Avoid_: Quota, cap
10+
11+
**Universal budget**:
12+
The AI credit budget that applies to every user in an enterprise unless overridden.
13+
_Avoid_: Default budget, global budget
14+
15+
**User budget**:
16+
An AI credit budget set for one individual user that overrides the universal budget for that user.
17+
_Avoid_: Override, personal budget
18+
19+
**Effective budget**:
20+
The AI credit budget that currently applies to a user, whether universal or user-specific.
21+
_Avoid_: Current limit
22+
23+
**Budget increase**:
24+
Raising a user's effective budget by a dollar amount, or to an absolute dollar amount.
25+
_Avoid_: Top-up, bump

‎README.md‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Each script is a self-contained utility designed for a specific task. Navigate t
141141
### Folder Layout (Domain-Based)
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`
144-
- `enterprise/`: `github-add-enterprise-team-read-permissions`, `github-dockerfile-discovery`, `github-get-consumed-licenses`, `github-get-public-repos`, `github-install-enterprise-app`
144+
- `enterprise/`: `github-add-enterprise-team-read-permissions`, `github-dockerfile-discovery`, `github-get-consumed-licenses`, `github-get-public-repos`, `github-increase-copilot-user-budget`, `github-install-enterprise-app`
145145
- `reporting/`: `github-monthly-issues-report`, `github-repo-permissions-report`, `github-copilot-report`, `github-copilot-budget-advisor`
146146
- `personal/`: `github-organize-stars`
147147

@@ -742,6 +742,48 @@ Total seats purchased: 200
742742
743743
---
744744

745+
### Increase Copilot User Budget
746+
747+
**Script:** `enterprise/github-increase-copilot-user-budget/github-increase-copilot-user-budget.sh`
748+
749+
Raises the Copilot AI credit budget for one enterprise user. The script shows the user's effective budget and consumption, then offers +$50, +$100, +$150, +$200 and +$250 presets, a custom increase, or an absolute amount. After confirmation it updates the user's own AI credit budget, or creates one when the user is only covered by the Universal budget.
750+
751+
**Required variables:**
752+
```bash
753+
export GITHUB_ENTERPRISE="your-enterprise-slug"
754+
755+
# GitHub auth — use one of:
756+
export GITHUB_TOKEN=ghp_yourtoken # PAT with manage_billing:enterprise scope
757+
# OR: token is resolved automatically from an active gh auth session with the required scope
758+
```
759+
760+
**Usage:**
761+
```bash
762+
cd enterprise/github-increase-copilot-user-budget
763+
764+
./github-increase-copilot-user-budget.sh -u octocat
765+
./github-increase-copilot-user-budget.sh -u octocat --increase 100 --expires 2026-12-31 -y
766+
./github-increase-copilot-user-budget.sh -u octocat --amount 400 --dry-run
767+
```
768+
769+
**Options:**
770+
771+
| Flag | Description | Default |
772+
|------|-------------|---------|
773+
| `-e, --enterprise SLUG` | GitHub Enterprise slug (or `$GITHUB_ENTERPRISE`) | — |
774+
| `-u, --user LOGIN` | GitHub username to update (or `$TARGET_USER`); prompted if omitted | — |
775+
| `--increase N` | Raise the limit by N whole dollars, skipping the menu | — |
776+
| `--amount N` | Set the limit to N whole dollars, skipping the menu | — |
777+
| `--expires DATE` | Expire the user budget on `YYYY-MM-DD` | none |
778+
| `--allow-decrease` | Permit a new limit at or below the current limit | off |
779+
| `--dry-run` | Show the planned change without applying it | off |
780+
| `-y, --yes` | Skip the confirmation prompt | off |
781+
782+
> [!NOTE]
783+
> Limits are whole dollars. Without `--increase` or `--amount`, prompts require a terminal. An ambiguous match (more than one AI credit budget for the user) aborts without changes.
784+
785+
---
786+
745787
### Install Enterprise App
746788

747789
**Script:** `enterprise/github-install-enterprise-app/github-install-enterprise-app.sh`
@@ -1016,6 +1058,7 @@ Each script is published as a **composite action**, so you can reference it dire
10161058
| `enterprise/github-add-enterprise-team-read-permissions` | Grant read permissions to an enterprise team across all orgs |
10171059
| `enterprise/github-dockerfile-discovery` | Discover Dockerfiles and extract `FROM` instructions across all enterprise orgs |
10181060
| `enterprise/github-get-consumed-licenses` | Report Enterprise consumed licence seat counts |
1061+
| `enterprise/github-increase-copilot-user-budget` | Raise the Copilot AI credit budget for a single enterprise user |
10191062
| `enterprise/github-get-public-repos` | List all public repositories across all Enterprise orgs |
10201063
| `enterprise/github-install-enterprise-app` | Install an enterprise-owned GitHub App into an org (JWT flow) |
10211064
| `org-admin/github-add-repo-collaborators-by-pattern` | Add collaborators to repositories matching a name pattern |
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: 'Increase Copilot User Budget'
2+
description: 'Raise the GitHub Copilot AI credit budget for a single enterprise user'
3+
inputs:
4+
github-token:
5+
description: 'PAT with manage_billing:enterprise scope. Cannot be the built-in GITHUB_TOKEN.'
6+
required: true
7+
enterprise:
8+
description: 'GitHub Enterprise slug'
9+
required: true
10+
user:
11+
description: 'GitHub username whose budget is raised'
12+
required: true
13+
increase:
14+
description: 'Whole dollars to add to the current limit (use this or amount)'
15+
required: false
16+
default: ''
17+
amount:
18+
description: 'Absolute new limit in whole dollars (use this or increase)'
19+
required: false
20+
default: ''
21+
expires:
22+
description: 'Optional expiry date for the user budget (YYYY-MM-DD)'
23+
required: false
24+
default: ''
25+
allow-decrease:
26+
description: 'Permit a new limit at or below the current limit'
27+
required: false
28+
default: 'false'
29+
dry-run:
30+
description: 'Show the planned change without applying it'
31+
required: false
32+
default: 'false'
33+
api-url-prefix:
34+
description: 'GitHub API base URL'
35+
required: false
36+
default: 'https://api.github.com'
37+
runs:
38+
using: composite
39+
steps:
40+
- name: Increase Copilot user budget
41+
shell: bash
42+
env:
43+
GITHUB_TOKEN: ${{ inputs.github-token }}
44+
GITHUB_ENTERPRISE: ${{ inputs.enterprise }}
45+
TARGET_USER: ${{ inputs.user }}
46+
API_URL_PREFIX: ${{ inputs.api-url-prefix }}
47+
INPUT_INCREASE: ${{ inputs.increase }}
48+
INPUT_AMOUNT: ${{ inputs.amount }}
49+
INPUT_EXPIRES: ${{ inputs.expires }}
50+
INPUT_ALLOW_DECREASE: ${{ inputs.allow-decrease }}
51+
INPUT_DRY_RUN: ${{ inputs.dry-run }}
52+
run: |
53+
ARGS=(--yes)
54+
[[ -n "${INPUT_INCREASE}" ]] && ARGS+=(--increase "${INPUT_INCREASE}")
55+
[[ -n "${INPUT_AMOUNT}" ]] && ARGS+=(--amount "${INPUT_AMOUNT}")
56+
[[ -n "${INPUT_EXPIRES}" ]] && ARGS+=(--expires "${INPUT_EXPIRES}")
57+
[[ "${INPUT_ALLOW_DECREASE}" == "true" ]] && ARGS+=(--allow-decrease)
58+
[[ "${INPUT_DRY_RUN}" == "true" ]] && ARGS+=(--dry-run)
59+
"${{ github.action_path }}/github-increase-copilot-user-budget.sh" "${ARGS[@]}"

0 commit comments

Comments
 (0)