Bauke/tildes-issue-log
Bauke
/
tildes-issue-log
Archived
1
Fork 0

feat: add # of commits each month to statistics

This commit is contained in:
Bauke 2019-01-30 15:41:18 +01:00
parent 724ea38c3f
commit 9385a0175b
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 36 additions and 16 deletions

View File

@ -19,6 +19,7 @@ const { avgTime, freqUsers, labelsAlphabet } = require('./statistics')
// Define paths that are gonna be used commonly // Define paths that are gonna be used commonly
const paths = { const paths = {
data: { data: {
commits: path.join(__dirname, 'data/commits/'),
issues: { issues: {
open: path.join(__dirname, 'data/issues/open/'), open: path.join(__dirname, 'data/issues/open/'),
closed: path.join(__dirname, 'data/issues/closed/'), closed: path.join(__dirname, 'data/issues/closed/'),
@ -74,14 +75,16 @@ const months = [
] ]
// Add the year and month to the open/closed/out path so they're easy to identify // Add the year and month to the open/closed/out path so they're easy to identify
const openPath = `${paths.data.issues.open}${wantedYear}/${months[wantedMonth]}/` // folder const commitsPath = `${paths.data.commits}${wantedYear}/${months[wantedMonth]}/`
const closedPath = `${paths.data.issues.closed}${wantedYear}/${months[wantedMonth]}/` // folder const openIssuesPath = `${paths.data.issues.open}${wantedYear}/${months[wantedMonth]}/` // folder
const outPath = `${paths.data.issues.out}${months[wantedMonth]}${wantedYear}` // will become table and statistics files const closedIssuesPath = `${paths.data.issues.closed}${wantedYear}/${months[wantedMonth]}/` // folder
const outIssuesPath = `${paths.data.issues.out}${months[wantedMonth]}${wantedYear}` // will become table and statistics files
// Make the directories using fs-extra's "mkdir -p" equivalent // Make the directories using fs-extra's "mkdir -p" equivalent
// It will make any directory that doesn't yet exist in the path // It will make any directory that doesn't yet exist in the path
fs.mkdirpSync(openPath) fs.mkdirpSync(commitsPath)
fs.mkdirpSync(closedPath) fs.mkdirpSync(openIssuesPath)
fs.mkdirpSync(closedIssuesPath)
fs.mkdirpSync(paths.data.issues.out) fs.mkdirpSync(paths.data.issues.out)
// Create the browser sync server, it only starts when using `gulp watch` however // Create the browser sync server, it only starts when using `gulp watch` however
@ -155,19 +158,34 @@ function download() {
const createdDate = new Date(issue.created_at) const createdDate = new Date(issue.created_at)
if (createdDate.getFullYear() === wantedYear && if (createdDate.getFullYear() === wantedYear &&
createdDate.getMonth() === wantedMonth) { createdDate.getMonth() === wantedMonth) {
fs.writeFileSync(openPath + `${issue.iid}.json`, JSON.stringify(issue, null, 2)) fs.writeFileSync(openIssuesPath + `${issue.iid}.json`, JSON.stringify(issue, null, 2))
} }
const closedDate = new Date(issue.closed_at) const closedDate = new Date(issue.closed_at)
if (issue.closed_at !== null && if (issue.closed_at !== null &&
closedDate.getFullYear() === wantedYear && closedDate.getFullYear() === wantedYear &&
closedDate.getMonth() === wantedMonth) { closedDate.getMonth() === wantedMonth) {
fs.writeFileSync(closedPath + `${issue.iid}.json`, JSON.stringify(issue, null, 2)) fs.writeFileSync(closedIssuesPath + `${issue.iid}.json`, JSON.stringify(issue, null, 2))
} }
} }
log('Finished writing to file.') log('Finished writing issues to file.')
// When we finish writing to file we can resolve the Promise that was created at the beginning log('Downloading commits...')
resolve() })
.then(() => {
api.Commits.all(project.id, { ref_name: 'master' })
.catch((error) => reject(new Error('There was an error downloading the commits:', error)))
.then((commits) => {
log(`Downloaded commits, saving commits from ${months[wantedMonth]} ${wantedYear} to file...`)
for (const commit of commits) {
const authoredDate = new Date(commit.authored_date)
if (authoredDate.getFullYear() === wantedYear &&
authoredDate.getMonth() === wantedMonth) {
fs.writeFileSync(commitsPath + `${commit.short_id}.json`, JSON.stringify(commit, null, 2))
}
}
log('Finished writing commits to file.')
resolve()
})
}) })
}) })
}) })
@ -177,8 +195,8 @@ function createIssueTable() {
// Using a Promise again for Gulp's async completion // Using a Promise again for Gulp's async completion
return new Promise((resolve) => { return new Promise((resolve) => {
// Klaw returns all files in a directory recursively so we're getting all opened and closed issue files // Klaw returns all files in a directory recursively so we're getting all opened and closed issue files
let opened = klaw(openPath) let opened = klaw(openIssuesPath)
let closed = klaw(closedPath) let closed = klaw(closedIssuesPath)
// Then we want to sort all of these issue files in their arrays // Then we want to sort all of these issue files in their arrays
opened.sort(function(a, b) { opened.sort(function(a, b) {
@ -288,7 +306,7 @@ function createIssueTable() {
table += '</article>\n' table += '</article>\n'
// And finally when the HTML is done generating we can write it and resolve that Promise we made // And finally when the HTML is done generating we can write it and resolve that Promise we made
fs.writeFileSync(outPath + '_table.html', table, { encoding: 'UTF-8' }) fs.writeFileSync(outIssuesPath + '_table.html', table, { encoding: 'UTF-8' })
resolve() resolve()
}) })
} }
@ -296,13 +314,15 @@ function createIssueTable() {
function createStatistics() { function createStatistics() {
return new Promise((resolve) => { return new Promise((resolve) => {
// Same process as the Issue Table generation // Same process as the Issue Table generation
let opened = klaw(openPath) let commits = klaw(commitsPath)
let closed = klaw(closedPath) let opened = klaw(openIssuesPath)
let closed = klaw(closedIssuesPath)
let statistics = '<article id="statistics">\n' let statistics = '<article id="statistics">\n'
statistics += ' <h2>Statistics</h2>\n' statistics += ' <h2>Statistics</h2>\n'
statistics += ` <p>In the month of ${months[wantedMonth]} ` statistics += ` <p>In the month of ${months[wantedMonth]} `
statistics += `${commits.length} commits were made to the Tildes code, `
statistics += `${opened.length} issues were opened and ` statistics += `${opened.length} issues were opened and `
statistics += `${closed.length} issues were closed.</p>\n` statistics += `${closed.length} issues were closed.</p>\n`
@ -351,7 +371,7 @@ function createStatistics() {
statistics += ' </ul>\n' statistics += ' </ul>\n'
statistics += '</article>\n' statistics += '</article>\n'
fs.writeFileSync(outPath + '_statistics.html', statistics, { encoding: 'UTF-8' }) fs.writeFileSync(outIssuesPath + '_statistics.html', statistics, { encoding: 'UTF-8' })
resolve() resolve()
}) })
} }