Skip to content

Commit

Permalink
infra: getPrNumber fix (anuraghazra#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra authored Aug 10, 2020
1 parent 7a4b093 commit 792e5a4
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions scripts/preview-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 792e5a4

Please sign in to comment.