-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplifies & refactors the way
git log
fields are parsed
`--pretty=tformat` string is generated automatically from array of `git log` fields. Each field is separated by a null character, which as far as I know can't appear naturally in any of those fields. Babel now transpiles from .es to .js, which is easier than transpiling to .compiled.js now that there are multiple .es scripts
- Loading branch information
Showing
10 changed files
with
165 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
presets: ['es2015'] | ||
presets: ['es2015'], | ||
only: 'scripts/**.es' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
var fs = require('fs'), | ||
path = require('path'), | ||
chalk = require('chalk'), | ||
{chunk} = require('lodash'), | ||
{fields: gitLogFields} = require('./git-log-fields'), | ||
// Read and write from file descriptors. Bash script will hook these up. | ||
input_file = 3, | ||
output_file = 4; | ||
|
||
try { | ||
require('source-map-support').install(); | ||
} catch(e) {} | ||
|
||
console.log(chalk.yellow('Generating JSON output...')); | ||
|
||
var changes = function(data, index) { | ||
var v = data.split(',')[index] || 0; | ||
var w = 0; | ||
if (v !== 0) { | ||
var w = v.split(' ')[1]; // the number of changes is second on the array | ||
} | ||
return parseInt(w); | ||
}; | ||
|
||
console.time(chalk.green('JSON output generated in')); | ||
|
||
|
||
const fields = [ | ||
{identifier: 'repository'}, | ||
...gitLogFields, | ||
{identifier: 'shortstats'} | ||
]; | ||
|
||
let input = fs.readFileSync(input_file, 'utf8').split('\0'); | ||
input.shift(); | ||
const totalFields = fields.length; | ||
const inputCommits = chunk(input, totalFields); | ||
|
||
const output = {}; | ||
inputCommits.forEach(item => { | ||
// The last field for each commit includes the trailing newline output by `git log`; remove it | ||
item[totalFields - 1] = item[totalFields - 1].slice(0, -1); | ||
|
||
const commit = {}; | ||
fields.forEach((field, i) => { | ||
commit[field.identifier] = item[i]; | ||
}); | ||
const stats = commit.shortstats; | ||
commit.files_changed = changes(stats, 0); | ||
const insertions = commit.insertions = changes(stats, 1); | ||
const deletions = commit.deletions = changes(stats, 2); | ||
commit.impact = insertions - deletions; | ||
// TODO reimplement commit_nr | ||
|
||
const repository = commit.repository; | ||
output[repository] = output[repository] || []; | ||
output[repository].push(commit); | ||
}); | ||
|
||
console.timeEnd(chalk.green('JSON output generated in')); | ||
|
||
console.log(chalk.yellow('Writing output to file...')); | ||
|
||
fs.writeFileSync(output_file, JSON.stringify(output, null, 2)); |
Oops, something went wrong.