feat: add # of commits each month to statistics
This commit is contained in:
parent
724ea38c3f
commit
9385a0175b
52
gulpfile.js
52
gulpfile.js
|
@ -19,6 +19,7 @@ const { avgTime, freqUsers, labelsAlphabet } = require('./statistics')
|
|||
// Define paths that are gonna be used commonly
|
||||
const paths = {
|
||||
data: {
|
||||
commits: path.join(__dirname, 'data/commits/'),
|
||||
issues: {
|
||||
open: path.join(__dirname, 'data/issues/open/'),
|
||||
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
|
||||
const openPath = `${paths.data.issues.open}${wantedYear}/${months[wantedMonth]}/` // folder
|
||||
const closedPath = `${paths.data.issues.closed}${wantedYear}/${months[wantedMonth]}/` // folder
|
||||
const outPath = `${paths.data.issues.out}${months[wantedMonth]}${wantedYear}` // will become table and statistics files
|
||||
const commitsPath = `${paths.data.commits}${wantedYear}/${months[wantedMonth]}/`
|
||||
const openIssuesPath = `${paths.data.issues.open}${wantedYear}/${months[wantedMonth]}/` // folder
|
||||
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
|
||||
// It will make any directory that doesn't yet exist in the path
|
||||
fs.mkdirpSync(openPath)
|
||||
fs.mkdirpSync(closedPath)
|
||||
fs.mkdirpSync(commitsPath)
|
||||
fs.mkdirpSync(openIssuesPath)
|
||||
fs.mkdirpSync(closedIssuesPath)
|
||||
fs.mkdirpSync(paths.data.issues.out)
|
||||
|
||||
// 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)
|
||||
if (createdDate.getFullYear() === wantedYear &&
|
||||
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)
|
||||
if (issue.closed_at !== null &&
|
||||
closedDate.getFullYear() === wantedYear &&
|
||||
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.')
|
||||
// When we finish writing to file we can resolve the Promise that was created at the beginning
|
||||
resolve()
|
||||
log('Finished writing issues to file.')
|
||||
log('Downloading commits...')
|
||||
})
|
||||
.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
|
||||
return new Promise((resolve) => {
|
||||
// Klaw returns all files in a directory recursively so we're getting all opened and closed issue files
|
||||
let opened = klaw(openPath)
|
||||
let closed = klaw(closedPath)
|
||||
let opened = klaw(openIssuesPath)
|
||||
let closed = klaw(closedIssuesPath)
|
||||
|
||||
// Then we want to sort all of these issue files in their arrays
|
||||
opened.sort(function(a, b) {
|
||||
|
@ -288,7 +306,7 @@ function createIssueTable() {
|
|||
table += '</article>\n'
|
||||
|
||||
// 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()
|
||||
})
|
||||
}
|
||||
|
@ -296,13 +314,15 @@ function createIssueTable() {
|
|||
function createStatistics() {
|
||||
return new Promise((resolve) => {
|
||||
// Same process as the Issue Table generation
|
||||
let opened = klaw(openPath)
|
||||
let closed = klaw(closedPath)
|
||||
let commits = klaw(commitsPath)
|
||||
let opened = klaw(openIssuesPath)
|
||||
let closed = klaw(closedIssuesPath)
|
||||
|
||||
let statistics = '<article id="statistics">\n'
|
||||
statistics += ' <h2>Statistics</h2>\n'
|
||||
|
||||
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 += `${closed.length} issues were closed.</p>\n`
|
||||
|
||||
|
@ -351,7 +371,7 @@ function createStatistics() {
|
|||
statistics += ' </ul>\n'
|
||||
statistics += '</article>\n'
|
||||
|
||||
fs.writeFileSync(outPath + '_statistics.html', statistics, { encoding: 'UTF-8' })
|
||||
fs.writeFileSync(outIssuesPath + '_statistics.html', statistics, { encoding: 'UTF-8' })
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
|
|
Reference in New Issue