Skip to content

Commit 42c366e

Browse files
committed
Add queries for organization and enterprise metrics, and update USAGE_API.md for local JSON file usage
1 parent 9d1f7e9 commit 42c366e

9 files changed

+148
-104
lines changed

README.md

Lines changed: 89 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,20 @@ With the release of the latest [GitHub Copilot Metrics API](https://github.com/o
44

55
However, many organizations that we work with already have established Power BI teams. If your organization is **already using Power BI, please read on!**
66

7+
## New Features
8+
- New metrics for Pull Request summaries and Copilot Chat on GitHub.com.
9+
- Clarity on code completions and Copilot Chat usage in IDEs.
10+
- User engagement summaries updated daily.
11+
- Custom model slicing support, coming soon!
12+
- Data can be aggregated by enterprise, organization or team.
13+
714
Located in the `./samples` directory you'll find sample JSON and PBIX files used to create the *new* dashboard below.
8-
> Note: The legacy GitHub Copilot Usage API is still available and can be used with the legacy PBIX file. For instructions, see [Usage_API.md](USAGE_API.md).
15+
> Note: The legacy GitHub Copilot Usage API is still available and can be used with the `GitHub Copilot - Telemetry Sample (Usage).pbix` file. For instructions, see [Usage_API.md](USAGE_API.md).
916
10-
![Image of the Power BI dashboard with sample GitHub Copilot Metrics API data displayed.](https://github.com/jasonmoodie/pbi-4-ghcopilot/blob/main/assets/Sample_Metrics_PBI.png)
17+
![Image of the Power BI dashboard with sample GitHub Copilot Metrics API data displayed.](./assets/Sample_Metrics_PBI.png)
1118

1219
## Setup
1320

14-
### Test: Modify the local JSON data source
15-
> Note: This example provided a proof of concept for loading metrics data and requires an exported JSON file. If you have access to the REST API you can configure the **Source** accordingly.
16-
17-
1. Download and open the sample `GitHub Copilot - Telemetry Sample (Metrics with KPIs).pbix` file.
18-
2. The file contains three data sources on the right hand side.
19-
20-
| Name | Description |
21-
| :-------------------- | :----------------------------------------------------- |
22-
| config | Configuration used to display date of refresh and for setting up KPI dashboard |
23-
| source | Base source used to connect to API or local JSON files. |
24-
| GH Copilot - dotcom chat | Detailed metrics of code completions using chat on the web. |
25-
| GH Copilot - ide chat | Detailed metrics of code completions using chat within the IDE. |
26-
| GH Copilot - ide code completions | Detailed metrics of code completions within the IDE. |
27-
| GH Copilot - pull requests | Detailed metrics of pull requests. |
28-
| GH Copilot - summary | Daily summary of active and egnaged user. |
29-
30-
3. Open the **Power Query Editor** by clicking **Transform data** in the top-menu and selecting **Tranform data**.
31-
4. Click on **source** query in the left-menu, then under APPLIED STEPS in the right-menu click the gear (settings) icon, selecting your JSON file and clicking **OK**.
32-
![Image of a data source selector in Power Query Editor.](https://github.com/jasonmoodie/pbi-4-ghcopilot/blob/main/assets/Modify_JSON_source.png)
33-
5. Click **Close and Apply** in the top-left of the **Power Query Editor**.
34-
6. On the **Report View** page click **Refresh** to load the new data into your dashboard.
35-
7. **Happy Customizing!**
36-
3721
### Connect to Metrics API
3822
> Notes: The REST API provides metrics for the previous 28 days and is refreshed daily with data from the previous day. Please ensure you are using the latest version of the [REST API](https://docs.github.com/en/enterprise-cloud@latest/rest/copilot/copilot-metrics).
3923
@@ -43,67 +27,92 @@ In order to connect we'll need to generate a token and link to your metrics data
4327
3. Follow the instructions below to generate a token with permissions to access the API:
4428
[REST API endpoints for GitHub Copilot usage metrics - GitHub Docs](https://docs.github.com/en/rest/copilot/copilot-usage)
4529
>**IMPORTANT: Do not share this token and ensure you follow you organizations security policies.**
46-
4. Open the **Power Query Editor** by clicking **Transform data** in the top-menu and selecting **Tranform data**.
47-
5. Click on **source** in the left-menu
48-
6. Select **Advanced editor**.
49-
![Image of Power Query Advanced Editor.](https://github.com/jasonmoodie/pbi-4-ghcopilot/blob/main/assets/Advanced_editor.png)
50-
7. Replace the first 2 lines with following, ensure to replace <YOUR-TOKEN> and <ORG> with the values from step 1 and 2.
30+
4. The file contains the following data sources, descriptions are inlcuded below.
31+
32+
| Name | Description |
33+
| :--------------------------------- | :------------------------------------------------------------ |
34+
| config | Configuration used to display date of refresh and KPI dashboard |
35+
| source | Base source used to connect to API or local JSON files. |
36+
| GH Copilot - dotcom chat | Detailed metrics of code completions using chat on the web. |
37+
| GH Copilot - ide chat | Detailed metrics of code completions using chat within the IDE. |
38+
| GH Copilot - ide code completions | Detailed metrics of code completions within the IDE. |
39+
| GH Copilot - pull requests | Detailed metrics of pull requests. |
40+
| GH Copilot - summary | Daily summary of active and engaged users. |
41+
5. Open the **Power Query Editor** by clicking **Transform data** in the top-menu and selecting **Tranform data**.
42+
6. Click on **source** in the left-menu.
43+
7. Select **Advanced editor**.
44+
![Image of Power Query Advanced Editor.](./assets/Advanced_editor.png)
45+
8. Replace the first 2 lines with following, ensure to replace `<YOUR-TOKEN>` along with the relevant `<ENTERPRISE>`, `<ORG>` and `<TEAM_SLUG>` with the values from step 2.
5146

52-
**Enterprise**
53-
```powerquery
54-
let
55-
// Replace <YOUR-TOKEN> and <ENTERPRISE> with your actual token and enterprise name.
56-
url = "https://api.github.com/enterprises/<ENTERPRISE>/copilot/metrics",
57-
headers = [
58-
#"Accept" = "application/vnd.github+json",
59-
#"Authorization" = "Bearer <YOUR-TOKEN>",
60-
#"X-GitHub-Api-Version" = "2022-11-28"
61-
],
62-
Source = Json.Document(Web.Contents(url, [Headers=headers])),
63-
```
64-
65-
**Enterprise Team**
66-
```powerquery
67-
let
68-
// Replace <YOUR-TOKEN>, <ENTERPRISE> and <TEAM_SLUG> with your actual token and enterprise name.
69-
url = "https://api.github.com/enterprises/<ENTERPRISE>/team/<TEAM_SLUG>/copilot/metrics
70-
headers = [
71-
#"Accept" = "application/vnd.github+json",
72-
#"Authorization" = "Bearer <YOUR-TOKEN>",
73-
#"X-GitHub-Api-Version" = "2022-11-28"
74-
],
75-
Source = Json.Document(Web.Contents(url, [Headers=headers])),
76-
```
77-
**Organization**
78-
```powerquery
79-
let
80-
// Replace <YOUR-TOKEN> and <ORG> with your actual token and org name.
81-
url = "https://api.github.com/orgs/<ORG>/copilot/metrics",
82-
headers = [
83-
#"Accept" = "application/vnd.github+json",
84-
#"Authorization" = "Bearer <YOUR-TOKEN>",
85-
#"X-GitHub-Api-Version" = "2022-11-28"
86-
],
87-
Source = Json.Document(Web.Contents(url, [Headers=headers])),
88-
```
89-
**Team**
90-
```powerquery
91-
let
92-
// Replace <YOUR-TOKEN>, <ORG> and <TEAM_SLUG> with your actual token and enterprise name.
93-
url = "https://api.github.com/orgs/<ORG>/team/<TEAM_SLUG>/copilot/metrics",
94-
headers = [
95-
#"Accept" = "application/vnd.github+json",
96-
#"Authorization" = "Bearer <YOUR-TOKEN>",
97-
#"X-GitHub-Api-Version" = "2022-11-28"
98-
],
99-
Source = Json.Document(Web.Contents(url, [Headers=headers])),
100-
```
47+
**Enterprise**
48+
```powerquery
49+
let
50+
// Replace <YOUR-TOKEN> and <ENTERPRISE> with your actual token and enterprise name.
51+
url = "https://api.github.com/enterprises/<ENTERPRISE>/copilot/metrics",
52+
headers = [
53+
#"Accept" = "application/vnd.github+json",
54+
#"Authorization" = "Bearer <YOUR-TOKEN>",
55+
#"X-GitHub-Api-Version" = "2022-11-28"
56+
],
57+
Source = Json.Document(Web.Contents(url, [Headers=headers])),
58+
```
59+
60+
**Enterprise Team**
61+
```powerquery
62+
let
63+
// Replace <YOUR-TOKEN>, <ENTERPRISE> and <TEAM_SLUG> with your actual token and enterprise name.
64+
url = "https://api.github.com/enterprises/<ENTERPRISE>/team/<TEAM_SLUG>/copilot/metrics",
65+
headers = [
66+
#"Accept" = "application/vnd.github+json",
67+
#"Authorization" = "Bearer <YOUR-TOKEN>",
68+
#"X-GitHub-Api-Version" = "2022-11-28"
69+
],
70+
Source = Json.Document(Web.Contents(url, [Headers=headers])),
71+
```
72+
73+
**Organization**
74+
```powerquery
75+
let
76+
// Replace <YOUR-TOKEN> and <ORG> with your actual token and org name.
77+
url = "https://api.github.com/orgs/<ORG>/copilot/metrics",
78+
headers = [
79+
#"Accept" = "application/vnd.github+json",
80+
#"Authorization" = "Bearer <YOUR-TOKEN>",
81+
#"X-GitHub-Api-Version" = "2022-11-28"
82+
],
83+
Source = Json.Document(Web.Contents(url, [Headers=headers])),
84+
```
85+
86+
**Team**
87+
```powerquery
88+
let
89+
// Replace <YOUR-TOKEN>, <ORG> and <TEAM_SLUG> with your actual token and enterprise name.
90+
url = "https://api.github.com/orgs/<ORG>/team/<TEAM_SLUG>/copilot/metrics",
91+
headers = [
92+
#"Accept" = "application/vnd.github+json",
93+
#"Authorization" = "Bearer <YOUR-TOKEN>",
94+
#"X-GitHub-Api-Version" = "2022-11-28"
95+
],
96+
Source = Json.Document(Web.Contents(url, [Headers=headers])),
97+
```
10198
8. Your Power Query will look something like this:
102-
![Image of Power Query Advanced Editor.](https://github.com/jasonmoodie/pbi-4-ghcopilot/blob/main/assets/Advanced_editor_metrics_query.png)
99+
![Image of Power Query Advanced Editor.](./assets/Advanced_editor_metrics_query.png)
103100
9. Click **OK** to close the editor and select `Anonymous` authentication if prompted.
104101
10. Click **Close and Apply** in the top-left of the **Power Query Editor**.
105102
11. On the **Report View** page click **Refresh** to load the new data into your dashboard.
106103
104+
### Test: Modify the local JSON data source
105+
> Note: This example provided a proof of concept for loading metrics data and requires an exported JSON file. If you have access to the REST API you can configure the **Source** accordingly.
106+
107+
1. Download and open the sample `GitHub Copilot - Telemetry Sample (Metrics with KPIs).pbix` file.
108+
2. Open the **Power Query Editor** by clicking **Transform data** in the top-menu and selecting **Tranform data**.
109+
3. Click on **source** query in the left-menu
110+
4. In the right-menu under **APPLIED STEPS** click the gear (settings) icon, selecting your JSON file and clicking **OK**.
111+
![Image of a data source selector in Power Query Editor.](https://github.com/github-copilot-resources/copilot-metrics-viewer-power-bi/blob/main/assets/Modify_JSON_source.png)
112+
5. Click **Close and Apply** in the top-left of the **Power Query Editor**.
113+
6. On the **Report View** page click **Refresh** to load the new data into your dashboard.
114+
7. **Happy Customizing!**
115+
107116
## Publishing
108117
If you need help deploying or publishing this script, please see: [Publish README](/publish/README.md)
109118

USAGE_API.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,9 @@
44
55
Located in the `./samples` directory you'll find sample JSON and PBIX files used to create the dashboard below.
66

7-
![Image of a Power BI dashboard with GitHuub Copilot Metrics API data displayed.](https://github.com/jasonmoodie/pbi-4-ghcopilot/blob/main/assets/Sample_PBI.png)
7+
![Image of a Power BI dashboard with GitHuub Copilot Metrics API data displayed.](./assets/Sample_PBI.png)
88

99
## Setup
10-
11-
### Test: Modify the local JSON data source
12-
> Note: This example provided a proof of concept for loading metrics data and requires an exported JSON file. If you have access to the REST API you can configure the **Source** accordingly.
13-
14-
1. Download and open the sample `GitHub Copilot - Telemetry Sample (Usage).pbix` file.
15-
2. The file contains three data sources on the right hand side.
16-
17-
| Name | Description |
18-
| :-------------------- | :----------------------------------------------------- |
19-
| GH Copilot - Details | Detailed breakdown of metrics data by language and editor. |
20-
| GH Copilot - Summary | Daily summary of metrics data. |
21-
| Last Refresh | Used to display the data time of data refresh on the top-right corner of the dashboard. |
22-
23-
3. Open the **Power Query Editor** by right clicking the `GH Copilot - Details` and selecting **Edit query**.
24-
4. Modify the **Source** step by clicking the settings icon, selecting your JSON file and clicking **OK**.
25-
![Image of a data source selector in Power Query Editor.](https://github.com/jasonmoodie/pbi-4-ghcopilot/blob/main/assets/Modify_JSON_source.png)
26-
6. Repeat steps 3 and 4 for the `GH Copilot - Summary` **Source**.
27-
7. Click **Close and Apply** in the top-left of the **Power Query Editor**.
28-
8. On the **Report View** page click **Refresh** to load the new data into your dashboard.
29-
9. **Happy Customizing!**
30-
3110
### Connect to Metrics API
3211
> Notes: The REST API provides metrics for the previous 28 days and is refreshed daily with data from the previous day. This is currently in beta, so please ensure you are using the latest version of the [REST API](https://docs.github.com/en/rest/copilot/copilot-usage).
3312
@@ -39,7 +18,7 @@ In order to connect we'll need to generate a token and link to your metrics data
3918
>**IMPORTANT: Do not share this token and ensure you follow you organizations security policies.**
4019
4. Open the **Power Query Editor** by right clicking the `GH Copilot - Details` and selecting **Edit query**.
4120
5. Select **Advanced editor**.
42-
![Image of Power Query Advanced Editor.](https://github.com/jasonmoodie/pbi-4-ghcopilot/blob/main/assets/Advanced_editor.png)
21+
![Image of Power Query Advanced Editor.](./assets/Advanced_editor.png)
4322
6. Replace the first 2 lines with following, ensure to replace <YOUR-TOKEN> and <ORG> with the values from step 1 and 2.
4423

4524
**Organization**
@@ -67,12 +46,32 @@ In order to connect we'll need to generate a token and link to your metrics data
6746
Source = Json.Document(Web.Contents(url, [Headers=headers])),
6847
```
6948
7. Your Power Query will look something like this:
70-
![Image of Power Query Advanced Editor.](https://github.com/jasonmoodie/pbi-4-ghcopilot/blob/main/assets/Advanced_editor_query.png)
49+
![Image of Power Query Advanced Editor.](./assets/Advanced_editor_query.png)
7150
8. Click **OK** to close the editor and select `Anonymous` authentication if prompted.
7251
9. Repeat steps 4 and 8 for the `GH Copilot - Summary` **Source**.
7352
10. Click **Close and Apply** in the top-left of the **Power Query Editor**.
7453
11. On the **Report View** page click **Refresh** to load the new data into your dashboard.
7554

55+
### Modify to use a local JSON file
56+
> Note: This example provided a proof of concept for loading metrics data and requires an exported JSON file. If you have access to the REST API you can configure the **Source** accordingly.
57+
58+
1. Download and open the sample `GitHub Copilot - Telemetry Sample (Usage).pbix` file.
59+
2. The file contains three data sources on the right hand side.
60+
61+
| Name | Description |
62+
| :-------------------- | :----------------------------------------------------- |
63+
| GH Copilot - Details | Detailed breakdown of metrics data by language and editor. |
64+
| GH Copilot - Summary | Daily summary of metrics data. |
65+
| Last Refresh | Used to display the data time of data refresh on the top-right corner of the dashboard. |
66+
67+
3. Open the **Power Query Editor** by right clicking the `GH Copilot - Details` and selecting **Edit query**.
68+
4. Modify the **Source** step by clicking the settings icon, selecting your JSON file and clicking **OK**.
69+
![Image of a data source selector in Power Query Editor.](./assets/Modify_JSON_source.png)
70+
6. Repeat steps 3 and 4 for the `GH Copilot - Summary` **Source**.
71+
7. Click **Close and Apply** in the top-left of the **Power Query Editor**.
72+
8. On the **Report View** page click **Refresh** to load the new data into your dashboard.
73+
9. **Happy Customizing!**
74+
7675
## Publishing
7776
If you need help deploying or publishing this script, please see: [Publish README](/publish/README.md)
7877

queries/enterprise_metrics.pq

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let
2+
// Replace <YOUR-TOKEN> and <ENTERPRISE> with your actual token and enterprise name.
3+
url = "https://api.github.com/enterprises/<ENTERPRISE>/copilot/metrics",
4+
headers = [
5+
#"Accept" = "application/vnd.github+json",
6+
#"Authorization" = "Bearer <YOUR-TOKEN>",
7+
#"X-GitHub-Api-Version" = "2022-11-28"
8+
],
9+
Source = Json.Document(Web.Contents(url, [Headers=headers])),

queries/enterprise_team_metrics.pq

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let
2+
// Replace <YOUR-TOKEN>, <ENTERPRISE> and <TEAM_SLUG> with your actual token and enterprise name.
3+
url = "https://api.github.com/enterprises/<ENTERPRISE>/team/<TEAM_SLUG>/copilot/metrics",
4+
headers = [
5+
#"Accept" = "application/vnd.github+json",
6+
#"Authorization" = "Bearer <YOUR-TOKEN>",
7+
#"X-GitHub-Api-Version" = "2022-11-28"
8+
],
9+
Source = Json.Document(Web.Contents(url, [Headers=headers])),
File renamed without changes.

queries/organization_metrics.pq

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let
2+
// Replace <YOUR-TOKEN> and <ORG> with your actual token and org name.
3+
url = "https://api.github.com/orgs/<ORG>/copilot/metrics",
4+
headers = [
5+
#"Accept" = "application/vnd.github+json",
6+
#"Authorization" = "Bearer <YOUR-TOKEN>",
7+
#"X-GitHub-Api-Version" = "2022-11-28"
8+
],
9+
Source = Json.Document(Web.Contents(url, [Headers=headers])),
File renamed without changes.

queries/teams_metrics.pq

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let
2+
// Replace <YOUR-TOKEN>, <ORG> and <TEAM_SLUG> with your actual token and enterprise name.
3+
url = "https://api.github.com/orgs/<ORG>/team/<TEAM_SLUG>/copilot/metrics",
4+
headers = [
5+
#"Accept" = "application/vnd.github+json",
6+
#"Authorization" = "Bearer <YOUR-TOKEN>",
7+
#"X-GitHub-Api-Version" = "2022-11-28"
8+
],
9+
Source = Json.Document(Web.Contents(url, [Headers=headers])),
Binary file not shown.

0 commit comments

Comments
 (0)