AndreiS-gh opened a new pull request, #8980:
URL: https://github.com/apache/devlake/pull/8980

   ## Summary
   
   Add support for GitHub Copilot AI credit usage billing metrics collection 
via the GitHub Copilot billing API endpoints.
   
   This PR closes gaps identified in the 
[copilot-metrics-roi-toolkit](https://github.com/DevExpGbb/copilot-metrics-roi-toolkit)
 schema reconciliation, specifically the missing **Billing Usage** API group (3 
endpoints).
   
   ## Changes
   
   ### New Models (3 tables)
   - `GhCopilotEnterpriseAiCreditUsage` — Enterprise-level AI credit tracking 
with cost center support
   - `GhCopilotOrgAiCreditUsage` — Organization-level AI credit tracking  
   - `GhCopilotUserAiCreditUsage` — Individual user-level AI credit tracking
   
   ### New Tasks
   - **Collector** (`ai_credit_collector.go`) — Routes requests to appropriate 
GitHub billing API endpoint based on connection type (enterprise/org/user) and 
filters by date range
   - **Extractor** (`ai_credit_extractor.go`) — Parses credit usage items and 
routes records to corresponding tables
   
   ### New Migration
   - `20260708_add_ai_credit_usage_metrics.go` — Registers all three billing 
tables
   
   ### E2E Tests
   - Added snapshot tables for all three billing levels with realistic test data
   
   ## Technical Details
   
   **GitHub Copilot Billing API Endpoints Covered:**
   - `GET /enterprises/{enterprise}/settings/billing/ai_credit/usage`
   - `GET /organizations/{org}/settings/billing/ai_credit/usage`
   - `GET /users/{username}/settings/billing/ai_credit/usage`
   
   **Data Structure (denormalized per model per entity per time period):**
   - Time period: year, month, day
   - Model name (e.g., gpt-4.1, claude-3)
   - Cost center (enterprise only)
   - Usage metrics: gross/net quantity, pricing, discounts
   
   **Connection Type Routing:**
   - Enterprise connections → `_tool_copilot_enterprise_ai_credit_usage`
   - Organization connections → `_tool_copilot_org_ai_credit_usage`
   - User-scoped connections → `_tool_copilot_user_ai_credit_usage`
   
   ## Testing
   - [x] Migration script registered in `migrationscripts/register.go`
   - [x] Models registered in `models.go` and `models_test.go`
   - [x] Subtasks registered in `register.go` and `subtasks.go`
   - [x] E2E snapshot tables added with test data
   - [x] Go formatting verified
   
   ## Related
   - Metrics parity gap analysis: 
copilot-metrics-roi-toolkit/blob/main/copilot-api-schemas/README.md
   - Reference PR: #8889 (user-teams metrics collection by @jaroslawgajewski)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to