github: apiURL

Also took the opportunity to make some methods static

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-02-01 01:42:02 +01:00
parent e218647127
commit 17f9c80d9c
2 changed files with 51 additions and 33 deletions

View File

@@ -15,27 +15,30 @@ export interface GitHubOpts {
}
export class GitHub {
public static readonly serverURL: string = process.env.GITHUB_SERVER_URL || 'https://github.com';
public readonly octokit: InstanceType<typeof Octokit>;
constructor(opts?: GitHubOpts) {
this.octokit = github.getOctokit(`${opts?.token}`);
}
get context(): Context {
return github.context;
}
get serverURL(): string {
return process.env.GITHUB_SERVER_URL || 'https://github.com';
}
get actionsRuntimeToken(): GitHubActionsRuntimeToken {
const token = process.env['ACTIONS_RUNTIME_TOKEN'] || '';
return token ? jwt_decode<GitHubActionsRuntimeToken>(token) : {};
}
public repoData(): Promise<GitHubRepo> {
return this.octokit.rest.repos.get({...github.context.repo}).then(response => response.data as GitHubRepo);
}
static get context(): Context {
return github.context;
}
static get serverURL(): string {
return process.env.GITHUB_SERVER_URL || 'https://github.com';
}
static get apiURL(): string {
return process.env.GITHUB_API_URL || 'https://api.github.com';
}
static get actionsRuntimeToken(): GitHubActionsRuntimeToken {
const token = process.env['ACTIONS_RUNTIME_TOKEN'] || '';
return token ? jwt_decode<GitHubActionsRuntimeToken>(token) : {};
}
}