@graphql-inspector/action
Version:
GraphQL Inspector functionality for GitHub Actions
36 lines (35 loc) • 1.22 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCurrentCommitSha = getCurrentCommitSha;
exports.getAssociatedPullRequest = getAssociatedPullRequest;
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;
}
async function getAssociatedPullRequest(octokit, commitSha) {
const result = await octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls', {
...github.context.repo,
commit_sha: commitSha,
mediaType: {
format: 'json',
previews: ['groot'],
},
});
return result.data.length > 0 ? result.data[0] : null;
}
;