Created
October 15, 2020 00:19
-
-
Save bigethan/926634ba740a87b3452f4158df3e2140 to your computer and use it in GitHub Desktop.
Adds the additions/deletions/files_changed to the pull request listing. Requires you to edit the script after installing it with username and a personal access token with "repo" permissions. To install click the `Raw` button and your userscript extension will take it from there
This file contains hidden or 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 PR Size on PR List | |
// @namespace http://bigethan.com/ | |
// @version 0.1 | |
// @description give a sense of PR size when looking at the PR board | |
// @author @bigethan | |
// @match https://github.com/*/*/pulls* | |
// @grant none | |
// ==/UserScript== | |
(function(document) { | |
'use strict'; | |
const user = "<your username>"; | |
// Generate token here: https://github.com/settings/tokens | |
const token = "<token with repo access>"; | |
const creds = `${user}:${token}`; | |
const auth = btoa(creds); | |
const options = { | |
mode: "cors", | |
headers: { | |
Authorization: "Basic " + auth, | |
}, | |
}; | |
const api = (resource) => { | |
return fetch(`${resource}`, options).then( | |
(response) => response.json(), | |
(err) => console.error("Error fetching", err) | |
); | |
}; | |
let orgNRepo = window.location.pathname.split('/').slice(1,3).join('/') | |
api(`https://api.github.com/repos/${orgNRepo}/pulls`).then( | |
(pullJson) => { | |
// console.log(pullJson) | |
pullJson.forEach((pr) => { | |
api(pr.url).then( | |
(prJson) => { | |
// console.log(prJson) | |
let statsEl = document.createElement("small"); | |
statsEl.classList.add("text-small", "text-gray"); | |
statsEl.innerText = ` [${prJson.additions}/${prJson.deletions}/${prJson.changed_files} ]`; | |
let prEl = document.getElementById(`issue_${prJson.number}_link`); | |
prEl.append(statsEl); | |
}, | |
(err) => console.error("Error parsing", err) | |
); | |
}); | |
}, | |
(err) => console.error("Error parsing", err) | |
); | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment