Since GitHubCopilot usage and seat API (see https://docs.github.com/en/rest/copilot/copilot-usage?apiVersion=2022-11-28) just return latest information. like copilot usage only returns latest 28 days usage. and manager API just return the current-latest activity. if we need a long period usage and seat for analysis. it needs a job to periodllyget such data and save it for persistent. so this project is target to meet such requirement.
This App works as backend, it will call GitHubAPI periodlly(each 12 hours by default), then save the fetched data to a file or MySQL for persistent storage, and expose some data by RestAPI, just as similar with GitHubCopilot API itself, the path is same, just update the endpoint by replacing https://api.github.com/ with http://YourServer:3000/api/
add docker support.
We have recently added support for GitHub Copilot Metrics. Here are some key features:
/api/:scopeType/:scopeName/copilot/metrics
endpoint to retrieve Copilot Metrics data for a specific tenant./api/:scopeType/:scopeName/copilot/metrics
endpoint, making it easier for developers to view and test the API.Clone the repository:
git clone https://github.com/DevOps-zhuang/copilot-metric-saver.git
cd copilot-metric-saver
Install dependencies:
npm install
npm install -g ts-node typescript
Configure the database and other settings in .env
.
if you prefer to save the output as file format, no needed to update the database setting.
Start the server:
ts-node src/server.ts
The server will run on http://localhost:3000
.
And for the overroll API, plese visit http://localhost:3000/api-docs
.
docker build -t copilot-metrics-saver . docker run -p 3000:3000 --env-file ./.env copilot-metrics-saver
GET /api/:scopeType/:scopeName/copilot/usage
Parameters:
scopeType
: The type of scope (organization, team, or enterprise).scopeName
: The name of the scope.token
: The authorization token (passed as a Bearer token in the Authorization header).since
(optional): The start date for fetching usage data.until
(optional): The end date for fetching usage data.page
(optional): The page number for pagination.per_page
(optional): The number of items per page for pagination.Example:
curl -H "Authorization: Bearer YOUR_TOKEN" "http://localhost:3000/api/organization/example-org/copilot/usage"
GET /tenants
Returns: A list of active tenants with their scopeType
and scopeName
.
Example:
curl "http://localhost:3000/tenants"
src/
├── api/
│ ├── GitHubApi.ts # Contains functions to call GitHubAPIs.
│ ├── TenantServiceFactory.ts # Factory to create tenant service instances.
│ ├── UsageServiceFactory.ts # Factory to create usage service instances.
│ ├── MySQLTenantStorage.ts # Implementation of tenant storage using MySQL.
│ └── FileTenantStorage.ts # Implementation of tenant storage using the file system.
├── model/
│ ├── Tenant.ts # Tenant model class.
│ └── Metrics.ts # Metrics model class.
└── server.ts # Main server file.
The Tenant
class represents a tenant and includes the following properties:
scopeType
: The type of scope (organization, team, or enterprise).scopeName
: The name of the scope.token
: The authorization token.isActive
: Indicates whether the tenant is active.The Tenant
class also includes a method to validate the tenant using the GitHubAPI.
This project is licensed under the MIT License. See the LICENSE file for details.