Skip to content

Instantly share code, notes, and snippets.

@ochameau
Created February 9, 2017 18:13
Show Gist options
  • Save ochameau/146779ec307c1ceadca92b4903f00595 to your computer and use it in GitHub Desktop.
Save ochameau/146779ec307c1ceadca92b4903f00595 to your computer and use it in GitHub Desktop.
Progress git log to compute some data about devtools bugs
var git = "git log --numstat --format=oneline --grep '^Bug '";
function execCommand(cmd, callback) {
const exec = require('child_process').exec;
exec(cmd, {maxBuffer:10000000}, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
callback(stdout);
});
}
function readStdin(callback) {
process.stdin.setEncoding('utf8');
let data = "";
process.stdin.on('readable', () => {
var chunk = process.stdin.read();
if (chunk !== null) {
data += chunk;
}
});
process.stdin.on('end', () => {
callback(data);
});
}
function processGitOutput(output) {
var lines = output.split("\n");
var current;
var bugs = {};
for (var line of lines) {
if (!line) continue;
var m = line.match(/^(\d+|-)\s+(\d+|-)\s+(.+)$/);
if (m) {
// This is a modified file
current.files.push(m[3]);
} else {
// This should be a sha+commit msg line
m = line.match(/^([^ ]+) (.+)$/);
if (!m) {
console.log("Unsupported line format", line);
continue;
}
var sha = m[1];
var msg = m[2];
m = msg.match(/Bug (\d+)/);
if (m) {
var bug = m[1];
current = bugs[bug] || {sha:[], msg:[], files:[]};
current.sha.push(sha);
current.msg.push(msg);
bugs[bug] = current;
} else {
console.log("no bug for ", line);
continue;
}
}
}
return bugs;
}
function main() {
execCommand(git, function (data) {
var bugs = processGitOutput(data);
computeLocations(bugs);
stats(bugs);
});
}
function computeLocations(bugs) {
for (var bug in bugs) {
var entry = bugs[bug];
if (entry.files.length == 0) {
console.log("commit with no modified file");
continue;
}
var hasServer = false, hasClient = false, hasShared = false;
for (var file of entry.files) {
if (file.startsWith("client")) {
hasClient = true;
}
if (file.startsWith("shared")) {
hasShared = true;
}
if (file.startsWith("server")) {
hasServer = true;
}
}
var locations = [];
if (hasServer) locations.push("server");
if (hasClient) locations.push("client");
if (hasShared) locations.push("shared");
entry.locations = locations;
}
}
function stats(bugs) {
var total = 0;
var groups = {
client: [],
server: [],
onlyClient: [],
onlyServer: [],
both: []
};
for (var bug in bugs) {
var entry = bugs[bug];
var l = entry.locations;
if (l.includes("client")) {
groups.client.push(bug);
}
if (l.includes("server")) {
groups.server.push(bug);
}
if (l.includes("server") && l.includes("client")) {
groups.both.push(bug);
}
if (l.includes("server") && !l.includes("client")) {
groups.onlyServer.push(bug);
}
if (l.includes("client") && !l.includes("server")) {
groups.onlyClient.push(bug);
}
total++;
}
console.log("total:", total);
for(var name in groups) {
var count = groups[name].length;
console.log(name, ":", count, Math.round(count/total*100) + "%");
}
for(var name in groups) {
console.log(name, ":", groups[name].sort().join(" "));
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment