@graphql-inspector/action
Version:
GraphQL Inspector functionality for GitHub Actions
35 lines (34 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAssociatedPullRequest = exports.getCurrentCommitSha = void 0;
const tslib_1 = require("tslib");
const child_process_1 = require("child_process");
const github = tslib_1.__importStar(require("@actions/github"));
function getCurrentCommitSha() {
const sha = (0, child_process_1.execSync)(`git rev-parse HEAD`).toString().trim();
try {
const msg = (0, child_process_1.execSync)(`git show ${sha} -s --format=%s`).toString().trim();
const PR_MSG = /Merge (\w+) into \w+/i;
if (PR_MSG.test(msg)) {
const result = PR_MSG.exec(msg);
if (result) {
return result[1];
}
}
}
catch (e) {
//
}
return sha;
}
exports.getCurrentCommitSha = getCurrentCommitSha;
function getAssociatedPullRequest(octokit, commitSha) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const result = yield octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls', Object.assign(Object.assign({}, github.context.repo), { commit_sha: commitSha, mediaType: {
format: 'json',
previews: ['groot'],
} }));
return result.data.length > 0 ? result.data[0] : null;
});
}
exports.getAssociatedPullRequest = getAssociatedPullRequest;