11import { emptyConfig } from '../model/config' ;
2- import { Limits } from '../model/limits' ;
3- import { LogEntry , parseGitLog } from './git-parser' ;
2+ import { LogEntry , parseGitLog , ParseOptions } from './git-parser' ;
43import { getToday , subtractMonths , subtractSeconds } from '../utils/date-utils' ;
54import { loadCachedLog } from '../infrastructure/log' ;
65
@@ -16,7 +15,7 @@ jest.mock('../infrastructure/config', () => ({
1615 } ) ) ,
1716} ) ) ;
1817
19- const logWithoutRenames = `"John Doe <john.doe@acme.com>,${ today . toISOString ( ) } "
18+ const logWithoutRenames = `"John Doe <john.doe@acme.com>,${ today . toISOString ( ) } \t123456,ci: format with prettier "
20191\t0\t/booking/feature-manage/my.component.ts
21201\t0\t/booking/feature-manage/my-other.component.ts
22210\t1\t/checkin/feature-checkin/my.component.ts
@@ -65,16 +64,19 @@ describe('git parser', () => {
6564 } ) ;
6665
6766 it ( 'returns all log entries' , async ( ) => {
68- const limits : Limits = {
69- limitCommits : 0 ,
70- limitMonths : 0 ,
67+ const parseOptions : ParseOptions = {
68+ limits : {
69+ limitCommits : 0 ,
70+ limitMonths : 0 ,
71+ } ,
72+ filter : [ ] ,
7173 } ;
7274
7375 const entries : LogEntry [ ] = [ ] ;
7476
7577 parseGitLog ( ( entry ) => {
7678 entries . push ( entry ) ;
77- } , limits ) ;
79+ } , parseOptions ) ;
7880
7981 expect ( entries ) . toEqual ( [
8082 {
@@ -167,16 +169,19 @@ describe('git parser', () => {
167169 } ) ;
168170
169171 it ( 'returns last 2 log entries' , async ( ) => {
170- const limits : Limits = {
171- limitCommits : 2 ,
172- limitMonths : 0 ,
172+ const parseOptions : ParseOptions = {
173+ limits : {
174+ limitCommits : 2 ,
175+ limitMonths : 0 ,
176+ } ,
177+ filter : null ,
173178 } ;
174179
175180 const entries : LogEntry [ ] = [ ] ;
176181
177182 parseGitLog ( ( entry ) => {
178183 entries . push ( entry ) ;
179- } , limits ) ;
184+ } , parseOptions ) ;
180185
181186 expect ( entries ) . toEqual ( [
182187 {
@@ -230,17 +235,134 @@ describe('git parser', () => {
230235 ] ) ;
231236 } ) ;
232237
238+ it ( 'returns last 2 log entries after filtering' , async ( ) => {
239+ const parseOptions : ParseOptions = {
240+ limits : {
241+ limitCommits : 2 ,
242+ limitMonths : 0 ,
243+ } ,
244+ filter : [ 'format with prettier' ] ,
245+ } ;
246+
247+ const entries : LogEntry [ ] = [ ] ;
248+
249+ parseGitLog ( ( entry ) => {
250+ entries . push ( entry ) ;
251+ } , parseOptions ) ;
252+
253+ expect ( entries ) . toEqual ( [
254+ {
255+ header : {
256+ userName : 'Jane Doe' ,
257+ email : 'jane.doe@acme.com' ,
258+ date : today ,
259+ } ,
260+ body : [
261+ {
262+ linesAdded : 10 ,
263+ linesRemoved : 0 ,
264+ path : '/booking/feature-manage/my.component.ts' ,
265+ } ,
266+ {
267+ linesAdded : 0 ,
268+ linesRemoved : 1 ,
269+ path : '/checkin/feature-checkin/my.component.ts' ,
270+ } ,
271+ ] ,
272+ } ,
273+ {
274+ header : {
275+ userName : 'John Doe' ,
276+ email : 'john.doe@acme.com' ,
277+ date : past ,
278+ } ,
279+ body : [
280+ {
281+ linesAdded : 10 ,
282+ linesRemoved : 0 ,
283+ path : '/booking/feature-manage/my.component.ts' ,
284+ } ,
285+ {
286+ linesAdded : 0 ,
287+ linesRemoved : 1 ,
288+ path : '/shared/feature-checkin/my.component.ts' ,
289+ } ,
290+ ] ,
291+ } ,
292+ ] ) ;
293+ } ) ;
294+
295+ it ( 'returns last 2 log entries after filtering with multiple filters' , async ( ) => {
296+ const parseOptions : ParseOptions = {
297+ limits : {
298+ limitCommits : 2 ,
299+ limitMonths : 0 ,
300+ } ,
301+ filter : [ 'does not match' , 'format with prettier' ] ,
302+ } ;
303+
304+ const entries : LogEntry [ ] = [ ] ;
305+
306+ parseGitLog ( ( entry ) => {
307+ entries . push ( entry ) ;
308+ } , parseOptions ) ;
309+
310+ expect ( entries ) . toEqual ( [
311+ {
312+ header : {
313+ userName : 'Jane Doe' ,
314+ email : 'jane.doe@acme.com' ,
315+ date : today ,
316+ } ,
317+ body : [
318+ {
319+ linesAdded : 10 ,
320+ linesRemoved : 0 ,
321+ path : '/booking/feature-manage/my.component.ts' ,
322+ } ,
323+ {
324+ linesAdded : 0 ,
325+ linesRemoved : 1 ,
326+ path : '/checkin/feature-checkin/my.component.ts' ,
327+ } ,
328+ ] ,
329+ } ,
330+ {
331+ header : {
332+ userName : 'John Doe' ,
333+ email : 'john.doe@acme.com' ,
334+ date : past ,
335+ } ,
336+ body : [
337+ {
338+ linesAdded : 10 ,
339+ linesRemoved : 0 ,
340+ path : '/booking/feature-manage/my.component.ts' ,
341+ } ,
342+ {
343+ linesAdded : 0 ,
344+ linesRemoved : 1 ,
345+ path : '/shared/feature-checkin/my.component.ts' ,
346+ } ,
347+ ] ,
348+ } ,
349+ ] ) ;
350+ } ) ;
351+
233352 it ( "returns last month's log entries" , async ( ) => {
234- const limits : Limits = {
235- limitCommits : 0 ,
236- limitMonths : 1 ,
353+ const parseOptions : ParseOptions = {
354+ limits : {
355+ limitCommits : 0 ,
356+ limitMonths : 1 ,
357+ } ,
358+ filter : [ ] ,
237359 } ;
238360
239361 const entries : LogEntry [ ] = [ ] ;
240362
241363 parseGitLog ( ( entry ) => {
242364 entries . push ( entry ) ;
243- } , limits ) ;
365+ } , parseOptions ) ;
244366
245367 expect ( entries ) . toEqual ( [
246368 {
@@ -318,16 +440,19 @@ describe('git parser', () => {
318440 mocks . loadCachedLog . mockImplementation ( ( ) => logWithRenames ) ;
319441 } ) ;
320442 it ( 'returns all log entries' , async ( ) => {
321- const limits : Limits = {
322- limitCommits : 0 ,
323- limitMonths : 0 ,
443+ const parseOptions : ParseOptions = {
444+ limits : {
445+ limitCommits : 0 ,
446+ limitMonths : 0 ,
447+ } ,
448+ filter : [ ] ,
324449 } ;
325450
326451 const entries : LogEntry [ ] = [ ] ;
327452
328453 parseGitLog ( ( entry ) => {
329454 entries . push ( entry ) ;
330- } , limits ) ;
455+ } , parseOptions ) ;
331456
332457 expect ( entries ) . toEqual ( [
333458 {
0 commit comments