Created
July 7, 2019 15:58
-
-
Save EmilyRosina/fd44104555590b4db336a871331dbf17 to your computer and use it in GitHub Desktop.
Get all Zenhub estimate totals from any given board.
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
var groupedEstimates = {} | |
// get all pipelines | |
var allPipelines = document.querySelectorAll('.zhc-pipeline') | |
allPipelines.forEach((pipeline) => { | |
const key = (pipeline.querySelector('div.zhc-pipeline-header__info') || {}).innerText | |
if (key) { | |
groupedEstimates[key] = {} | |
// initialise properties for each pipeline | |
const allCardsWithEstimates = [...pipeline.querySelectorAll('.zhc-badge__value')] | |
.map(({ offsetParent }) => offsetParent) | |
allCardsWithEstimates.forEach((card) => { | |
const { alt = 'unassigned', src = '' } = card.querySelector('.zhc-avatar img') || {} | |
const username = alt.split(' ')[0] | |
/* const avatar = src */ // re-enable if want to use as a extension | |
const estimate = card.querySelector('.zhc-badge__value').innerText | |
// set keys on each pipeline for each user, instantiate the avatar | |
if (!groupedEstimates[key][username]) groupedEstimates[key][username] = 0 | |
// add the estimate to the running total | |
groupedEstimates[key][username] += Number(estimate) | |
}) | |
} | |
}) | |
var totals = {} | |
for (const users of Object.values(groupedEstimates)) { | |
if (Object.keys(users).length) { | |
for (const [username, estimate] of Object.entries(users)) { | |
if (!totals[username]) totals[username] = 0 | |
totals[username] += Number(estimate) | |
} | |
} | |
} | |
console.log(` | |
============================= | |
ESTIMATES PER PIPELINE | |
=============================\n\n` | |
) | |
for (const [key, value] of Object.entries(groupedEstimates)) console.log(key, value) | |
Object.entries(groupedEstimates), | |
console.log(` | |
============================= | |
TOTALS | |
=============================\n`, | |
totals | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment