diff --git a/__tests__/services/state.test.ts b/__tests__/services/state.test.ts index a10fa6f..dafa2cf 100644 --- a/__tests__/services/state.test.ts +++ b/__tests__/services/state.test.ts @@ -1,6 +1,25 @@ import { getMatchingFilePaths } from '../../src/services'; import { Comment, Change, ChangeType } from '../../src/models'; +test('* matches everything', () => { + const comment: Comment = { + pathFilter: ['*'], + markdown: 'Woohoo!', + blocking: false + }; + + const changes: Change[] = [ + { + file: 'app/models/foo.rb', + changeType: ChangeType.edit + } + ]; + + const result = getMatchingFilePaths(comment, changes); + + expect(result).toEqual(changes.map(c => c.file)); +}); + test('match recursively', () => { const comment: Comment = { pathFilter: ['app/**'], @@ -20,6 +39,25 @@ test('match recursively', () => { expect(result).toEqual(changes.map(c => c.file)); }); +test('ignore case', () => { + const comment: Comment = { + pathFilter: ['app/**'], + markdown: 'Woohoo!', + blocking: false + }; + + const changes: Change[] = [ + { + file: 'APP/MODELS/FOO.rb', + changeType: ChangeType.edit + } + ]; + + const result = getMatchingFilePaths(comment, changes); + + expect(result).toEqual(changes.map(c => c.file)); +}); + test('remove exclusion patterns', () => { const comment: Comment = { pathFilter: ['app/**', '!app/models/*.h'], @@ -107,3 +145,22 @@ test('match edited files only', () => { expect(result).toEqual(['app/models/old.rb']); }); + +test('disallow multiple modifiers', () => { + const comment: Comment = { + pathFilter: ['!~app/**'], + markdown: 'Not edited files', + blocking: false + }; + + const changes: Change[] = [ + { + file: 'app/models/old.rb', + changeType: ChangeType.edit + } + ]; + + expect(() => getMatchingFilePaths(comment, changes)).toThrow( + 'Multiple path modifiers are not supported' + ); +}); diff --git a/package-lock.json b/package-lock.json index 4421dd8..736e7d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "typescript-action", + "name": "nitpicker", "version": "0.0.0", "lockfileVersion": 1, "requires": true, diff --git a/src/services/state.ts b/src/services/state.ts index 3d59ec5..1fddc95 100644 --- a/src/services/state.ts +++ b/src/services/state.ts @@ -12,6 +12,8 @@ import { getExistingComments } from '.'; import { IOptions, Minimatch } from 'minimatch'; import { Constants } from '../constants'; +const pathModifiers = ['!', '+', '-', '~']; + export async function getTargetState( octokit: github.GitHub, allComments: Comment[], @@ -91,6 +93,10 @@ export function getMatchingFilePaths( } else { inclusions.push(pathFilter); } + + if (pathModifiers.includes(pathFilter[1])) { + throw new Error('Multiple path modifiers are not supported'); + } } for (const change of changes) {