Skip to content

Commit

Permalink
Merge pull request #48 from getsentry/master
Browse files Browse the repository at this point in the history
feat: Add support for multiple patterns when using file status
  • Loading branch information
Michal Dorner authored and GitHub committed Nov 8, 2020
2 parents 804ec66 + 5282566 commit 550eb49
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,15 @@ jobs:
# dictionary, where type(s) of change composes the key.
# Multiple change types can be specified using `|` as delimiter.
filters: |
shared: &shared
- common/**
- config/**
addedOrModified:
- added|modified: '**'
allChanges:
- added|deleted|modified: '**'
addedOrModifiedAnchors:
- added|modified: *shared
```
</details>
Expand Down
14 changes: 14 additions & 0 deletions __tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ describe('matching specific change status', () => {
const match = filter.match(files)
expect(match.addOrModify).toEqual(files)
})

test.only('matches when using an anchor', () => {
const yaml = `
shared: &shared
- common/**/*
- config/**/*
src:
- modified: *shared
`
let filter = new Filter(yaml)
const files = modified(['config/file.js', 'common/anotherFile.js'])
const match = filter.match(files)
expect(match.src).toEqual(files)
})
})

function modified(paths: string[]): File[] {
Expand Down
2 changes: 1 addition & 1 deletion src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class Filter {

if (typeof item === 'object') {
return Object.entries(item).map(([key, pattern]) => {
if (typeof key !== 'string' || typeof pattern !== 'string') {
if (typeof key !== 'string' || (typeof pattern !== 'string' && !Array.isArray(pattern))) {
this.throwInvalidFormatError(
`Expected [key:string]= pattern:string, but [${key}:${typeof key}]= ${pattern}:${typeof pattern} found`
)
Expand Down

0 comments on commit 550eb49

Please sign in to comment.