Skip to content

Instantly share code, notes, and snippets.

@UnquietCode
Last active January 22, 2019 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UnquietCode/c8dba8a5e8f0bea43ac7aa75f0277142 to your computer and use it in GitHub Desktop.
Save UnquietCode/c8dba8a5e8f0bea43ac7aa75f0277142 to your computer and use it in GitHub Desktop.
sum github issue labels

Bookmarklet Usage

  1. copy the bookmarklet code below
  2. create a new bookmark with the code as the URL
  3. navigate to an issues listing view in GitHub, like a milestone view
  4. click the bookmark, an alert box will show you the results

Script Usage

  1. navigate to an issues listing view in GitHub, like a milestone view
  2. copy the code snippet
  3. open the browsers JavaScript developer console on the page
  4. paste the code into the console and run it
  5. the console output contains the results

Notes

  • the issues need a label like size: 1 or size : 1
  • sums everything it sees on the page
  • executes in a closure so it can be re-run if needed
  • will break if GitHub styles ever change significantly
    • looks for nodes with the IssueLabel class and title attribute
(function() {
let sum = 0;
let reducer = function(x) {
let size = x.title;
let split = size.indexOf(':') + 1;
size = size.substring(split).trim();
sum += Number(size);
};
let nodes = document.querySelectorAll(".IssueLabel[title^=\"size\"]");
nodes.forEach(reducer);
alert("total size is "+sum+" days ("+(sum*8)+" hours)");
})();
javascript:(function()%7B(function()%20%7Blet%20sum%20%3D%200%3Blet%20reducer%20%3D%20function(x)%20%7Blet%20size%20%3D%20x.title%3Blet%20split%20%3D%20size.indexOf('%3A')%20%2B%201%3Bsize%20%3D%20size.substring(split).trim()%3Bsum%20%2B%3D%20Number(size)%3B%7D%3Blet%20nodes%20%3D%20document.querySelectorAll(%22.IssueLabel%5Btitle%5E%3D%5C%22size%5C%22%5D%22)%3Bnodes.forEach(reducer)%3Balert(%22total%20size%20is%20%22%2Bsum%2B%22%20days%20(%22%2B(sum*8)%2B%22%20hours)%22)%3B%7D)()%7D)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment