UNPKG

@codechecks/client

Version:

Open source platform for code review automation

55 lines 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const errors_1 = require("../utils/errors"); const fs_1 = require("fs"); const lodash_1 = require("lodash"); const path_1 = require("path"); // github actions have explicit event for PR creation but we cant use it since it fired only once // in future we need to build a mechanism to get pull request information using API since it's impossible to get from the inside the PR class GithubActions { constructor(env) { this.env = env; } isCurrentlyRunning() { return !!this.env["GITHUB_WORKFLOW"]; } getPullRequestID() { const event = this.getEvent(); return event.number; } getCurrentSha() { const event = this.getEvent(); const sha = lodash_1.get(event, "pull_request.head.sha") || this.env["GITHUB_SHA"]; if (!sha) { throw errors_1.crash("Couldn't get target SHA"); } return sha; } isFork() { const event = this.getEvent(); return lodash_1.get(event, "pull_request.head.repo.fork") || false; } getProjectSlug() { const event = this.getEvent(); if (this.isFork()) { return lodash_1.get(event, "pull_request.base.repo.full_name"); } return lodash_1.get(event, "pull_request.head.repo.full_name") || lodash_1.get(event, "repository.full_name"); } supportsSpeculativeBranchSelection() { return true; } getEvent() { // tslint:disable-next-line let eventPath = this.env["GITHUB_EVENT_PATH"]; // workaround for tests if (eventPath.startsWith(".")) { eventPath = path_1.join(__dirname, eventPath); } const eventFile = fs_1.readFileSync(eventPath, "utf-8"); const event = JSON.parse(eventFile); return event; } } exports.GithubActions = GithubActions; //# sourceMappingURL=GithubActions.js.map