Skip to content

Commit

Permalink
feat: files multi matcher (#21)
Browse files Browse the repository at this point in the history
* feat: files multi matcher

* Added 2 more test for better coverage

* Added more invalid labels for testing
  • Loading branch information
fuxingloh authored Jan 15, 2021
1 parent 75bed12 commit a264fc6
Show file tree
Hide file tree
Showing 9 changed files with 703 additions and 65 deletions.
20 changes: 20 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,23 @@ labels:
- label: "test:stale"
matcher:
comment: "/stale"

- label: "test: s"
matcher:
files:
count:
gte: 1
lte: 4

- label: "test: m"
matcher:
files:
count:
gte: 5
lte: 10

- label: "test: l"
matcher:
files:
count:
gte: 11
65 changes: 60 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ Multi labeler for title, body, comments, commit messages, branch or files.
- PR/Issue comments
- PR commit messages
- PR branch name
- Glob Matcher:
- Files
- File Matcher:
- Files count
- Files any glob match
- Files all glob match

## Usage

Expand Down Expand Up @@ -89,7 +91,7 @@ labels:
```yml
on:
issues:
types: [opened, edited]
types: [ opened, edited ]
jobs:
labeler:
Expand Down Expand Up @@ -122,7 +124,7 @@ labels:
```yml
on:
issue_comment:
types: [created, edited]
types: [ created, edited ]
jobs:
labeler:
Expand Down Expand Up @@ -177,6 +179,7 @@ version: v1
labels:
- label: "bug"
matcher:
# e.g. '- [x] bug'
body: "(\\n|.)*- \\[x\\] bug(\\n|.)*"
```

Expand Down Expand Up @@ -217,21 +220,73 @@ labels:

### PR Files: [Glob Matcher](https://github.com/isaacs/minimatch)

Maximum of 3000 files only. If you use this to audit changes, take note of the 3000 files limitation.
Maximum of 3000 files only. If you use this to audit changes, take note of the 3000 files limitation. Matcher within
files are 'and condition', all must match.

#### PR Files Basic

```yml
version: v1
labels:
- label: "github"
matcher:
# This is shorthand for any: [".github/**"]
files: ".github/**"
- label: "security"
matcher:
# This is shorthand for any: ["web/security/**", "security/**"]
files: [ "web/security/**", "security/**" ]
```

#### PR Files Count

```yml
version: v1
labels:
- label: "size: s"
matcher:
files:
count:
gte: 1
lte: 4
- label: "size: m"
matcher:
files:
count:
gte: 5
lte: 10
- label: "size: l"
matcher:
files:
count:
gte: 11
```

#### PR Files Any & All

```yml
version: v1
labels:
- label: "ci"
matcher:
files:
any: [ ".github/workflow/**", ".circleci/**" ]
all: [ "!app/**" ]
- label: "attention"
matcher:
files:
any: [ "app/**" ]
count:
neq: 1
```

## Why?

> There are so many labeler why create another? 😧
Expand Down
3 changes: 1 addition & 2 deletions __tests__/fixtures/invalid/matcher-files-invalid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ version: v1
labels:
- label: "files"
matcher:
files:
any: []
files: false
6 changes: 6 additions & 0 deletions __tests__/matcher/commits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ describe('commits', function () {
expect(await getMatchedLabels(config)).toEqual([])
})

it('payload empty should be empty', async function () {
github.context.payload = {}
expect(await getMatchedLabels(config)).toEqual([])
})


it('should have feat', async function () {
github.context.payload = {
pull_request: {
Expand Down
Loading

0 comments on commit a264fc6

Please sign in to comment.