Skip to content

Commit

Permalink
fix: validate by labels even if excludeTitle returns false (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
ookami-kb authored Feb 1, 2023
1 parent 95be6b6 commit 429a5b8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
61 changes: 41 additions & 20 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,47 @@ test('skips validation if excludeTitle matches', () => {
expect(result).toBe(Result.ok)
})

test('skips validation if excludeLabels matches', () => {
const checker = new Checker({
errorSize: 40,
warningSize: 30,
excludeLabels: ['skip']
})
const result = checker.check({
title: 'PR',
files: [
{additions: 10, filename: '1.txt'},
{additions: 15, filename: '2.txt'},
{additions: 100, filename: 'some/test/file.txt'},
{additions: 100, filename: 'README.md'},
{additions: 100, filename: 'resources/1.json'}
],
labels: ['skip']
})
expect(result).toBe(Result.ok)
})

test('skips validation if excludeTitle not matches, but excludeLabels matches', () => {
const checker = new Checker({
errorSize: 40,
warningSize: 30,
excludeLabels: ['skip'],
excludeTitle: new RegExp('NO_VALIDATION'),
})
const result = checker.check({
title: 'PR',
files: [
{additions: 10, filename: '1.txt'},
{additions: 15, filename: '2.txt'},
{additions: 100, filename: 'some/test/file.txt'},
{additions: 100, filename: 'README.md'},
{additions: 100, filename: 'resources/1.json'}
],
labels: ['skip']
})
expect(result).toBe(Result.ok)
})

test('does validation if excludeTitle not matches', () => {
const excludeTitle = new RegExp('NO_VALIDATION')
const checker = new Checker({errorSize: 20, warningSize: 10, excludeTitle})
Expand Down Expand Up @@ -102,23 +143,3 @@ test('skips files matching excludePath', () => {
})
expect(result).toBe(Result.ok)
})

test('skips files matching excludeLabels', () => {
const checker = new Checker({
errorSize: 40,
warningSize: 30,
excludeLabels: ['skip']
})
const result = checker.check({
title: 'PR',
files: [
{additions: 10, filename: '1.txt'},
{additions: 15, filename: '2.txt'},
{additions: 100, filename: 'some/test/file.txt'},
{additions: 100, filename: 'README.md'},
{additions: 100, filename: 'resources/1.json'}
],
labels: ['skip']
})
expect(result).toBe(Result.ok)
})
2 changes: 1 addition & 1 deletion src/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Checker {

private shouldSkip(title: string, labels: string[]): boolean {
return (
this.excludeTitle?.test(title) ??
(this.excludeTitle?.test(title) ?? false) ||
labels.filter(it => this.excludeLabels.includes(it)).length > 0
)
}
Expand Down

0 comments on commit 429a5b8

Please sign in to comment.