feat: add lines changed and contributor count statistics
This commit is contained in:
parent
c84fdcdc2b
commit
8fe644f8d7
12
gulpfile.js
12
gulpfile.js
|
@ -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`
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Reference in New Issue