mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
A small tool for rebasing pr (#3781)
This commit is contained in:
parent
4156c78c09
commit
34b9fe2ffe
2 changed files with 36 additions and 1 deletions
34
extra/rebase-pr.js
Normal file
34
extra/rebase-pr.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
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());
|
||||
console.log("Found commits: ", prCommits.commits.length);
|
||||
|
||||
// Get the oldest commit id
|
||||
const oldestCommitID = prCommits.commits[prCommits.commits.length - 1].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();
|
|
@ -72,7 +72,8 @@
|
|||
"deploy-demo-server": "node extra/deploy-demo-server.js",
|
||||
"sort-contributors": "node extra/sort-contributors.js",
|
||||
"quick-run-nightly": "docker run --rm --env NODE_ENV=development -p 3001:3001 louislam/uptime-kuma:nightly2",
|
||||
"start-dev-container": "cd docker && docker-compose -f docker-compose-dev.yml up --force-recreate"
|
||||
"start-dev-container": "cd docker && docker-compose -f docker-compose-dev.yml up --force-recreate",
|
||||
"rebase-pr-to-1.23.X": "node extra/rebase-pr.js 1.23.X"
|
||||
},
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "~1.7.3",
|
||||
|
|
Loading…
Reference in a new issue