@@ -21,7 +21,7 @@ export class IncreaseProcess<T extends keyof Mapper> extends BaseProcess<T> {
21
21
stream : { } ,
22
22
} ;
23
23
24
- private firstGitMessage : CommitInfo = { } ;
24
+ private baseDiffCommitInfo : CommitInfo | undefined ;
25
25
26
26
constructor ( lcovPath : string | string [ ] , opts : IncreaseProcessOpts < T > = { stream : { } } ) {
27
27
super ( ) ;
@@ -45,11 +45,14 @@ export class IncreaseProcess<T extends keyof Mapper> extends BaseProcess<T> {
45
45
}
46
46
47
47
async exec ( ) : Promise < IncreaseResult > {
48
- // 得到本次 diff 信息
48
+ // 如果传递了 hash,则得到该提交记录
49
49
if ( this . opts . hash ) {
50
- await this . getInfoByHash ( this . opts . hash ) ;
51
- } else {
52
- await this . getLog ( ) ;
50
+ this . baseDiffCommitInfo = await this . getCommitInfoByHash ( this . opts . hash ) ;
51
+ }
52
+
53
+ // 如果通过 hash 无法获得,则自动获取指定日期的那次代码提交
54
+ if ( ! this . baseDiffCommitInfo ) {
55
+ this . baseDiffCommitInfo = await this . getCommitInfoByLogSince ( ) ;
53
56
}
54
57
55
58
if ( ! this . opts . cwd ) {
@@ -59,9 +62,6 @@ export class IncreaseProcess<T extends keyof Mapper> extends BaseProcess<T> {
59
62
// 将首次提交的代码信息当做创建信息
60
63
const createInfo = await this . getCreateInfo ( ) as CommitInfo ;
61
64
62
- // 得到创建信息
63
- this . firstGitMessage = createInfo ;
64
-
65
65
// 得到增量合并结果
66
66
await this . getLcov ( ) ;
67
67
@@ -70,14 +70,14 @@ export class IncreaseProcess<T extends keyof Mapper> extends BaseProcess<T> {
70
70
if ( this . opts . output ) {
71
71
this . output ( {
72
72
data : this . formatData ,
73
- commit : this . firstGitMessage ,
73
+ commit : this . baseDiffCommitInfo ,
74
74
createInfo,
75
75
} ) ;
76
76
}
77
77
78
78
return {
79
79
data : this . formatData ,
80
- commit : this . firstGitMessage ,
80
+ commit : this . baseDiffCommitInfo as CommitInfo ,
81
81
createInfo,
82
82
gitRepoInfo : this . getGitRepoInfo ( )
83
83
} ;
@@ -90,36 +90,41 @@ export class IncreaseProcess<T extends keyof Mapper> extends BaseProcess<T> {
90
90
// 解析获得 lcov.info 的信息,这里是全量覆盖率信息
91
91
const res = await getLcovFile ( this . lcovPath ) ;
92
92
93
- this . lcov = (
94
- await new IncreaseConcat ( {
95
- cwd : this . opts . cwd ,
96
- hash : this . firstGitMessage ?. hash ,
97
- } ) . concat ( ...res )
98
- ) . getRes ( ) ;
93
+ // 合并多个 lcov 文件
94
+ const increaseConcat = await new IncreaseConcat ( {
95
+ cwd : this . opts . cwd ,
96
+ hash : this . baseDiffCommitInfo ?. hash ,
97
+ } ) . concat ( ...res ) ;
98
+
99
+ // 获得合并结果
100
+ this . lcov = increaseConcat . getRes ( ) ;
99
101
}
100
102
101
103
/**
102
- * 得到 GitLog 结果
104
+ * 通过 GitLog 的 since 值得到本次提交的记录
103
105
*/
104
- private async getLog ( ) {
106
+ private async getCommitInfoByLogSince ( ) : Promise < ( CommitInfo | undefined ) > {
107
+ // 获得当月1号
105
108
const subDate = dayjs ( this . opts . since ) . subtract ( 1 , 'day' ) . format ( 'YYYY-MM-DD' ) ;
106
109
107
110
const res = await new LogParser ( {
108
111
repo : this . opts . cwd as string ,
109
- until : subDate ,
112
+
113
+ // before: 该日期之前的记录,更新的排在前面
114
+ // after: 该日期之后的记录,更新的排在前面
115
+ before : subDate ,
110
116
} ) . run ( ) ;
111
117
112
- [ this . firstGitMessage ] = res ;
118
+ // 返回第一个值
119
+ return res [ 0 ] ;
113
120
}
114
121
115
122
/**
116
123
* 通过 hash 值得到本次提交的记录
117
124
*/
118
- private async getInfoByHash ( hash : string ) {
125
+ private async getCommitInfoByHash ( hash : string ) : Promise < ( CommitInfo | undefined ) > {
119
126
const result = await getGitRepoCommitInfoByHash ( hash , this . opts . cwd ) ;
120
127
121
- if ( result ) {
122
- this . firstGitMessage = result ;
123
- }
128
+ return result || undefined ;
124
129
}
125
130
}
0 commit comments