mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
50 lines
1.9 KiB
JavaScript
50 lines
1.9 KiB
JavaScript
"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
|