Skip to content

Commit

Permalink
Added branch matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh committed Jan 14, 2021
1 parent 8230f92 commit 84ce44a
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 49 deletions.
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ labels:
- label: "feat"
matcher:
title: "^feat:.*"
branch: "^feat/.*"
commits: "^feat:.*"

- label: "fix"
matcher:
title: "^fix:.*"
branch: "^fix/.*"
commits: "^fix:.*"

- label: "chore"
matcher:
title: "^chore(\\((deps|ci)\\))?:.*"
branch: "^chore/.*"
commits: "^chore(\\((deps|ci)\\))?:.*"

- label: "docs"
matcher:
title: "^docs:.*"
branch: "^docs/.*"
commits: "^docs:.*"

### Examples
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ labels:
body: "(\\n|.)*- \\[x\\] bug(\\n|.)*"
```
### PR Branch: RegEx
```yml
version: v1

labels:
- label: "feat"
matcher:
branch: "^feat/.*"
```
## Features
- Append based multi-labeler, using `.github/labeler.yml` as config.
Expand Down
2 changes: 1 addition & 1 deletion __tests__/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('main core and context', () => {
}

await run('token', '__tests__/fixtures/empty.yml')
});
})

describe('basic.yml', () => {
beforeEach(async () => {
Expand Down
59 changes: 59 additions & 0 deletions __tests__/matcher/branch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import match from '../../src/matcher/branch'
import * as github from '@actions/github'
import {Config} from '../../src/config'

function getMatchedLabels(config: Config): string[] {
// @ts-ignore
return match(null, config)
}

const config: Config = {
version: 'v1',
labels: [
{
label: 'feat',
matcher: {
branch: '^feat/.*'
}
}
]
}

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

it('pull_request should be empty', async function () {
github.context.payload = {
pull_request: {
number: 1,
title: 'nothing interesting',
head: {
ref: 'spaceship'
}
}
}

expect(getMatchedLabels(config)).toEqual([])
})
});

describe('pull_request', () => {
it('should have feat', async function () {
github.context.payload = {
pull_request: {
number: 1,
title: 'spaceship',
head: {
ref: 'feat/spaceship'
}
}
}

const labels = getMatchedLabels(config)
expect(labels).toEqual(['feat'])
})
})

Loading

0 comments on commit 84ce44a

Please sign in to comment.