-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-history-coauthors.js
39 lines (33 loc) · 1.07 KB
/
git-history-coauthors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const Git = require("nodegit");
let authors = {};
Git.Repository.open(".")
.then(function (repo) {
// repo.getCurrentBranch, repo.getHeadCommit, repo.getMasterCommit
return repo.getHeadCommit();
})
.then(function (firstCommit) {
const history = firstCommit.history();
history.on("end", async function (commits) {
for await (const commit of commits) {
var commitStats = 0;
for (const diff of await commit.getDiff()) {
const diffStats = await diff.getStats();
commitStats += diffStats.insertions() + diffStats.deletions();
}
const author = commit.author();
if (author in authors) {
authors[author] += commitStats;
} else {
authors[author] = commitStats;
}
}
// TODO: deduplicate by username and email
for (const author of Object.keys(authors).sort(
(author1, author2) => authors[author2] - authors[author1]
)) {
// sort descending
console.log(`Co-authored-by: ${author}`);
}
});
history.start();
});