Merge pull request #12 from crazy-max/github-apiurl

github: apiUrl
This commit is contained in:
CrazyMax 2023-02-01 01:46:12 +01:00 committed by GitHub
commit c617b15f70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 33 deletions

View file

@ -31,27 +31,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) : {};
}
}