Skip to content

Instantly share code, notes, and snippets.

@scawp
Last active Feb 23, 2022
Embed
What would you like to do?
A UserScript to see which Github forks are ahead and other info
// ==UserScript==
// @name Github is Fork Ahead
// @version 0.1
// @description Shows how far ahead/behind a fork is from upstream when viewing fork page on github
// @match https://github.com/*/*/network/members
// ==/UserScript==
async function fetchLastCommit(partial_url) {
const response = await fetch('https://api.github.com/repos/' + partial_url + '/commits?page=1&per_page=1')
const commitJson = await response.json();
return commitJson;
}
async function fetchFork(fork_url) {
const response = await fetch(fork_url)
const responseText = await response.text();
return responseText;
}
// some of this code is based on https://stackoverflow.com/a/68335748
const repo_tags = [...document.querySelectorAll('div.repo a:last-of-type')].slice(1);
for (const repo_tag of repo_tags) {
const partial_url = repo_tag.href.replace("https://github.com/","")
fetchFork(repo_tag.href).then(responseText => {
var ahead_text = responseText.match(/This branch is.*/).pop().replace('This branch', '');
fetchLastCommit(partial_url).then(commitJson => {
var formatted_date = new Date(commitJson[0].commit.author.date).toLocaleString();
repo_tag.outerHTML += ("<span>" + ahead_text +
" | last-author: <a href='/" + commitJson[0].commit.author.name + "'>" + commitJson[0].commit.author.name + "</a>" +
" | commit-date: " + formatted_date +
" | message: " + commitJson[0].commit.message +
"</span>")
});
});
}
@scawp
Copy link
Author

scawp commented Dec 30, 2021

Screenshot:

image_2021-12-30_164122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment