From dd50451ae42c038ac307f346d0e225c19a4237f9 Mon Sep 17 00:00:00 2001 From: Bauke Date: Sun, 24 Jun 2018 23:24:21 +0200 Subject: [PATCH] Add average issue/day and list of issues from each label --- main.js | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index e568dd7..d9295d4 100644 --- a/main.js +++ b/main.js @@ -162,14 +162,19 @@ function createStatistics() { statistics += `${opened.length} issues were opened and ` statistics += `${closed.length} issues were closed.\n\n` + const averageOpenPerDay = (opened.length / 30).toFixed(2) + const averageClosePerDay = (closed.length / 30).toFixed(2) + statistics += `An average of ${averageOpenPerDay} issues were opened ` + statistics += `and ${averageClosePerDay} issues were closed each day.\n\n` + let averageClosedDays let averageClosedHours for (const file of closed) { const issue = require(file.path) const openedAt = new Date(issue.created_at) const closedAt = new Date(issue.closed_at) - const diffDays = Math.floor((closedAt - openedAt) / (1000 * 60 * 60 * 24)) - const diffHours = Math.floor((closedAt - openedAt) / (1000 * 60 * 60)) + const diffDays = (closedAt - openedAt) / (1000 * 60 * 60 * 24) + const diffHours = (closedAt - openedAt) / (1000 * 60 * 60) averageClosedDays = (typeof averageClosedDays === 'undefined') ? averageClosedDays = diffDays @@ -178,11 +183,42 @@ function createStatistics() { ? averageClosedHours = diffHours : averageClosedHours += diffHours } - averageClosedDays = Math.floor(averageClosedDays / closed.length) - averageClosedHours = Math.floor(averageClosedHours / closed.length) + averageClosedDays = (averageClosedDays / closed.length).toFixed(2) + averageClosedHours = (averageClosedHours / closed.length).toFixed(2) statistics += `The average time to close issues was ${averageClosedDays} days ` statistics += `or ${averageClosedHours} hours.\n\n` + let labels = {} + for (const file of opened) { + const issue = require(file.path) + if (issue.closed_at !== null) continue + for (const label of issue.labels) { + if (typeof labels[label] === 'undefined') labels[label] = 1 + else labels[label]++ + } + } + + statistics += 'Total amount of labels assigned to currently open issues:\n' + + for (const label in labels) { + statistics += `* [${label}](https://gitlab.com/tildes/tildes/issues?state=opened&label_name%5B%5D=${label.replace(' ', '+')}): ${labels[label]} times.\n` + } + + labels = {} + for (const file of closed) { + const issue = require(file.path) + for (const label of issue.labels) { + if (typeof labels[label] === 'undefined') labels[label] = 1 + else labels[label]++ + } + } + + statistics += '\nTotal amount of labels assigned to closed issues:\n' + + for (const label in labels) { + statistics += `* [${label}](https://gitlab.com/tildes/tildes/issues?state=closed&label_name%5B%5D=${label.replace(' ', '+')}): ${labels[label]} times.\n` + } + fs.writeFileSync(path.join(__dirname, year, month, 'statistics.md'), statistics, {encoding: 'UTF-8'}) }