summaryrefslogtreecommitdiffstats
path: root/extra/rebase-pr.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-11-26 09:28:28 +0100
committerDaniel Baumann <daniel@debian.org>2024-11-26 12:25:58 +0100
commita1882b67c41fe9901a0cd8059b5cc78a5beadec0 (patch)
tree2a24507c67aa99a15416707b2f7e645142230ed8 /extra/rebase-pr.js
parentInitial commit. (diff)
downloaduptime-kuma-upstream.tar.xz
uptime-kuma-upstream.zip
Adding upstream version 2.0.0~beta.0+dfsg.upstream/2.0.0_beta.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'extra/rebase-pr.js')
-rw-r--r--extra/rebase-pr.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/extra/rebase-pr.js b/extra/rebase-pr.js
new file mode 100644
index 0000000..4921d2e
--- /dev/null
+++ b/extra/rebase-pr.js
@@ -0,0 +1,40 @@
+const { execSync } = require("child_process");
+
+/**
+ * Rebase a PR onto such as 1.23.X or master
+ * @returns {Promise<void>}
+ */
+async function main() {
+ const branch = process.argv[2];
+
+ // Use gh to get current branch's pr id
+ let currentBranchPRID = execSync("gh pr view --json number --jq \".number\"").toString().trim();
+ 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()).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[0].oid;
+ console.log("Oldest commit id of this pr:", oldestCommitID);
+
+ // Get the latest commit id of the target branch
+ const latestCommitID = execSync(`git rev-parse origin/${branch}`).toString().trim();
+ console.log("Latest commit id of " + branch + ":", latestCommitID);
+
+ // Get the original parent commit id of the oldest commit
+ const originalParentCommitID = execSync(`git log --pretty=%P -n 1 "${oldestCommitID}"`).toString().trim();
+ console.log("Original parent commit id of the oldest commit:", originalParentCommitID);
+
+ // Rebase the pr onto the target branch
+ execSync(`git rebase --onto ${latestCommitID} ${originalParentCommitID}`);
+}
+
+main();