Skip to content
upload-cloud

GitHub Action

Copilot Metrics Retention

v1.0 Latest version

Copilot Metrics Retention

upload-cloud

Copilot Metrics Retention

This Action is designed to persistently store Copilot Usage Metrics data over time in a JSON file format

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Copilot Metrics Retention

uses: ambilykk/copilot-metrics-retention@v1.0

Learn more about this action in ambilykk/copilot-metrics-retention

Choose a version

Copilot Metrics Retention

The Copilot Usage Metrics API supplies data spanning a 28-day timeframe. This Action is designed to persistently store this data over time in a JSON file format. This Action generates the Copilot Usage Metrics data in a JSON file format and stores it in the repository. Each time the Action is executed, the JSON file is refreshed to incorporate the delta data retrieved from the API.

Note:

PAT Token

Create a Fine-grained personal access tokens with

  • Resource owner as Organization
  • read & write access to GitHub Copilot for Business under Organization permissions gh image

Pass this token as an input to the action - GITHUB_TOKEN

Usage in workflow

Incorporate the copilot-metrics-retention action into your workflow and initiate the workflow either manually or through a schedule.

Sample workflow file:

    name: Copilot Metrics Retention

    on:
     workflow_dispatch:
      inputs:
          org_name: 
            description: 'Organization name'
            required: true
            default: 'octodemo'
          json_path:
            description: 'JSON File path'
            required: true
            default: 'metrics.json'
         
    jobs:
     first-job:
     runs-on: ubuntu-latest
    
     steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Copilot Metrics Retention 
        uses: ambilykk/copilot-metrics-retention@main
        with:        
          GITHUB_TOKEN: ${{ secrets.ORG_TOKEN }}
          org_name: ${{ inputs.org_name }} 
          json_path: ${{ inputs.json_path }} 
    
      - name: Commit and push if it changed
        run: |
            git config --global user.name 'Copilot Metrics Retention'
            git config --global user.email 'action@github.com'
            git add -A
            git diff --quiet && git diff --staged --quiet || git commit -m "Copilot Metrics data update"
            git push
     

Parameters

Name Required Description
GITHUB_TOKEN Yes PAT Token for access
org_name Yes GitHub Organization Name
json_path Yes JSON file path to store the Copilot Metrics dtaa in repository

License

The scripts and documentation in this project are released under the MIT License