Last active
February 25, 2022 09:16
-
-
Save lgk-bsw/c229ce3f4fa4ca3dcf55132fc9f3f8c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use this together with this browser extension (Chrome/Edge) and enable it for GitHub: | |
// https://chrome.google.com/webstore/detail/custom-javascript-for-web/ddbjnfjiigjmcpcpkmhogomapikjbjdk | |
// The following code checks if your branch you want to merge, contains "lts-" | |
// and offers to set the correct base branch. | |
if (location.pathname.includes("/bruegmann/florence/compare/")) { | |
let params = location.pathname.split("/") | |
let compareBranchs = params[params.length - 1].split("...") | |
if ((compareBranchs.length === 1 && compareBranchs[0].startsWith("lts-")) || (compareBranchs[1].startsWith("lts-") && !compareBranchs[0].startsWith("lts-"))) { | |
// lts-* branch should not merged to master | |
console.log("Should redirect") | |
const secondBranch = compareBranchs.length === 1 ? compareBranchs[0] : compareBranchs[1] | |
const parts = secondBranch.split("-") | |
const baseBranch = `${parts[0]}-${parts[1]}` | |
compareBranchs = [baseBranch, secondBranch] | |
params[params.length - 1] = compareBranchs.join("...") | |
if (confirm(`Merge changes to ${baseBranch}?`)) { | |
location.pathname = params.join("/") | |
} | |
} | |
} | |
// The following code presents a button on the commit page of PRs to show you | |
// the commands for `git cherry-pick` | |
if (location.pathname.includes("/pull/") && location.pathname.includes("/commits")) { | |
const tabnav = document.querySelector(".tabnav") | |
if (tabnav) { | |
let div = document.createElement("div") | |
div.innerHTML = `<button class="btn mb-3" id="bsw-show-cherry-pick">Show cherry-pick commands</button>` | |
tabnav.parentNode.insertBefore(div, tabnav.nextSibling) | |
const btn = document.getElementById("bsw-show-cherry-pick") | |
btn.addEventListener("click", () => { | |
btn.remove() | |
let queries = [] | |
const rows = document.querySelectorAll(".TimelineItem-body .Box-row") | |
for (const r of rows) { | |
const label = r.querySelector(".Details .Link--primary") | |
const link = r.querySelector("a.BtnGroup-item") | |
const splitted = link.href.split("/") | |
queries.push(`${label.innerText}<br><code>git cherry-pick ${splitted[splitted.length - 1]}</code>`) | |
} | |
const start = '<label class="d-block px-3 py-2"><input type="checkbox" class="mr-1">' | |
document.querySelector(".pull-request-tab-content").innerHTML = start + queries.join('</label>' + start) | |
}) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment