bthomas2622 / copilot-metrics-export-action

GitHub Action to export metrics from the GitHub Copilot Usage Metrics API into csv files
MIT License
3 stars 1 forks source link

GitHub Copilot Usage Metrics API Export

This action exports usage metrics from the GitHub Copilot Usage Metrics API into a CSV file. The files are available as workflow artifacts in the GitHub Action run.

Inputs

Input Description Required Default
access-token The access token to use for authenticating with the GitHub API. See the eligible access token types and required permissions in the GitHub Copilot Usage Metrics API documentation. Yes -
enterprise-summary true or false on whether to generate a csv for Copilot usage for enterprise members. No false
enterprise-name The name/slug of the enterprise to generate a csv for. Example: myent for https://github.com/enterprises/myent. If enterprise-summary is true -
enterprise-team-summary true or false on whether to generate a csv for Copilot usage for an enterprise team. No false
enterprise-team-name The slug of the enterprise team to generate a csv for. Example: engineering for https://github.com/orgs/myorg/teams/engineering. Use 'all' or '*' to generate a report containing every team If enterprise-team-summary is true -
org-summary true or false on whether to generate a csv for Copilot usage for organization members. No false
org-name The name of the organization to generate a csv for. Example: myorg for https://github.com/myorg. No Name of organization that action is running in.
team-summary true or false on whether to generate a csv for Copilot usage for a team. No false
team-name The name of the team to generate a csv for. Example: engineering for https://github.com/orgs/myorg/teams/engineering. If team-summary is true -

Usage

In order to run this action you must create a GitHub Action workflow (.github/workflows/copilot-api-export.yml). See Creating a Workflow file.

Examples

Generate a CSV for Copilot usage for organization members:

name: Copilot Usage Metrics Export
on:
  workflow_dispatch:

jobs:
  run:
    name: Copilot Usage Metrics Export Action
    runs-on: ubuntu-latest
    steps:
      - uses: bthomas2622/copilot-metrics-export-action@v1.2
        with:
          access-token: ${{ secrets.authorized-pat-here}}
          org-summary: true
          org-name: myorg

Generate a CSV for Copilot usage for an organzation and its team:

uses: bthomas2622/copilot-metrics-export-action@v1.2
with:
  access-token: ${{ secrets.authorized-pat-here}}
  enterprise-summary: true
  enterprise-name: myenterprise
  org-summary: true
  org-name: myorg
  team-summary: true
  team-name: engineering

Generate a CSV for Copilot usage for an enterprise and its enterprise team:

uses: bthomas2622/copilot-metrics-export-action@v1.2
with:
  access-token: ${{ secrets.authorized-pat-here}}
  enterprise-summary: true
  enterprise-name: myenterprise
  enterprise-team-summary: true
  enterprise-team-name: engineering

Generate a CSV for Copilot usage for an enterprise and all enterprise team:

uses: bthomas2622/copilot-metrics-export-action@v1.2
with:
  access-token: ${{ secrets.authorized-pat-here}}
  enterprise-summary: true
  enterprise-name: myenterprise
  enterprise-team-summary: true
  enterprise-team-name: '*'

Creating an Access Token

See the eligible access token types and required permissions in the GitHub Copilot Usage Metrics API documentation.

Personal Access Tokens (Classic)

If you choose to utilize a Personal Access Token (PAT) (Classic) it must possess copilot, manage_billing:copilot, admin:org, admin:enterprise, or manage_billing:enterprise scope to use the Copilot Usage Metrics API endpoint.

Add this PAT as a secret so it can be used as input for access-token, see Creating encrypted secrets for a repository.

Organizations

If your organization has SAML enabled you must authorize the PAT, see Authorizing a personal access token for use with SAML single sign-on.

Downloading your files

The files are available as workflow artifacts in the GitHub Action run.

Screenshot 2024-04-24 at 9 06 11 AM