Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
austenstone committed Apr 23, 2024
1 parent 2040971 commit 5f16370
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

41 changes: 36 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,59 @@
import { getInput, info } from "@actions/core";
import { getBooleanInput, getInput, info } from "@actions/core";
import { getOctokit } from "@actions/github";
import { CopilotUsageResponse } from './types'

Check failure on line 3 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Replace `'./types'` with `"./types";`

interface Input {
token: string;
organization?: string;
enterprise?: string;
team?: string;
report: boolean;
}

const getInputs = (): Input => {
const result = {} as Input;
result.token = getInput("github-token");
result.organization = getInput("organization");
result.enterprise = getInput("enterprise");
result.report = getBooleanInput("report");
if (!result.token || result.token === "") {
throw new Error("github-token is required");
}
if (!result.organization && !result.enterprise && !result.team) {
throw new Error("organization, enterprise or team is required");
}
if (result.team && !result.organization) {
throw new Error("organization is required when team is provided");
}
return result;
}

Check failure on line 29 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Insert `;`

const run = async (): Promise<void> => {
const input = getInputs();
const octokit = getOctokit(input.token);

const {
data: { login },
} = await octokit.rest.users.getAuthenticated();
let req;
if (input.enterprise) {
info(`Fetching Copilot usage for enterprise ${input.enterprise}`);

Check failure on line 37 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci

English text in string literals is not allowed
req = octokit.request("GET /enterprises/{enterprise}/copilot/usage", {
enterprise: input.enterprise,
});
} else if (input.organization) {
info(`Fetching Copilot usage for organization ${input.organization}`);

Check failure on line 42 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci

English text in string literals is not allowed
req = octokit.request("GET /orgs/{org}/copilot/usage", {
org: input.organization,
});
} else if (input.team) {
info(`Fetching Copilot usage for team ${input.team}`);

Check failure on line 47 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci

English text in string literals is not allowed
req = octokit.request("GET /orgs/{org}/team/{team_slug}/copilot/usage", {
org: input.organization,
team_id: input.team,

Check failure on line 50 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Identifier 'team_id' is not in camel case
});
}

Check failure on line 53 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Delete `··`
const data: CopilotUsageResponse = await req;

info(`Hello, ${login}!`);
console.log(data);

Check failure on line 56 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
};

run();
28 changes: 28 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
type CopilotUsageBreakdown = {
language: string;
editor: string;
suggestions_count: number;
acceptances_count: number;
lines_suggested: number;
lines_accepted: number;
active_users: number;
};

type CopilotUsageResponseData = {
day: string;
total_suggestions_count: number;
total_acceptances_count: number;
total_lines_suggested: number;
total_lines_accepted: number;
total_active_users: number;
total_chat_acceptances: number;
total_chat_turns: number;
total_active_chat_users: number;
breakdown: CopilotUsageBreakdown[];
};

type CopilotUsageResponse = CopilotUsageResponseData[];

export {

Check failure on line 26 in src/types.ts

View workflow job for this annotation

GitHub Actions / ci

Replace `⏎··CopilotUsageResponse⏎}` with `·CopilotUsageResponse·};`
CopilotUsageResponse
}

0 comments on commit 5f16370

Please sign in to comment.