You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.9 KiB
50 lines
1.9 KiB
"use strict"; |
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.Context = void 0; |
|
const fs_1 = require("fs"); |
|
const os_1 = require("os"); |
|
class Context { |
|
/** |
|
* Hydrate the context from the environment |
|
*/ |
|
constructor() { |
|
this.payload = {}; |
|
if (process.env.GITHUB_EVENT_PATH) { |
|
if (fs_1.existsSync(process.env.GITHUB_EVENT_PATH)) { |
|
this.payload = JSON.parse(fs_1.readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' })); |
|
} |
|
else { |
|
const path = process.env.GITHUB_EVENT_PATH; |
|
process.stdout.write(`GITHUB_EVENT_PATH ${path} does not exist${os_1.EOL}`); |
|
} |
|
} |
|
this.eventName = process.env.GITHUB_EVENT_NAME; |
|
this.sha = process.env.GITHUB_SHA; |
|
this.ref = process.env.GITHUB_REF; |
|
this.workflow = process.env.GITHUB_WORKFLOW; |
|
this.action = process.env.GITHUB_ACTION; |
|
this.actor = process.env.GITHUB_ACTOR; |
|
this.job = process.env.GITHUB_JOB; |
|
this.runNumber = parseInt(process.env.GITHUB_RUN_NUMBER, 10); |
|
this.runId = parseInt(process.env.GITHUB_RUN_ID, 10); |
|
} |
|
get issue() { |
|
const payload = this.payload; |
|
return Object.assign(Object.assign({}, this.repo), { number: (payload.issue || payload.pull_request || payload).number }); |
|
} |
|
get repo() { |
|
if (process.env.GITHUB_REPOSITORY) { |
|
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); |
|
return { owner, repo }; |
|
} |
|
if (this.payload.repository) { |
|
return { |
|
owner: this.payload.repository.owner.login, |
|
repo: this.payload.repository.name |
|
}; |
|
} |
|
throw new Error("context.repo requires a GITHUB_REPOSITORY environment variable like 'owner/repo'"); |
|
} |
|
} |
|
exports.Context = Context; |
|
//# sourceMappingURL=context.js.map
|