generated from austenstone/action-typescript
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2040971
commit 5f16370
Showing
3 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
||
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; | ||
} | ||
|
||
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}`); | ||
req = octokit.request("GET /enterprises/{enterprise}/copilot/usage", { | ||
enterprise: input.enterprise, | ||
}); | ||
} else if (input.organization) { | ||
info(`Fetching Copilot usage for organization ${input.organization}`); | ||
req = octokit.request("GET /orgs/{org}/copilot/usage", { | ||
org: input.organization, | ||
}); | ||
} else if (input.team) { | ||
info(`Fetching Copilot usage for team ${input.team}`); | ||
req = octokit.request("GET /orgs/{org}/team/{team_slug}/copilot/usage", { | ||
org: input.organization, | ||
team_id: input.team, | ||
}); | ||
} | ||
|
||
const data: CopilotUsageResponse = await req; | ||
|
||
info(`Hello, ${login}!`); | ||
console.log(data); | ||
}; | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
CopilotUsageResponse | ||
} |