Skip to content
This repository was archived by the owner on Mar 22, 2020. It is now read-only.

Commit ca6903d

Browse files
committed
author name in stats
1 parent d3ef06f commit ca6903d

4 files changed

Lines changed: 24 additions & 10 deletions

File tree

handlers/contributors.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ exports.get = async function (ctx) {
2626

2727
debug('repo', repoName, repo);
2828

29-
const {files, emailToGithubUser} = Stats.instance().get(repoName).contributors;
29+
const {files, emailToGithubUser, emailToName} = Stats.instance().get(repoName).contributors;
3030

3131
let statsByAuthor = Object.create(null);
32+
// let authorEmailToName = Object.create(null);
3233

3334
// console.log(files);
3435

3536
for(let file in files) {
36-
let fileStats = files[file];
37+
let {fileStats} = files[file];
3738
for (let author in fileStats) {
3839
statsByAuthor[author] = (statsByAuthor[author] || 0) + fileStats[author];
3940
}
@@ -90,6 +91,7 @@ exports.get = async function (ctx) {
9091

9192
for (let value of result.values()) {
9293
value.percent = (value.linesCount / linesTotal * 100).toFixed(2);
94+
value.name = emailToName[value.githubEmail];
9395
}
9496

9597
// console.log(result.entries());

lib/countAuthors.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ async function countAuthors(repoPath, contributorsCache) {
6161
})).trim(); // output ends with \n
6262

6363
let statsByAuthor = Object.create(null);
64+
let emailToName = Object.create(null);
6465

6566
for(let file in contributorsCache.files) {
66-
let fileStats = contributorsCache.files[file];
67+
let {fileStats, authorEmailToName} = contributorsCache.files[file];
68+
Object.assign(emailToName, authorEmailToName);
6769
for (let author in fileStats) {
6870
statsByAuthor[author] = (statsByAuthor[author] || 0) + fileStats[author];
6971
}
@@ -110,6 +112,7 @@ async function countAuthors(repoPath, contributorsCache) {
110112
}
111113

112114
contributorsCache.emailToGithubUser = emailToGithubUser;
115+
contributorsCache.emailToName = emailToName;
113116

114117
debug(contributorsCache);
115118

lib/countFileAuthorStats.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ async function countFileAuthorStats(repoPath, filePath) {
3636

3737
if (!commits[hash]) {
3838
i++;
39-
let authorEmail;
39+
let authorEmail, authorName;
4040

4141
while(lines[i][0] !== '\t') { // source line starts prefixed by tab
4242
if (lines[i].startsWith('author-mail ')) {
4343
authorEmail = lines[i].slice('author-mail <'.length, -1);
4444
}
45+
46+
if (lines[i].startsWith('author ')) {
47+
authorName = lines[i].slice('author '.length);
48+
}
4549
i++;
4650
}
4751

@@ -54,7 +58,8 @@ async function countFileAuthorStats(repoPath, filePath) {
5458
// next lines from same commit may be non-empty, but there will be no commit info
5559
commits[hash] = {
5660
linesCount: sourceLine ? 1 : 0, // ignore blank lines
57-
authorEmail
61+
authorEmail,
62+
authorName
5863
};
5964

6065
} else {
@@ -67,21 +72,25 @@ async function countFileAuthorStats(repoPath, filePath) {
6772
}
6873

6974
assert(commits[hash].authorEmail);
75+
assert(commits[hash].authorName);
7076

7177
// some commits may have no lines yet
7278
}
7379

7480

81+
let fileStats = Object.create(null);
82+
let authorEmailToName = Object.create(null);
7583

76-
let stats = Object.create(null);
7784
for (let hash in commits) {
7885
let commit = commits[hash];
7986
if (!commit.linesCount) continue; // ignore commit with blank lines only
80-
stats[commit.authorEmail] = (stats[commit.authorEmail] || 0) + commit.linesCount;
87+
authorEmailToName[commit.authorEmail] = commit.authorName;
88+
fileStats[commit.authorEmail] = (fileStats[commit.authorEmail] || 0) + commit.linesCount;
8189
}
8290

83-
debug(stats);
84-
return stats;
91+
debug(fileStats);
92+
93+
return {fileStats, authorEmailToName};
8594
}
8695

8796
module.exports = countFileAuthorStats;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "javascript-tutorial-translate-hook",
2+
"name": "javascript-tutorial-stats",
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",

0 commit comments

Comments
 (0)