infra: getPrNumber fix (#357)

This commit is contained in:
Anurag Hazra 2020-08-10 20:01:19 +05:30 committed by GitHub
parent 7a4b0930fc
commit 792e5a4ba7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,21 +3,25 @@ const github = require("@actions/github");
const parse = require("parse-diff");
require("dotenv").config();
const parsePullRequestId = (githubRef) => {
const result = /refs\/pull\/(\d+)\/merge/g.exec(githubRef);
if (!result) {
console.log("Reference not found.");
return 297;
function getPrNumber() {
const pullRequest = github.context.payload.pull_request;
if (!pullRequest) {
return undefined;
}
const [, pullRequestId] = result;
return pullRequestId;
};
return pullRequest.number;
}
async function run() {
try {
const token = core.getInput("token");
const octokit = github.getOctokit(token || process.env.PERSONAL_TOKEN);
const pullRequestId = parsePullRequestId(process.env.GITHUB_REF);
const pullRequestId = getPrNumber();
if (!pullRequestId) {
console.log("PR not found");
return;
}
let res = await octokit.pulls.get({
owner: "anuraghazra",