-
-
Save cannibalox/d0f0929bf85709ceaeeb69fc16c7157e to your computer and use it in GitHub Desktop.
A UserScript to see which Github forks are ahead and other info
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
// ==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>") | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment