This API provides endpoints to retrieve GitHub Copilot usage metrics at different organizational levels. This app utilizes the GitHub Copilot Metrics API to fetch and visualize Copilot metrics.
This project is developed and maintained by:
I+D Tech (Primary)
primary.com.ar
- Clone the repository
- Create a
.env
file in the root directory using.env.example
as a template:
cp .env.example .env
Then edit .env
with your values:
- GITHUB_TOKEN: Your GitHub personal access token
- ENTERPRISE: Your enterprise name
- ORG: Your organization name
- TEAM_SLUG: Your team slug
- API_VERSION: GitHub API version (defaults to 2022-11-28)
- Build and start the containers:
docker-compose up --build
The services will be available at:
- Frontend: http://localhost:8080
- Backend API: http://localhost:3000
To stop the services:
docker-compose down
- Clone the repository
- Install dependencies:
npm install
- Configure the environment as described above
- Start the server:
npm start
The API will be available at: http://localhost:3000
The API includes a Swagger UI interface for easy testing and documentation:
- Start the server:
npm start
- Access the Swagger UI at: http://localhost:3000/api-docs
The Swagger interface allows you to:
- View detailed API documentation
- Test endpoints directly from the browser
- See request/response schemas
- Authenticate using your GitHub token
- Download response examples
All endpoints are prefixed with the base URL: http://localhost:3000
GET /metrics/refresh
Fetches the most recent Copilot metrics, generates charts, and exports the data to both PNG and JSON files. This endpoint provides a convenient way to get fresh metrics data and automatically generate all associated files.
Returns the same structure as other metrics endpoints, including:
- Raw metrics data
- Formatted chart data
- Statistical summary
- Generated chart information
- Export file information
GET /enterprise/metrics
Returns Copilot usage metrics for the entire enterprise.
GET /enterprise/team/metrics
Returns Copilot metrics for a specific team within the enterprise.
GET /org/metrics
Returns Copilot usage metrics for the entire organization.
GET /org/team/metrics
Returns Copilot metrics for a specific team within the organization.
Each endpoint will:
- Return JSON data with metrics
- Generate and save a PNG chart in the exports directory
- Export the full data as JSON in the exports directory
All endpoints automatically export their data in two formats in the exports
directory:
- PNG chart images with format:
copilot-metrics-YYYY-MM-DDTHH-mm-ss.png
- JSON data files with format:
copilot-metrics-[type]-YYYY-MM-DD-YYYY-MM-DDTHH-mm-ss.json
Where:
[type]
is one of: enterprise, enterprise-team, organization, organization-team- The date (YYYY-MM-DD) helps with file organization
- The timestamp (HH-mm-ss) ensures unique filenames
All endpoints return JSON responses with the following structure:
{
"raw": {
// Raw metrics data from GitHub API
},
"chartData": {
"labels": ["01/01/2024", "02/01/2024", ...],
"datasets": [
{
"label": "Sugerencias Aceptadas",
"data": [100, 150, ...],
"borderColor": "#36A2EB",
"fill": false
},
{
"label": "Sugerencias Totales",
"data": [200, 250, ...],
"borderColor": "#FF6384",
"fill": false
}
]
},
"summary": {
"overall": {
"totalAcceptedSuggestions": 1000,
"totalSuggestions": 2000,
"acceptanceRate": "50.00",
"activeUsers": 50
},
"weeklyAverages": {
"acceptedSuggestions": "145.50",
"totalSuggestions": "290.75",
"acceptanceRate": "50.04"
},
"trends": {
"acceptedSuggestions": 5.2,
"totalSuggestions": 3.8,
"trend": "Ligero incremento"
},
"lastUpdate": "2024-01-15"
},
"chart": {
"success": true,
"filePath": "exports/copilot-metrics-2024-01-15T12-30-45.png",
"fileName": "copilot-metrics-2024-01-15T12-30-45.png"
}
}
The chartData
object is formatted for use with chart libraries like Chart.js. The API automatically generates and saves chart images in PNG format in the exports
directory.
The API generates several types of chart visualizations that are saved as PNG files in the exports
directory:
This chart shows an overview of key Copilot metrics including active users and engagement rates.
This visualization displays weekly trends and acceptance rates over time.
The API uses standard HTTP response codes:
- 200: Success
- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 500: Internal Server Error
To ensure the integrity and reliability of the application, follow the steps below to run the test suite.
-
Install Dependencies
Ensure all dependencies are installed:npm install
-
Run Tests
Execute the test suite with the following command:npm test
-
Start Containers
Make sure the necessary containers are running:docker-compose up --build
-
Execute Tests Inside Container
Run the tests within the backend container:docker-compose exec backend npm test
All requests require proper GitHub authentication headers.
This project was developed with the assistance of:
- Aider, an AI pair programming tool
- Model: Anthropic Claude 3.5 Sonnet
The use of these AI tools helped streamline development while maintaining code quality and best practices.