github: add serverURL annd provenanceBuilderID

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-01-25 03:20:18 +01:00
parent 380149da27
commit b03f6a405c
3 changed files with 48 additions and 3 deletions

View File

@@ -14,7 +14,9 @@ interface Jwt extends JwtPayload {
export class GitHub {
private static instance?: GitHub;
static getInstance = (): GitHub => (GitHub.instance = GitHub.instance ?? new GitHub());
private static _serverURL: string;
private static _gitContext: string;
private static _provenanceBuilderID: string;
private constructor() {
let ref = this.ref();
@@ -24,7 +26,13 @@ export class GitHub {
if (github.context.sha && !ref.startsWith(`refs/pull/`)) {
ref = github.context.sha;
}
GitHub._gitContext = `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${github.context.repo.owner}/${github.context.repo.repo}.git#${ref}`;
GitHub._serverURL = process.env.GITHUB_SERVER_URL || 'https://github.com';
GitHub._gitContext = `${GitHub._serverURL}/${github.context.repo.owner}/${github.context.repo.repo}.git#${ref}`;
GitHub._provenanceBuilderID = `${GitHub._serverURL}/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`;
}
public reset() {
GitHub.instance = undefined;
}
public context(): Context {
@@ -35,10 +43,18 @@ export class GitHub {
return github.context.ref;
}
public serverURL() {
return GitHub._serverURL;
}
public gitContext() {
return GitHub._gitContext;
}
public provenanceBuilderID() {
return GitHub._provenanceBuilderID;
}
private payload(): Payload {
return github.context.payload;
}