mirror of
https://github.com/Aviortheking/codestats-readme.git
synced 2025-04-22 10:42:08 +00:00
infra: getPrNumber fix (#357)
This commit is contained in:
parent
7a4b0930fc
commit
792e5a4ba7
@ -3,21 +3,25 @@ const github = require("@actions/github");
|
|||||||
const parse = require("parse-diff");
|
const parse = require("parse-diff");
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
const parsePullRequestId = (githubRef) => {
|
function getPrNumber() {
|
||||||
const result = /refs\/pull\/(\d+)\/merge/g.exec(githubRef);
|
const pullRequest = github.context.payload.pull_request;
|
||||||
if (!result) {
|
if (!pullRequest) {
|
||||||
console.log("Reference not found.");
|
return undefined;
|
||||||
return 297;
|
}
|
||||||
|
|
||||||
|
return pullRequest.number;
|
||||||
}
|
}
|
||||||
const [, pullRequestId] = result;
|
|
||||||
return pullRequestId;
|
|
||||||
};
|
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const token = core.getInput("token");
|
const token = core.getInput("token");
|
||||||
const octokit = github.getOctokit(token || process.env.PERSONAL_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({
|
let res = await octokit.pulls.get({
|
||||||
owner: "anuraghazra",
|
owner: "anuraghazra",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user