Skip to content

Commit

Permalink
Merge pull request #23 from github-copilot-resources/feature/enterpri…
Browse files Browse the repository at this point in the history
…se-team-slice-calls

Add support to Enterprise level metrics
  • Loading branch information
martedesco committed Apr 30, 2024
2 parents ac9105f + b10cbee commit f227a05
Show file tree
Hide file tree
Showing 21 changed files with 29,844 additions and 444 deletions.
12 changes: 11 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Determines if mocked data should be used instead of making API calls.
VUE_APP_MOCKED_DATA=true

# Determines the scope of the API calls.
# Can be 'enterprise' or 'organization' to target API calls to an enterprise or an organization respectively.
VUE_APP_SCOPE=organization

# Determines the enterprise or organization name to target API calls.
VUE_APP_GITHUB_ORG=octodemo

VUE_APP_GITHUB_TOKEN=
VUE_APP_GITHUB_ENT=

# Determines the GitHub Personal Access Token to use for API calls.
# Create with scopes copilot, manage_billing:copilot, admin:enterprise, or manage_billing:enterprise, read:enterprise AND read:org
VUE_APP_GITHUB_TOKEN=
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,40 @@ The language breakdown analysis tab also displays a table showing the Accepted P

## Setup instructions

- Instructions on how to authenticate are provided in the [API documentation](https://docs.github.com/en/enterprise-cloud@latest/rest/copilot/copilot-usage?apiVersion=2022-11-28)
Instructions on how to authenticate are provided in the [API documentation](https://docs.github.com/en/enterprise-cloud@latest/rest/copilot/copilot-usage?apiVersion=2022-11-28)

In the `.env` file, you can configure several environment variables that control the behavior of the application.

#### VUE_APP_SCOPE

The `VUE_APP_SCOPE` environment variable in the `.env` file determines the scope of the API calls made by the application. It can be set to either 'enterprise' or 'organization'.

- If set to 'enterprise', the application will target API calls to the GitHub Enterprise account defined in the `VUE_APP_GITHUB_ENT` variable.
- If set to 'organization', the application will target API calls to the GitHub Organization account defined in the `VUE_APP_GITHUB_ORG` variable.

For example, if you want to target the API calls to an organization, you would set `VUE_APP_SCOPE=organization` in the `.env` file.

````
VUE_APP_SCOPE=organization
VUE_APP_GITHUB_ORG= <YOUR-ORGANIZATION>
VUE_APP_GITHUB_ENT=
````


#### VUE_APP_MOCKED_DATA

To access Copilot metrics from the last 28 days via the API and display actual data, set the following boolean environment variable to `false`:

### .env file setup
- To retrieve Copilot metrics via the API and display your organization's data, configure the following boolean environment variable to false:
```
VUE_APP_MOCKED_DATA=false
```
- Additionally, update the following environment variables:

#### VUE_APP_GITHUB_TOKEN
Specifies the GitHub Personal Access Token utilized for API requests. Generate this token with the following scopes: _copilot_, _manage_billing:copilot_, _manage_billing:enterprise_, _read:enterprise_, _admin:org_.

```
VUE_APP_GITHUB_ORG=
VUE_APP_GITHUB_TOKEN=
```

Expand Down Expand Up @@ -120,4 +143,5 @@ This project is licensed under the terms of the MIT open source license. Please
I aim to provide support through GitHub Issues. While I strive to stay responsive, I can't guarantee immediate responses. For critical issues, please include "CRITICAL" in the title for quicker attention.

### Coming next 🔮
- Enterprise level charts
- Team slicing
- Persistence layer
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "copilot-metrics-viewer",
"version": "1.2.0",
"version": "1.4.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
Binary file removed public/assets/copilotLogo.png
Binary file not shown.
Binary file added public/assets/github-mark@1200x733.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/favicon.ico
Binary file not shown.
3 changes: 3 additions & 0 deletions public/favicon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<link rel="icon" href="<%= BASE_URL %>favicon.svg">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
Expand Down
69 changes: 54 additions & 15 deletions src/api/GitHubApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,69 @@

import axios from "axios";

import { Metrics } from "../model/MetricsData";
import data from '../assets/copilot_metrics_response_sample.json';
import { Metrics } from "../model/Metrics";
import organizationMockedResponse from '../assets/organization_response_sample.json';
import enterpriseMockedResponse from '../assets/enterprise_response_sample.json';

export const getGitHubCopilotMetricsApi = async (): Promise<Metrics[]> => {

export const getMetricsApi = async (): Promise<Metrics[]> => {

let response;
let metricsData;

if (process.env.VUE_APP_MOCKED_DATA === "true") {
response = data;

if (process.env.VUE_APP_SCOPE === "organization") {
response = organizationMockedResponse;
} else if (process.env.VUE_APP_SCOPE === "enterprise") {
response = enterpriseMockedResponse;
} else {
throw new Error(`Invalid VUE_APP_SCOPE value: ${process.env.VUE_APP_SCOPE}. Expected "organization" or "enterprise".`);
}

metricsData = response.map((item: any) => new Metrics(item));
} else {
response = await axios.get(
`https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/usage`,
{
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
"X-GitHub-Api-Version": "2022-11-28",
},
}
);
if (process.env.VUE_APP_SCOPE === "organization") {
response = await axios.get(
`https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/usage`,
{
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
"X-GitHub-Api-Version": "2022-11-28",
},
}
);
} else if (process.env.VUE_APP_SCOPE === "enterprise") {

response = await axios.get(
`https://api.github.com/enterprises/${process.env.VUE_APP_GITHUB_ENT}/copilot/usage`,
{
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
"X-GitHub-Api-Version": "2022-11-28",
},
}
);
} else {
throw new Error(`Invalid VUE_APP_SCOPE value: ${process.env.VUE_APP_SCOPE}. Expected "organization" or "enterprise".`);
}

metricsData = response.data.map((item: any) => new Metrics(item));
}
return metricsData;
};
};

export const getTeams = async (): Promise<string[]> =>{
const response = await axios.get(`https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/teams`, {
headers: {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
'X-GitHub-Api-Version': '2022-11-28',
},
});

return response.data;
}

0 comments on commit f227a05

Please sign in to comment.