forked from git-chglog/git-chglog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit_parser_test.go
310 lines (288 loc) · 6.09 KB
/
commit_parser_test.go
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
package chglog
import (
"errors"
"fmt"
"io/ioutil"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCommitParserParse(t *testing.T) {
assert := assert.New(t)
assert.True(true)
mock := &mockClient{
ReturnExec: func(subcmd string, args ...string) (string, error) {
if subcmd != "log" {
return "", errors.New("")
}
bytes, _ := ioutil.ReadFile(filepath.Join("testdata", "gitlog.txt"))
return string(bytes), nil
},
}
parser := newCommitParser(mock, &Config{
Options: &Options{
CommitFilters: map[string][]string{
"Type": []string{
"feat",
"fix",
"perf",
"refactor",
},
},
HeaderPattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$",
HeaderPatternMaps: []string{
"Type",
"Scope",
"Subject",
},
IssuePrefix: []string{
"#",
"gh-",
},
RefActions: []string{
"close",
"closes",
"closed",
"fix",
"fixes",
"fixed",
"resolve",
"resolves",
"resolved",
},
MergePattern: "^Merge pull request #(\\d+) from (.*)$",
MergePatternMaps: []string{
"Ref",
"Source",
},
RevertPattern: "^Revert \"([\\s\\S]*)\"$",
RevertPatternMaps: []string{
"Header",
},
NoteKeywords: []string{
"BREAKING CHANGE",
},
},
})
commits, err := parser.Parse("HEAD")
assert.Nil(err)
assert.Equal([]*Commit{
&Commit{
Hash: &Hash{
Long: "65cf1add9735dcc4810dda3312b0792236c97c4e",
Short: "65cf1add",
},
Author: &Author{
Name: "tsuyoshi wada",
Email: "[email protected]",
Date: time.Unix(int64(1514808000), 0),
},
Committer: &Committer{
Name: "tsuyoshi wada",
Email: "[email protected]",
Date: time.Unix(int64(1514808000), 0),
},
Merge: nil,
Revert: nil,
Refs: []*Ref{
&Ref{
Action: "",
Ref: "123",
Source: "",
},
},
Notes: []*Note{},
Mentions: []string{},
Header: "feat(*): Add new feature #123",
Type: "feat",
Scope: "*",
Subject: "Add new feature #123",
Body: "",
},
&Commit{
Hash: &Hash{
Long: "14ef0b6d386c5432af9292eab3c8314fa3001bc7",
Short: "14ef0b6d",
},
Author: &Author{
Name: "tsuyoshi wada",
Email: "[email protected]",
Date: time.Unix(int64(1515153600), 0),
},
Committer: &Committer{
Name: "tsuyoshi wada",
Email: "[email protected]",
Date: time.Unix(int64(1515153600), 0),
},
Merge: &Merge{
Ref: "3",
Source: "username/branchname",
},
Revert: nil,
Refs: []*Ref{
&Ref{
Action: "",
Ref: "3",
Source: "",
},
&Ref{
Action: "Fixes",
Ref: "3",
Source: "",
},
&Ref{
Action: "Closes",
Ref: "1",
Source: "",
},
},
Notes: []*Note{
&Note{
Title: "BREAKING CHANGE",
Body: "This is breaking point message.",
},
},
Mentions: []string{},
Header: "Merge pull request #3 from username/branchname",
Type: "",
Scope: "",
Subject: "",
Body: `This is body message.
Fixes #3
Closes #1
BREAKING CHANGE: This is breaking point message.`,
},
&Commit{
Hash: &Hash{
Long: "809a8280ffd0dadb0f4e7ba9fc835e63c37d6af6",
Short: "809a8280",
},
Author: &Author{
Name: "tsuyoshi wada",
Email: "[email protected]",
Date: time.Unix(int64(1517486400), 0),
},
Committer: &Committer{
Name: "tsuyoshi wada",
Email: "[email protected]",
Date: time.Unix(int64(1517486400), 0),
},
Merge: nil,
Revert: nil,
Refs: []*Ref{},
Notes: []*Note{},
Mentions: []string{
"tsuyoshiwada",
"hogefuga",
"FooBarBaz",
},
Header: "fix(controller): Fix cors configure",
Type: "fix",
Scope: "controller",
Subject: "Fix cors configure",
Body: `Has mention body
@tsuyoshiwada
@hogefuga
@FooBarBaz`,
},
&Commit{
Hash: &Hash{
Long: "74824d6bd1470b901ec7123d13a76a1b8938d8d0",
Short: "74824d6b",
},
Author: &Author{
Name: "tsuyoshi wada",
Email: "[email protected]",
Date: time.Unix(int64(1517488587), 0),
},
Committer: &Committer{
Name: "tsuyoshi wada",
Email: "[email protected]",
Date: time.Unix(int64(1517488587), 0),
},
Merge: nil,
Revert: nil,
Refs: []*Ref{
&Ref{
Action: "Fixes",
Ref: "123",
Source: "",
},
&Ref{
Action: "Closes",
Ref: "456",
Source: "username/repository",
},
},
Notes: []*Note{
&Note{
Title: "BREAKING CHANGE",
Body: fmt.Sprintf(`This is multiline breaking change note.
It is treated as the body of the Note until a mention or reference appears.
We also allow blank lines :)
Example:
%sjavascript
import { Controller } from 'hoge-fuga';
@autobind
class MyController extends Controller {
constructor() {
super();
}
}
%s`, "```", "```"),
},
},
Mentions: []string{},
Header: "fix(model): Remove hoge attributes",
Type: "fix",
Scope: "model",
Subject: "Remove hoge attributes",
Body: fmt.Sprintf(`This mixed body message.
BREAKING CHANGE:
This is multiline breaking change note.
It is treated as the body of the Note until a mention or reference appears.
We also allow blank lines :)
Example:
%sjavascript
import { Controller } from 'hoge-fuga';
@autobind
class MyController extends Controller {
constructor() {
super();
}
}
%s
Fixes #123
Closes username/repository#456`, "```", "```"),
},
&Commit{
Hash: &Hash{
Long: "123456789735dcc4810dda3312b0792236c97c4e",
Short: "12345678",
},
Author: &Author{
Name: "tsuyoshi wada",
Email: "[email protected]",
Date: time.Unix(int64(1517488587), 0),
},
Committer: &Committer{
Name: "tsuyoshi wada",
Email: "[email protected]",
Date: time.Unix(int64(1517488587), 0),
},
Merge: nil,
Revert: &Revert{
Header: "fix(core): commit message",
},
Refs: []*Ref{},
Notes: []*Note{},
Mentions: []string{},
Header: "Revert \"fix(core): commit message\"",
Type: "",
Scope: "",
Subject: "",
Body: "This reverts commit f755db78dcdf461dc42e709b3ab728ceba353d1d.",
},
}, commits)
}