git 获取代码贡献量,并用echarts展示 在要统计的项

在要统计的项目目录中执行命令

windows用户需要在git bash 中执行命令

带时间范围

1
bash复制代码git log --since="2024-04-23 00:00:00" --until=2099-05-20 --format='%aN' | sort -u | while read name; do echo -en "\n{name: '$name',"; git log --since="2024-04-23 00:04:00" --until=2099-05-20 --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { printf "addedLines: %s, removedLines: %s, totalLines: %s},", add, subs, loc }' -; done
  • 可以设置时间范围排除项目初始化initial 提交。
  • 这段命令中since是指定开始时间,这段命令中使用了两个since,第一个是作用于前面的git log提交者的name,第二个是作用于后面的git log

查看全部的

1
bash复制代码 git log --format='%aN' | sort -u | while read name; do echo -en "\n{name: '$name',"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { printf "addedLines: %s, removedLines: %s, totalLines: %s},", add, subs, loc }' -; done

命令效果

image.png

echarts 配置

替换下面list中的内容,把代码替换页面中的js
echarts在线地址: Examples - Apache ECharts

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
js复制代码let list = [
{
name: 'Caichong',
addedLines: 3,
removedLines: 15,
totalLines: 18
},
{
name: 'Caisin',
addedLines: 1,
removedLines: 1,
totalLines: 2
},
{
name: 'Cao Duc Anh',
addedLines: 58,
removedLines: 31,
totalLines: 89
},
{
name: 'Captain',
addedLines: 113,
removedLines: 8,
totalLines: 121
},
{
name: 'Carfield',
addedLines: 2,
removedLines: 2,
totalLines: 4
},
{
name: 'Carlos',
addedLines: 1,
removedLines: 1,
totalLines: 2
},
{
name: 'Carson',
addedLines: 120,
removedLines: 135,
totalLines: 255
}
];

list = list.sort((a, b) => a.totalLines - b.totalLines)

const colors = {
addedLines: '#228B22',
removedLines: '#DC143C',
totalLines: '#FFD700'
};

const series = ['addedLines', 'removedLines', 'totalLines'].map((key) => ({
name: key,
type: 'bar',
barGap: '0%',
itemStyle: {
color: colors[key]
},
label: {
show: true,
position: 'top'
},
barCategoryGap: '50%',
data: list.map((v) => v[key])
}));

option = {
legend: {
show: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
xAxis: {
type: 'category',
axisLabel: {
show: true,
interval: 0
},

data: list.map((v) => v.name)
},
series,
yAxis: {
type: 'value'
}
};

echarts 效果

image.png

结束

我尝试用nodejs实现,导出一个json,然后输出一个页面,用echarts展示,发现在window下用node执行上面的命令会报错,有兴趣的可以自己实现一下写个插件发npm出来。

本文转载自: 掘金

开发者博客 – 和开发相关的 这里全都有

0%