Skip to content

Add personal Copilot analytics to the Copilot tab and document required token access - #20

Merged
thinkdj merged 3 commits into
mainfrom
copilot/add-personal-account-analytics
Apr 19, 2026
Merged

Add personal Copilot analytics to the Copilot tab and document required token access#20
thinkdj merged 3 commits into
mainfrom
copilot/add-personal-account-analytics

Conversation

Copilot AI commented Apr 19, 2026

Copy link
Copy Markdown
Contributor
  • Remove fallback-to-all-items in filterCopilotBillingItems — return empty list when no Copilot items match
  • Include premium request netAmount in totalNetAmount in aggregatePersonalUsage
  • Replace React.ReactNode with the imported ReactNode in BreakdownTable
  • Fix JSX comment "Org selector" → "Account/target selector"

Copilot AI and others added 2 commits April 19, 2026 12:17
@thinkdj
thinkdj marked this pull request as ready for review April 19, 2026 12:55
Copilot AI review requested due to automatic review settings April 19, 2026 12:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds personal-account Copilot analytics to the Copilot tab (via user billing usage endpoints) while preserving the existing org analytics flow, and documents the required token access.

Changes:

  • Introduces unified Copilot analytics “targets” (org + personal) with a selector and shared panel rendering.
  • Adds GitHub API support + types for personal billing usage and premium request usage, with partial-failure handling.
  • Expands tests and README/token settings copy to cover personal analytics and required permissions.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/types.ts Adds personal billing usage/premium request types and a union type for org vs personal analytics data.
src/github-api.ts Adds fetchers for personal billing usage + premium request usage, and returns normalized type/target metadata for org data.
src/github-api.test.ts Adds unit tests for personal analytics fetcher and partial-failure behavior.
src/demo-data.ts Updates demo org Copilot payload to include new type/target fields.
src/components/TokenSettings.tsx Updates in-app token guidance for Copilot personal + org analytics access.
src/components/CopilotMetricsPanel.tsx Adds account selector and personal analytics rendering/aggregation alongside existing org metrics UI.
src/App.tsx Switches Copilot tab to a single query keyed by selected target (org/personal) and passes new props to the panel.
src/App.test.tsx Adds coverage for personal-only analytics and switching between org/personal targets.
README.md Documents token permissions/scopes for PR/branch features plus Copilot org + personal analytics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/github-api.ts Outdated
Comment on lines +423 to +454
let totalUsageQuantity = 0
let totalPremiumRequests = 0
let totalNetAmount = 0

for (const item of usage) {
const quantity = item.quantity ?? item.netQuantity ?? item.grossQuantity ?? 0
totalUsageQuantity += quantity
totalNetAmount += item.netAmount ?? 0

const key = `${item.product} · ${item.sku}`
const existing = productMap.get(key) ?? { quantity: 0, netAmount: 0, unitType: item.unitType }
existing.quantity += quantity
existing.netAmount += item.netAmount ?? 0
productMap.set(key, existing)

if (item.repositoryName) {
const repoExisting = repoMap.get(item.repositoryName) ?? { quantity: 0, netAmount: 0 }
repoExisting.quantity += quantity
repoExisting.netAmount += item.netAmount ?? 0
repoMap.set(item.repositoryName, repoExisting)
}
}

for (const item of premiumRequests) {
const quantity = item.netQuantity ?? item.quantity ?? item.grossQuantity ?? 0
totalPremiumRequests += quantity
const key = item.model ? `${item.product} · ${item.model}` : `${item.product} · ${item.sku}`
const existing = premiumMap.get(key) ?? { quantity: 0, netAmount: 0 }
existing.quantity += quantity
existing.netAmount += item.netAmount ?? 0
premiumMap.set(key, existing)
}

Copilot AI Apr 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aggregatePersonalUsage’s totalNetAmount is only incremented for usage items, but premium request items also have netAmount. This makes the “Net spend” summary undercount whenever premium requests are non-zero. Consider adding premium request netAmount into the total (or rename the card/label to clarify it excludes premium requests).

Copilot uses AI. Check for mistakes.
@@ -1,4 +1,5 @@
import { useMemo, useState } from 'react'
import type { ReactNode } from 'react'

Copilot AI Apr 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file now imports ReactNode, but BreakdownTable still types icon as React.ReactNode. In this repo, the React namespace isn’t guaranteed to be available (and you’ve already switched SummaryCard to ReactNode), so this can reintroduce a type error. Prefer using the imported ReactNode here as well, or import the React namespace type explicitly.

Suggested change
import type { ReactNode } from 'react'
import type { ReactNode } from 'react'
import type * as React from 'react'

Copilot uses AI. Check for mistakes.
Comment thread src/components/CopilotMetricsPanel.tsx Outdated
Copilot AI requested a review from thinkdj April 19, 2026 13:14
@thinkdj
thinkdj merged commit 9525ef5 into main Apr 19, 2026
1 check passed
@thinkdj
thinkdj deleted the copilot/add-personal-account-analytics branch July 21, 2026 10:20
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.

3 participants