Unverified Commit 792e5a4b authored by Anurag Hazra's avatar Anurag Hazra Committed by GitHub
Browse files

infra: getPrNumber fix (#357)

parent 7a4b0930
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -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;
  }

  return pullRequest.number;
}
  const [, pullRequestId] = result;
  return pullRequestId;
};

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",