-
-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Request] Update fork button #88
Comments
Hi @Bluscream! I haven't tested it, but are you saying that just linking to
Will trigger an update fork? And you want a new "Update fork" link added in the same place as in the screenshot? |
Yes and yes, the two existing buttons will only create a pr from fork to source not from source to fork |
Please test out this userscript, let me know if you encounter any issues with weird branch names, or anything: // ==UserScript==
// @name GitHub Update Fork
// @version 0.1.1
// @description A userscript that adds a link to update your fork
// @license MIT
// @author Rob Garrison
// @namespace https://github.com/Mottie
// @include https://github.com/*
// @run-at document-idle
// @grant none
// @icon https://github.githubassets.com/pinned-octocat.svg
// ==/UserScript==
(() => {
"use strict";
function getUpstreamBranch(fork, info) {
const upstreamLink = $("a", fork);
// Look for "commit behind" or "commits behind"
if (upstreamLink && info && /commits?\sbehind/.test(info.textContent)) {
// forked from link text ":user/:repo"
const user = upstreamLink.textContent.split("/")[0];
const regexp = new RegExp(`(${user.trim()}:[-\\w.]+)`);
// The match will include the sentence period because branch names may
// include a version number, e.g. "user:my-branch-v1.0"
const branch = (info.textContent.match(regexp) || [])[0];
return branch ? branch.substring(0, branch.length - 1) : null;
}
return null;
}
function getUserBranch() {
// The branch selector may contain a truncated branch name, so use the url
const path = window.location.pathname;
const index = path.indexOf("/tree/");
return index > -1 ? path.substring(index + 6, path.length) : "master";
}
function addLink(fork, info) {
const branch = getUpstreamBranch(fork, info);
if (branch) {
const userBranch = getUserBranch();
const compareLink = $("a[href*='/compare']", info);
const prLink = $("a[href*='/pull']", info);
const link = prLink.cloneNode();
// https://github.com/<FORK>/<REPO>/compare/<BRANCH>...<SOURCE>:<BRANCH>
link.href = `${compareLink.href}/${userBranch}...${branch}`;
link.classList.add("ghuf-update-link");
link.appendChild($("svg", prLink).cloneNode(true));
link.appendChild(document.createTextNode(" Update fork"));
prLink.insertAdjacentElement("beforebegin", link);
}
}
function init() {
const fork = $(".fork-flag");
const info = $(".branch-infobar");
if (fork && info) {
addLink(fork, info);
}
}
function $(str, el = document) {
return el.querySelector(str);
}
document.addEventListener("pjax:end", init);
init();
})(); |
It doesn't show the button on https://github.com/Bluscream/VRCModLoader |
Oh, it's only showing when you have "commits behind". I didn't think you'd need to update from upstream if you're "commits ahead"; but it's a comparison, so maybe? |
Ah okay, well then i'm going to test it next time i am behind :) |
I've updated the userscript. It wasn't checking for the update on the master branch properly. |
It works fine |
One thing, could it fill the PR name automatically? |
Update it with what name? |
Maybe something like "Update fork" or |
I finally added this userscript to the repository: https://github.com/Mottie/GitHub-userscripts/wiki/GitHub-update-fork I never got around to getting it to fill in the PR name automatically; this would require it saving the name across several page loads, and I'm just not confident that it would work well. |
Maybe this can be interesting as a userscript; Github Compare link/URL generator |
Something like that and it should point to
The text was updated successfully, but these errors were encountered: