@graphql-inspector/action
Version:
GraphQL Inspector functionality for GitHub Actions
30 lines (29 loc) • 1.06 kB
JavaScript
import { __awaiter } from "tslib";
import { execSync } from 'child_process';
import * as github from '@actions/github';
export function getCurrentCommitSha() {
const sha = execSync(`git rev-parse HEAD`).toString().trim();
try {
const msg = 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;
}
export function getAssociatedPullRequest(octokit, commitSha) {
return __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;
});
}