2018-06-24 16:38:50 +00:00
|
|
|
const config = require('./config.json')
|
2018-06-24 17:55:47 +00:00
|
|
|
const df = require('date-format')
|
2018-06-24 16:38:50 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
const Gitlab = require('gitlab/dist/es5').default
|
|
|
|
const klaw = require('klaw-sync')
|
|
|
|
const path = require('path')
|
2018-06-26 17:26:53 +00:00
|
|
|
const { avgTime, freqUsers, labelsAlphabet } = require('./statistics')
|
2018-06-24 16:38:50 +00:00
|
|
|
|
|
|
|
const api = new Gitlab({
|
|
|
|
token: config.token
|
|
|
|
})
|
|
|
|
|
|
|
|
const months = [
|
|
|
|
'January',
|
|
|
|
'February',
|
|
|
|
'March',
|
|
|
|
'April',
|
|
|
|
'May',
|
|
|
|
'June',
|
|
|
|
'July',
|
|
|
|
'August',
|
|
|
|
'September',
|
|
|
|
'October',
|
|
|
|
'November',
|
|
|
|
'December'
|
|
|
|
]
|
|
|
|
|
|
|
|
const year = new Date().getFullYear().toString()
|
|
|
|
const month = months[new Date().getMonth()]
|
|
|
|
if (!fs.existsSync(path.join(__dirname, year))) fs.mkdirSync(path.join(__dirname, year))
|
|
|
|
if (!fs.existsSync(path.join(__dirname, year, month))) fs.mkdirSync(path.join(__dirname, year, month))
|
|
|
|
|
|
|
|
const openedPath = path.join(__dirname, year, month, 'Opened')
|
|
|
|
const closedPath = path.join(__dirname, year, month, 'Closed')
|
|
|
|
if (!fs.existsSync(openedPath)) fs.mkdirSync(openedPath)
|
|
|
|
if (!fs.existsSync(closedPath)) fs.mkdirSync(closedPath)
|
|
|
|
|
|
|
|
let args = ''
|
|
|
|
|
|
|
|
for (const arg of process.argv) {
|
|
|
|
args += arg + ' '
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!args.includes('--no-download')) download()
|
2018-06-24 20:49:46 +00:00
|
|
|
else {
|
|
|
|
createTable()
|
|
|
|
createStatistics()
|
|
|
|
}
|
2018-06-24 16:38:50 +00:00
|
|
|
|
|
|
|
function download() {
|
|
|
|
api.Projects
|
|
|
|
.show('tildes/tildes')
|
|
|
|
.then((project) => {
|
|
|
|
api.Issues
|
|
|
|
.all({
|
|
|
|
projectId: project.id
|
|
|
|
})
|
|
|
|
.then((issues) => {
|
|
|
|
for (const issue of issues) {
|
|
|
|
if (new Date(issue.created_at).getMonth() === new Date().getMonth()) {
|
|
|
|
fs.writeFileSync(path.join(openedPath, issue.iid.toString()) + '.json', JSON.stringify(issue, null, 2))
|
|
|
|
}
|
|
|
|
if (new Date(issue.closed_at).getMonth() === new Date().getMonth()) {
|
|
|
|
fs.writeFileSync(path.join(closedPath, issue.iid.toString()) + '.json', JSON.stringify(issue, null, 2))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2018-06-24 17:55:47 +00:00
|
|
|
.then(createTable)
|
2018-06-24 20:49:46 +00:00
|
|
|
.then(createStatistics)
|
2018-06-24 16:38:50 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-06-24 17:55:47 +00:00
|
|
|
function createTable() {
|
2018-06-24 16:38:50 +00:00
|
|
|
let opened = klaw(openedPath)
|
|
|
|
let closed = klaw(closedPath)
|
|
|
|
|
|
|
|
opened.sort(function(a,b) {
|
|
|
|
const aFile = require(a.path)
|
|
|
|
const bFile = require(b.path)
|
|
|
|
return (aFile.iid > bFile.iid) ? 1 : ((bFile.iid > aFile.iid) ? -1 : 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
closed.sort(function(a,b) {
|
|
|
|
const aFile = require(a.path)
|
|
|
|
const bFile = require(b.path)
|
|
|
|
return (aFile.iid > bFile.iid) ? 1 : ((bFile.iid > aFile.iid) ? -1 : 0)
|
|
|
|
})
|
|
|
|
|
2018-06-24 17:55:47 +00:00
|
|
|
let table = '## Issue Table\n'
|
|
|
|
|
|
|
|
table += '\n### Opened\n\n'
|
|
|
|
table += '| Issue | Title | Author | Opened | Closed |\n'
|
|
|
|
table += '| ----- | ----- | ------ | ------ | ------ |\n'
|
|
|
|
|
2018-06-24 16:38:50 +00:00
|
|
|
for (const file of opened) {
|
|
|
|
const issue = require(file.path)
|
2018-06-24 17:55:47 +00:00
|
|
|
|
2018-06-29 12:34:56 +00:00
|
|
|
table += `| [${issue.iid}](${issue.web_url}) |`
|
2018-06-24 17:55:47 +00:00
|
|
|
|
2018-06-24 16:38:50 +00:00
|
|
|
let title
|
|
|
|
if (issue.title.length >= 50) {
|
|
|
|
title = issue.title.substring(0, 47) + '...'
|
|
|
|
} else {
|
|
|
|
title = issue.title
|
|
|
|
}
|
2018-06-24 17:55:47 +00:00
|
|
|
|
|
|
|
table += ` ${title} |`
|
2018-06-29 12:34:56 +00:00
|
|
|
table += ` [${issue.author.username}](${issue.author.web_url}) |`
|
2018-06-24 17:55:47 +00:00
|
|
|
table += ` ${df.asString('yyyy/MM/dd hh:mm:ss', new Date(issue.created_at))} |`
|
|
|
|
|
|
|
|
let closedAt
|
|
|
|
if (issue.closed_at === null) {
|
|
|
|
closedAt = ''
|
|
|
|
} else {
|
|
|
|
closedAt = df.asString('yyyy/MM/dd hh:mm:ss', new Date(issue.closed_at))
|
|
|
|
}
|
|
|
|
|
|
|
|
table += ` ${closedAt} |\n`
|
2018-06-24 16:38:50 +00:00
|
|
|
}
|
2018-06-24 17:55:47 +00:00
|
|
|
|
|
|
|
table += '\n### Closed\n\n'
|
|
|
|
table += '| Issue | Title | Author | Opened | Closed |\n'
|
|
|
|
table += '| ----- | ----- | ------ | ------ | ------ |\n'
|
|
|
|
|
2018-06-24 16:38:50 +00:00
|
|
|
for (const file of closed) {
|
|
|
|
const issue = require(file.path)
|
2018-06-24 17:55:47 +00:00
|
|
|
|
2018-06-29 12:34:56 +00:00
|
|
|
table += `| [${issue.iid}](${issue.web_url}) |`
|
2018-06-24 17:55:47 +00:00
|
|
|
|
2018-06-24 16:38:50 +00:00
|
|
|
let title
|
|
|
|
if (issue.title.length >= 50) {
|
|
|
|
title = issue.title.substring(0, 47) + '...'
|
|
|
|
} else {
|
|
|
|
title = issue.title
|
|
|
|
}
|
2018-06-24 17:55:47 +00:00
|
|
|
|
|
|
|
table += ` ${title} |`
|
2018-06-29 12:34:56 +00:00
|
|
|
table += ` [${issue.author.username}](${issue.author.web_url}) |`
|
2018-06-24 17:55:47 +00:00
|
|
|
table += ` ${df.asString('yyyy/MM/dd hh:mm:ss', new Date(issue.created_at))} |`
|
|
|
|
|
|
|
|
let closedAt
|
|
|
|
if (issue.closed_at === null) {
|
|
|
|
closedAt = ''
|
|
|
|
} else {
|
|
|
|
closedAt = df.asString('yyyy/MM/dd hh:mm:ss', new Date(issue.closed_at))
|
|
|
|
}
|
|
|
|
|
|
|
|
table += ` ${closedAt} |\n`
|
2018-06-24 16:38:50 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 20:49:46 +00:00
|
|
|
if (!fs.existsSync(path.join(__dirname, year, month, 'post.md')))
|
|
|
|
fs.copyFileSync(path.join(__dirname, 'template.md'), path.join(__dirname, year, month, 'post.md'))
|
2018-06-24 17:55:47 +00:00
|
|
|
fs.writeFileSync(path.join(__dirname, year, month, 'table.md'), table, {encoding: 'UTF-8'})
|
2018-06-24 16:38:50 +00:00
|
|
|
}
|
2018-06-24 20:49:46 +00:00
|
|
|
|
|
|
|
function createStatistics() {
|
|
|
|
let opened = klaw(openedPath)
|
|
|
|
let closed = klaw(closedPath)
|
|
|
|
|
|
|
|
let statistics = '## Statistics\n\n'
|
|
|
|
|
|
|
|
statistics += `In the month of ${month} `
|
|
|
|
statistics += `${opened.length} issues were opened and `
|
|
|
|
statistics += `${closed.length} issues were closed.\n\n`
|
|
|
|
|
2018-06-26 17:26:53 +00:00
|
|
|
statistics += `An average of ${(opened.length / 30).toFixed(2)} issues were opened `
|
|
|
|
statistics += `and ${(closed.length / 30).toFixed(2)} issues were closed each day.\n\n`
|
2018-06-24 21:24:21 +00:00
|
|
|
|
2018-06-26 17:26:53 +00:00
|
|
|
statistics += `The average time to close issues was ${avgTime(closed, 'days')} days `
|
|
|
|
statistics += `or ${avgTime(closed, 'hours')} hours.\n\n`
|
2018-06-24 22:24:03 +00:00
|
|
|
|
2018-06-26 17:26:53 +00:00
|
|
|
const topUsers = freqUsers(opened, 3)
|
2018-06-25 08:36:42 +00:00
|
|
|
statistics += 'Top 3 issue creators:\n\n'
|
2018-07-10 22:53:20 +00:00
|
|
|
let top3 = 1
|
2018-06-26 17:26:53 +00:00
|
|
|
for (const user in topUsers) {
|
2018-07-10 22:53:20 +00:00
|
|
|
statistics += `${top3++}. [${user}](https://gitlab.com/${user}) `
|
2018-06-26 17:26:53 +00:00
|
|
|
statistics += `with [${topUsers[user]} issues created](https://gitlab.com/tildes/tildes/issues?state=all&author_username=${user}).\n`
|
2018-06-24 22:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 17:26:53 +00:00
|
|
|
let labels = labelsAlphabet(opened, true)
|
2018-06-25 08:36:42 +00:00
|
|
|
statistics += '\nAmount of labels assigned to currently open issues:\n\n'
|
2018-06-26 17:26:53 +00:00
|
|
|
for (const label in labels) {
|
2018-06-26 17:50:55 +00:00
|
|
|
statistics += `* [${label}](https://gitlab.com/tildes/tildes/issues?state=opened&label_name%5B%5D=${label.replace(' ', '+')}): ${labels[label]} `
|
|
|
|
if (labels[label] === 1) statistics += 'time.\n'
|
|
|
|
else statistics += 'times.\n'
|
2018-06-24 21:24:21 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 17:26:53 +00:00
|
|
|
labels = labelsAlphabet(closed, false)
|
2018-06-25 08:36:42 +00:00
|
|
|
statistics += '\nAmount of labels assigned to closed issues:\n\n'
|
2018-06-26 17:26:53 +00:00
|
|
|
for (const label in labels) {
|
2018-06-26 17:50:55 +00:00
|
|
|
statistics += `* [${label}](https://gitlab.com/tildes/tildes/issues?state=closed&label_name%5B%5D=${label.replace(' ', '+')}): ${labels[label]} `
|
|
|
|
if (labels[label] === 1) statistics += 'time.\n'
|
|
|
|
else statistics += 'times.\n'
|
2018-06-24 21:24:21 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 20:49:46 +00:00
|
|
|
fs.writeFileSync(path.join(__dirname, year, month, 'statistics.md'), statistics, {encoding: 'UTF-8'})
|
|
|
|
}
|