mirror of
https://github.com/actions/setup-dotnet.git
synced 2024-11-23 20:11:07 +07:00
45 lines
1.7 KiB
JavaScript
45 lines
1.7 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
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 {
|
||
|
process.stdout.write(`GITHUB_EVENT_PATH ${process.env.GITHUB_EVENT_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;
|
||
|
}
|
||
|
get issue() {
|
||
|
const payload = this.payload;
|
||
|
return Object.assign(Object.assign({}, this.repo), { number: (payload.issue || payload.pullRequest || 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
|