austenstone / copilot-usage

Create copilot usage reports as job summaries, and much more!
MIT License
12 stars 3 forks source link

[Bug] If enterprise is specified, it shouldn't set a default value for organization #124

Closed raffertyuy closed 43 minutes ago

raffertyuy commented 6 days ago

What happened?

When I specify the enterprise input, I am expecting to see enterprise level metrics. So organization should be "" unless otherwise specified.

Currently, organization defaults to ${{ github.repository_owner }} Workaround is to set

with:
  enterprise: <enterprise-slug>
  organization: ""

Relevant log output

No response

Contact Details

No response

austenstone commented 6 days ago

Today enterprise > team > organization https://github.com/austenstone/copilot-usage/blob/9c819bed3de4a3abca6a34ddba2f86b065ab50f9/src/run.ts#L92-L116

I do this so we can use default values https://github.com/austenstone/copilot-usage/blob/9c819bed3de4a3abca6a34ddba2f86b065ab50f9/action.yml#L15-L18

If you're running the action in the organization you're trying to get metrics from you simply can call it as

      - uses: austenstone/copilot-usage@v4
        with:
          github-token: ${{ secrets.TOKEN }}

If you want enterprise level metrics pass the enterprise

      - uses: austenstone/copilot-usage@v4
        with:
          github-token: ${{ secrets.TOKEN }}
          enterprise: avocado-corp

If you want team metrics pass team

      - uses: austenstone/copilot-usage@v4
        with:
          github-token: ${{ secrets.TOKEN }}
          team: avocado-team

If you want org metrics from a seperate org from the one you're running in pass the org

      - uses: austenstone/copilot-usage@v4
        with:
          github-token: ${{ secrets.TOKEN }}
          organization: callmegreg-demo-org
raffertyuy commented 2 days ago

HI @austenstone, I'm basically running this GHA in my personal account/repo but pulling metrics that belong to a different enterprise and organization.

So every assumption to use ${{ github.repository_owner }} fails for me, as ${{ github.repository_owner }} does not belong to the enterprise_slug that I'm using.

So with this code

      - uses: austenstone/copilot-usage@v4
        with:
          github-token: ${{ secrets.TOKEN }}
          enterprise: avocado-corp

I am getting this error:

Run austenstone/copilot-usage@v4
Fetching Copilot usage for enterprise ***
Fetched Copilot usage data for 1 days (2024-[10](https://github.com/raffertyuy/github-copilot-metrics/actions/runs/11338106911/job/31530784868#step:2:11)-14 to 2024-10-14)
Fetching Copilot details for organization raffertyuy
HttpError: Not Found - https://docs.github.com/rest/copilot/copilot-user-management#get-copilot-seat-information-and-settings-for-an-organization
    at /home/runner/work/_actions/austenstone/copilot-usage/v4/node_modules/@actions/github/node_modules/@octokit/request/dist-node/index.js:[12](https://github.com/raffertyuy/github-copilot-metrics/actions/runs/11338106911/job/31530784868#step:2:13)5:1
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at run (/home/runner/work/_actions/austenstone/copilot-usage/v4/src/run.ts:128:1)

But this workaround works:

      - uses: austenstone/copilot-usage@v4
        with:
          github-token: ${{ secrets.TOKEN }}
          enterprise: avocado-corp
          organization: ""
austenstone commented 2 days ago

You should use either the enterprise input or the organization input but not both at the same time.