Repository navigation
Add GitHub Copilot plugin #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adamkinniburgh
wants to merge
1
commit into
main
Choose a base branch
from
work/ak/github-copilot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| { | ||
| "steps": [ | ||
| { | ||
| "displayName": "Authenticate", | ||
| "dataStream": { "name": "currentUser" }, | ||
| "required": true, | ||
| "error": "Could not authenticate with GitHub. Check the personal access token and API URL.", | ||
| "success": "Authenticated with GitHub." | ||
| }, | ||
| { | ||
| "displayName": "Copilot seats", | ||
| "dataStream": { "name": "validationSeats" }, | ||
| "required": false, | ||
| "error": "Could not read Copilot seats. Check the account type and slug, that the account has Copilot Business or Enterprise, and that the token belongs to an organization owner (organizations), or an enterprise owner or billing manager (enterprises), with the manage_billing:copilot or read:org scope (read:enterprise for enterprises).", | ||
| "success": "Copilot seats are readable." | ||
| }, | ||
| { | ||
| "displayName": "Copilot usage metrics", | ||
| "dataStream": { "name": "validationUsageMetrics" }, | ||
| "required": false, | ||
| "error": "Could not read Copilot usage metrics. Check that the Copilot usage metrics policy is enabled and that the token has the read:org scope (manage_billing:copilot or read:enterprise for enterprises).", | ||
| "success": "Copilot usage metrics are readable." | ||
| }, | ||
| { | ||
| "displayName": "Billing", | ||
| "dataStream": { "name": "validationBilling" }, | ||
| "required": false, | ||
| "error": "Could not read AI credit usage. Check that the token owner is an owner or billing manager and, for enterprises, that the token has the manage_billing:enterprise scope.", | ||
| "success": "AI credit usage is readable." | ||
| }, | ||
| { | ||
| "displayName": "Token expiry", | ||
| "dataStream": { "name": "validationTokenExpiry" }, | ||
| "required": false, | ||
| "error": "The personal access token expires within 7 days. Check its expiration date in GitHub token settings.", | ||
| "success": "Token is not close to expiring." | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| [ | ||
| { | ||
| "name": "User", | ||
| "sourceType": "User", | ||
| "icon": "user", | ||
| "singular": "User", | ||
| "plural": "Users" | ||
| }, | ||
| { | ||
| "name": "Budget", | ||
| "sourceType": "Budget", | ||
| "icon": "wallet", | ||
| "singular": "Budget", | ||
| "plural": "Budgets" | ||
| }, | ||
| { | ||
| "name": "Cost Center", | ||
| "sourceType": "Cost Center", | ||
| "icon": "building", | ||
| "singular": "Cost Center", | ||
| "plural": "Cost Centers" | ||
| } | ||
| ] |
233 changes: 233 additions & 0 deletions
233
plugins/GitHubCopilot/v1/dataStreams/aiCreditUsage.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,233 @@ | ||
| { | ||
| "name": "aiCreditUsage", | ||
| "displayName": "AI Credit Usage", | ||
| "description": "AI credit (or legacy premium request) usage by model, one row per period, model and SKU, split into included and billed", | ||
| "tags": [ | ||
| "Billing", | ||
| "Cost", | ||
| "AI", | ||
| "Models" | ||
| ], | ||
| "baseDataSourceName": "httpRequestUnscoped", | ||
| "config": { | ||
| "httpMethod": "get", | ||
| "endpointPath": "/{{ dataSource.accountType === 'enterprise' ? 'enterprises' : 'organizations' }}/{{ dataSource.slug.trim() }}/settings/billing/{{ typeof meter !== 'undefined' && meter === 'premium_request' ? 'premium_request' : 'ai_credit' }}/usage", | ||
| "getArgs": [ | ||
| { | ||
| "key": "year", | ||
| "value": "{{ new Date(timeframe.start).getUTCFullYear() }}" | ||
| }, | ||
| { | ||
| "key": "month", | ||
| "value": "{{ new Date(timeframe.start).getUTCMonth() + 1 }}" | ||
| }, | ||
| { | ||
| "key": "day", | ||
| "value": "{{ timeframe.enum === 'last7days' ? new Date(timeframe.start).getUTCDate() : null }}" | ||
| }, | ||
| { | ||
| "key": "user", | ||
| "value": "{{ [].concat([].concat(typeof user !== 'undefined' && user || [])[0]?.name)[0] || null }}" | ||
| }, | ||
| { | ||
| "key": "model", | ||
| "value": "{{ typeof model !== 'undefined' && model ? model.trim() : null }}" | ||
| }, | ||
| { | ||
| "key": "organization", | ||
| "value": "{{ dataSource.accountType === 'enterprise' && typeof organization !== 'undefined' && organization ? organization.trim() : null }}" | ||
| }, | ||
| { | ||
| "key": "cost_center_id", | ||
| "value": "{{ dataSource.accountType === 'enterprise' ? ([].concat([].concat(typeof costCenter !== 'undefined' && costCenter || [])[0]?.rawId)[0] || null) : null }}" | ||
| } | ||
| ], | ||
| "paging": { | ||
| "mode": "nextUrl", | ||
| "in": { | ||
| "realm": "payload", | ||
| "path": "nextUrl" | ||
| } | ||
| }, | ||
| "postRequestScript": "aiCreditUsage.js" | ||
| }, | ||
| "ui": [ | ||
| { | ||
| "type": "switch", | ||
| "name": "meter", | ||
| "label": "Meter", | ||
| "options": [ | ||
| { | ||
| "value": "ai_credit", | ||
| "label": "AI credits" | ||
| }, | ||
| { | ||
| "value": "premium_request", | ||
| "label": "Premium requests (legacy)" | ||
| } | ||
| ], | ||
| "defaultValue": "ai_credit" | ||
| }, | ||
| { | ||
| "type": "objects", | ||
| "name": "user", | ||
| "label": "User (optional)", | ||
| "matches": { | ||
| "sourceType": { | ||
| "type": "oneOf", | ||
| "values": [ | ||
| "User" | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "type": "text", | ||
| "name": "model", | ||
| "label": "Model (optional)", | ||
| "placeholder": "gpt-5", | ||
| "help": "Only include usage for this model" | ||
| }, | ||
| { | ||
| "type": "objects", | ||
| "name": "costCenter", | ||
| "label": "Cost center (optional)", | ||
| "help": "Enterprise accounts only", | ||
| "matches": { | ||
| "sourceType": { | ||
| "type": "oneOf", | ||
| "values": [ | ||
| "Cost Center" | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "type": "text", | ||
| "name": "organization", | ||
| "label": "Organization (optional)", | ||
| "placeholder": "octo-org", | ||
| "help": "Enterprise accounts only" | ||
| } | ||
| ], | ||
| "matches": "none", | ||
| "metadata": [ | ||
| { | ||
| "name": "period", | ||
| "displayName": "Period", | ||
| "shape": "date", | ||
| "role": "timestamp" | ||
| }, | ||
| { | ||
| "name": "product", | ||
| "displayName": "Product", | ||
| "shape": "string" | ||
| }, | ||
| { | ||
| "name": "sku", | ||
| "displayName": "SKU", | ||
| "shape": "string" | ||
| }, | ||
| { | ||
| "name": "model", | ||
| "displayName": "Model", | ||
| "shape": "string", | ||
| "role": "label" | ||
| }, | ||
| { | ||
| "name": "unitType", | ||
| "displayName": "Unit type", | ||
| "shape": "string" | ||
| }, | ||
| { | ||
| "name": "pricePerUnit", | ||
| "displayName": "Price per unit (USD)", | ||
| "shape": [ | ||
| "currency", | ||
| { | ||
| "code": "usd", | ||
| "decimalPlaces": 4 | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "grossQuantity", | ||
| "displayName": "Quantity", | ||
| "shape": [ | ||
| "number", | ||
| { | ||
| "thousandsSeparator": true | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "grossAmount", | ||
| "displayName": "Gross (USD)", | ||
| "shape": [ | ||
| "currency", | ||
| { | ||
| "code": "usd", | ||
| "decimalPlaces": 2, | ||
| "thousandsSeparator": true | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "discountQuantity", | ||
| "displayName": "Included quantity", | ||
| "shape": [ | ||
| "number", | ||
| { | ||
| "thousandsSeparator": true | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "discountAmount", | ||
| "displayName": "Included (USD)", | ||
| "shape": [ | ||
| "currency", | ||
| { | ||
| "code": "usd", | ||
| "decimalPlaces": 2, | ||
| "thousandsSeparator": true | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "netQuantity", | ||
| "displayName": "Billed quantity", | ||
| "shape": [ | ||
| "number", | ||
| { | ||
| "thousandsSeparator": true | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "netAmount", | ||
| "displayName": "Billed (USD)", | ||
| "shape": [ | ||
| "currency", | ||
| { | ||
| "code": "usd", | ||
| "decimalPlaces": 2, | ||
| "thousandsSeparator": true | ||
| } | ||
| ], | ||
| "role": "value" | ||
| }, | ||
| { | ||
| "name": "costCenter", | ||
| "displayName": "Cost center", | ||
| "shape": "string" | ||
| } | ||
| ], | ||
| "timeframes": [ | ||
| "last7days", | ||
| "thisMonth", | ||
| "lastMonth", | ||
| "thisYear", | ||
| "lastYear" | ||
| ] | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The starting month comes from
getUTCMonth()/getUTCFullYear()ontimeframe.start. For workspaces ahead of UTC, that lands in the previous month. For example, at UTC+10 "Last month" starts at2026-09-30T14:00Z, so it reads September plus October. "This month" reads two months, and "This year" starts at Dec 2025, so the spend tiles report too much. Could we take the month from the local date, or step forward from the first month that falls within the timeframe?