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

feat: add lines changed and contributor count statistics

This commit is contained in:
Bauke 2019-01-30 16:48:45 +01:00
parent c84fdcdc2b
commit 8fe644f8d7
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 49 additions and 5 deletions

View File

@ -14,7 +14,7 @@ const
sync = require('browser-sync') sync = require('browser-sync')
// Require statistic functions // Require statistic functions
const { avgTime, freqUsers, labelsAlphabet } = require('./statistics') const { avgTime, freqUsers, labelsAlphabet, changedLines, uniqueContributors } = require('./statistics')
// Define paths that are gonna be used commonly // Define paths that are gonna be used commonly
const paths = { const paths = {
@ -172,7 +172,7 @@ function download() {
log('Downloading commits...') log('Downloading commits...')
}) })
.then(() => { .then(() => {
api.Commits.all(project.id, { ref_name: 'master' }) api.Commits.all(project.id, { ref_name: 'master', with_stats: true })
.catch((error) => reject(new Error('There was an error downloading the commits:', error))) .catch((error) => reject(new Error('There was an error downloading the commits:', error)))
.then((commits) => { .then((commits) => {
log(`Downloaded commits, saving commits from ${months[wantedMonth]} ${wantedYear} to file...`) log(`Downloaded commits, saving commits from ${months[wantedMonth]} ${wantedYear} to file...`)
@ -321,8 +321,12 @@ function createStatistics() {
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]} ` const commitStats = changedLines(commits)
statistics += `${commits.length} commits were made to the Tildes code, ` const contributors = uniqueContributors(commits)
statistics += ` <p>In the month of ${months[wantedMonth]}, `
statistics += `${commits.length} commits were made by ${contributors.length} contributors, `
statistics += `changing a total of ${Math.abs(commitStats.total)} (+${commitStats.added}|-${commitStats.deleted}) lines. `
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`

View File

@ -72,6 +72,46 @@ function labelsAlphabet(data, checkNull) {
return labelsOrdered return labelsOrdered
} }
/**
* @function changedLines
* @description Returns the number of added, deleted and total lines changed
* @param {Array} data Array with paths leading to GitLab Commit .json files (with stats)
* @returns {Object}
*/
function changedLines(data) {
const stats = {
added: 0,
deleted: 0,
total: 0,
}
for (const file of data) {
const commit = require(file.path)
stats.added += commit.stats.additions
stats.deleted += commit.stats.deletions
stats.total += commit.stats.additions - commit.stats.deletions
}
return stats
}
/**
* @function uniqueContributors
* @description Returns the names of all contributors
* @param {Array} data Array with paths leading to GitLab Commit .json files (with stats)
* @returns {Array}
*/
function uniqueContributors(data) {
const contributors = []
for (const file of data) {
const commit = require(file.path)
if (!contributors.includes(commit.author_name)) {
contributors.push(commit.author_name)
}
}
return contributors
}
exports.avgTime = avgTime exports.avgTime = avgTime
exports.freqUsers = freqUsers exports.freqUsers = freqUsers
exports.labelsAlphabet = labelsAlphabet exports.labelsAlphabet = labelsAlphabet
exports.changedLines = changedLines
exports.uniqueContributors = uniqueContributors