Skip to content

Instantly share code, notes, and snippets.

@EmilyRosina
Last active July 7, 2019 16:05
Show Gist options
  • Save EmilyRosina/a3bfcc897af056015ef0d70842c2dba3 to your computer and use it in GitHub Desktop.
Save EmilyRosina/a3bfcc897af056015ef0d70842c2dba3 to your computer and use it in GitHub Desktop.
Get all Zenhub estimate totals from any given board.
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) {
// initialise properties for each pipeline
groupedEstimates[key] = {}
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 estimate value too 0
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
)
@EmilyRosina
Copy link
Author

var is used so you can copy/paste as many times as you like without the console complaining that variable is already declared

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment