From 8c24b02fceeecf8ea688646fed05154258bd6325 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Thu, 21 Sep 2023 19:54:52 +0800 Subject: [PATCH] Fix rebase-pr.js --- extra/rebase-pr.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/extra/rebase-pr.js b/extra/rebase-pr.js index 65c41094f..4921d2e7c 100644 --- a/extra/rebase-pr.js +++ b/extra/rebase-pr.js @@ -12,11 +12,17 @@ async function main() { console.log("Pr ID: ", currentBranchPRID); // Use gh commend to get pr commits - const prCommits = JSON.parse(execSync(`gh pr view ${currentBranchPRID} --json commits`).toString().trim()); - console.log("Found commits: ", prCommits.commits.length); + const prCommits = JSON.parse(execSync(`gh pr view ${currentBranchPRID} --json commits`).toString().trim()).commits; + + 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 - const oldestCommitID = prCommits.commits[prCommits.commits.length - 1].oid; + const oldestCommitID = prCommits[0].oid; console.log("Oldest commit id of this pr:", oldestCommitID); // Get the latest commit id of the target branch