-
Notifications
You must be signed in to change notification settings - Fork 0
User scripts
Joern Bernhardt edited this page Oct 11, 2018
·
9 revisions
This is a small collection of scripts to readily be used as user scripts. If you want to share something, feel free!
const LABEL_TO_LOOK_FOR = "#bug";
const result = flattenTodos(list)
.filter(todo => todo.labels.some(l => l === LABEL_TO_LOOK_FOR))
.map(todo => todo.title);
console.log(result.join("\n"));
function flattenTodos(list) {
return list.reduce(
(all, item) => [...all, item, ...flattenTodos(item.children)],
[]
);
}
const result = flattenTodos(list)
.reduce((trackedTimes, todo) => [...trackedTimes, ...todo.trackedTimes], [])
.reduce((seconds, entry) => seconds + timeToSeconds(entry.trackedTime), 0);
alert(`Time tracked: ${secondsToTime(result)} (${result / 60 / 60 / 8} workdays [w/ 8 hours per day])`);
function secondsToTime(seconds) {
const h = Math.floor(seconds / 60 / 60);
const m = Math.floor((seconds % (60 * 60)) / 60);
const s = seconds % 60;
const nf = n => `${n < 10 ? "0" : ""}${n}`;
return [h, m, s].map(nf).join(":");
}
function timeToSeconds(time) {
const [hours, minutes, seconds] = time.split(":").map(num => parseInt(num));
return hours * 60 * 60 + minutes * 60 + seconds;
}
function flattenTodos(list) {
return list.reduce(
(all, item) => [...all, item, ...flattenTodos(item.children)],
[]
);
}