Skip to content

Instantly share code, notes, and snippets.

@scawp
Last active August 3, 2023 20:44
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scawp/087114f5417497542bf289715bf128fd to your computer and use it in GitHub Desktop.
Save scawp/087114f5417497542bf289715bf128fd to your computer and use it in GitHub Desktop.
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