Fix rebase-pr.js

This commit is contained in:
Louis Lam 2023-09-21 19:54:52 +08:00
parent 34b9fe2ffe
commit 8c24b02fce

View file

@ -12,11 +12,17 @@ async function main() {
console.log("Pr ID: ", currentBranchPRID); console.log("Pr ID: ", currentBranchPRID);
// Use gh commend to get pr commits // Use gh commend to get pr commits
const prCommits = JSON.parse(execSync(`gh pr view ${currentBranchPRID} --json commits`).toString().trim()); const prCommits = JSON.parse(execSync(`gh pr view ${currentBranchPRID} --json commits`).toString().trim()).commits;
console.log("Found commits: ", prCommits.commits.length);
console.log("Found commits: ", prCommits.length);
// Sort the commits by authoredDate
prCommits.sort((a, b) => {
return new Date(a.authoredDate) - new Date(b.authoredDate);
});
// Get the oldest commit id // Get the oldest commit id
const oldestCommitID = prCommits.commits[prCommits.commits.length - 1].oid; const oldestCommitID = prCommits[0].oid;
console.log("Oldest commit id of this pr:", oldestCommitID); console.log("Oldest commit id of this pr:", oldestCommitID);
// Get the latest commit id of the target branch // Get the latest commit id of the target branch