Skip to content

Commit

Permalink
Merge pull request #7 from amacado/feature/replace-wildcard-dependency
Browse files Browse the repository at this point in the history
replace deprecated wildcard with matcher and update readme with new YAML configuration format
  • Loading branch information
TimonVS authored Sep 23, 2019
2 parents e232968 + 7885b6a commit 8ef332f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 56 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@ Can be used in combination with [Release Drafter](https://github.com/toolmantim/

## Usage

Add `.github/main.workflow` with the following:
Add `.github/workflows/pr-labeler.yml` with the following:

```
workflow "Add label to PR" {
on = "pull_request"
resolves = "PR Labeler"
}
action "PR opened filter" {
uses = "actions/bin/filter@master"
args = "action opened"
}
action "PR Labeler" {
needs = "PR opened filter"
uses = "TimonVS/pr-labeler@master"
secrets = ["GITHUB_TOKEN"]
}
```yml
name: Label PRs
on: [pull_request]
jobs:
pr-labeler:
runs-on: ubuntu-latest
steps:
- uses: TimonVS/pr-labeler@master
if: github.event.action == 'opened'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
## Configuration
Expand All @@ -35,6 +30,11 @@ For example:
feature: ['feature/*', 'feat/*']
fix: fix/*
chore: chore/*
fixed-branch: fixed-branch-name
```

Then if a pull request is opened with the branch name `feature/218-add-emoji-support` the Action will automatically apply the `feature` label.

### Wildcard branches in configuration

You can use `*` as a wildcard for matching multiple branch names. See https://www.npmjs.com/package/matcher for more information about wildcard options.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Toolkit } = require('actions-toolkit')
const getConfig = require('./utils/config')
const wildcard = require('wildcard')
const matcher = require('matcher')

const CONFIG_FILENAME = 'pr-labeler.yml'
const defaults = {
Expand All @@ -25,8 +25,8 @@ Toolkit.run(
(labels, [label, patterns]) => {
if (
Array.isArray(patterns)
? patterns.some(pattern => wildcard(pattern, ref))
: wildcard(patterns, ref)
? patterns.some(pattern => matcher.isMatch(ref, pattern))
: matcher.isMatch(ref, patterns)
) {
labels.push(label)
}
Expand Down
61 changes: 26 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"actions-toolkit": "^2.0.0",
"wildcard": "^1.1.2"
"matcher": "^2.0.0"
},
"devDependencies": {
"jest": "^24.5.0",
Expand Down

0 comments on commit 8ef332f

Please sign in to comment.