only review changes between pushes

This commit is contained in:
Ville Saukkonen 2023-04-22 17:42:09 +03:00
parent 3413a8e8a0
commit d60ebfdf3c
3 changed files with 32 additions and 29 deletions

26
dist/index.js vendored

@ -216,14 +216,20 @@ function main() {
diff = yield getDiff(prDetails.owner, prDetails.repo, prDetails.pull_number);
}
else if (process.env.GITHUB_EVENT_NAME === "push") {
const diffUrl = yield getChangedFiles(prDetails.owner, prDetails.repo, baseSha, headSha);
if (diffUrl) {
const diffResponse = yield octokit.request({ url: diffUrl });
diff = diffResponse.data;
}
else {
diff = null;
}
const pushEvent = JSON.parse((0, fs_1.readFileSync)(process.env.GITHUB_EVENT_PATH || "", "utf8"));
const newBaseSha = pushEvent.before;
const newHeadSha = pushEvent.after;
const response = yield octokit.repos.compareCommits({
owner: prDetails.owner,
repo: prDetails.repo,
base: newBaseSha,
head: newHeadSha,
});
diff = response.data.diff_url
? yield octokit
.request({ url: response.data.diff_url })
.then((res) => res.data)
: null;
}
else {
console.log("Unsupported event:", process.env.GITHUB_EVENT_NAME);
@ -247,10 +253,6 @@ function main() {
}
});
}
main().catch((error) => {
console.error("Error:", error);
process.exit(1);
});
/***/ }),

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

@ -225,18 +225,24 @@ async function main() {
prDetails.pull_number
);
} else if (process.env.GITHUB_EVENT_NAME === "push") {
const diffUrl = await getChangedFiles(
prDetails.owner,
prDetails.repo,
baseSha,
headSha
const pushEvent = JSON.parse(
readFileSync(process.env.GITHUB_EVENT_PATH || "", "utf8")
);
if (diffUrl) {
const diffResponse = await octokit.request({ url: diffUrl });
diff = diffResponse.data;
} else {
diff = null;
}
const newBaseSha = pushEvent.before;
const newHeadSha = pushEvent.after;
const response = await octokit.repos.compareCommits({
owner: prDetails.owner,
repo: prDetails.repo,
base: newBaseSha,
head: newHeadSha,
});
diff = response.data.diff_url
? await octokit
.request({ url: response.data.diff_url })
.then((res) => res.data)
: null;
} else {
console.log("Unsupported event:", process.env.GITHUB_EVENT_NAME);
return;
@ -270,8 +276,3 @@ async function main() {
);
}
}
main().catch((error) => {
console.error("Error:", error);
process.exit(1);
});