Skip to content

Commit 83e2524

Browse files
Fix 🐛 by using 3rd-party (properly tested) wildcard-match library (#323)
1 parent 8ec3048 commit 83e2524

File tree

6 files changed

+39
-3
lines changed

6 files changed

+39
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ jobs:
5858
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5959
```
6060
61+
*The latest GitHub Marketplace release is not always up-to-date (due to [this](https://i.8713187.xyzmunity/t/automatically-publish-action-to-marketplace-on-release/17978)). To have access to all features please use version `@master`*
62+
6163
### GitHub Action output variable
6264

6365
The GitHub Action has one output variable: `branchName`, which contains the name of the branch that was created. You can use this output in downstream actions. For a trivial example see [this workflow](https://github.com/robvanderleek/robvanderleek.github.io/blob/2af5f90d94d81e942382892a6b6149467184b38b/.github/workflows/issue-branch.yml).

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"aws-sdk": "^2.824.0",
2828
"bunyan-sentry-stream": "^1.2.1",
2929
"probot": "^10.17.3",
30-
"probot-actions-adapter": "^2.0.0"
30+
"probot-actions-adapter": "^2.0.0",
31+
"wildcard-match": "^5.1.0"
3132
},
3233
"devDependencies": {
3334
"@vercel/ncc": "^0.26",

src/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const AWS = require('aws-sdk')
2+
const wcMatch = require('wildcard-match')
23

34
function makePrefixGitSafe (s) {
45
const regexp = /(?![-/])[\W]+/g
@@ -41,8 +42,8 @@ function interpolate (s, obj) {
4142
}
4243

4344
function wildcardMatch (pattern, s) {
44-
const regExp = new RegExp('^' + pattern.replace(/\*/g, '.*').replace(/\?/g, '.') + '$')
45-
return regExp.test(s)
45+
const isMatch = wcMatch(pattern, false)
46+
return isMatch(s)
4647
}
4748

4849
function isProduction () {

tests/probot-configuration.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,30 @@ test('configuration with label branch and prefix', async () => {
255255
expect(targetRef).toBe('refs/heads/feature/issue-1-Test_issue')
256256
})
257257

258+
test('issue #322 configuration', async () => {
259+
helpers.nockNonExistingBranch('feature/issue-1-Test_issue')
260+
helpers.nockExistingBranch('master', '12345678')
261+
helpers.nockBranchCreatedComment()
262+
const ymlConfig = `branches:
263+
- label: 'type | bug'
264+
prefix: bug/
265+
- label: 'type | feature'
266+
prefix: feature/`
267+
helpers.nockConfig(ymlConfig)
268+
let targetRef = ''
269+
270+
nock('https://api.github.com')
271+
.post('/repos/robvanderleek/create-issue-branch/git/refs', (body) => {
272+
targetRef = body.ref
273+
return true
274+
})
275+
.reply(200)
276+
277+
await probot.receive({ name: 'issues', payload: helpers.issueAssignedWithLabelsPayload('type | feature') })
278+
279+
expect(targetRef).toBe('refs/heads/feature/issue-1-Test_issue')
280+
})
281+
258282
test('configuration with label field missing', async () => {
259283
const ymlConfig = `branches:
260284
- name: dev

tests/utils.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ test('wildcard matching', () => {
7474
expect(utils.wildcardMatch('aap', 'aapnoot')).toBeFalsy()
7575
expect(utils.wildcardMatch('noot', 'aapnoot')).toBeFalsy()
7676
expect(utils.wildcardMatch('aap', 'Aap')).toBeFalsy()
77+
78+
expect(utils.wildcardMatch('aap*', 'aap/bar/noot')).toBeTruthy()
79+
expect(utils.wildcardMatch('type | bug', 'type | feature')).toBeFalsy()
7780
})
7881

7982
test('is running in GitHub Actions', () => {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6562,6 +6562,11 @@ widest-line@^3.1.0:
65626562
dependencies:
65636563
string-width "^4.0.0"
65646564

6565+
wildcard-match@^5.1.0:
6566+
version "5.1.0"
6567+
resolved "https://registry.yarnpkg.com/wildcard-match/-/wildcard-match-5.1.0.tgz#cb9d0c54a8bde298e534054146f3577f9e7b3c97"
6568+
integrity sha512-Q02fSwOl4xPEyLLMs3TiAOBD735ELrdiczcCnvYAn5VRDAycmzYzc69BmWI1MGONfngCSq+5mgIaYMoGfICqQg==
6569+
65656570
word-wrap@^1.2.3, word-wrap@~1.2.3:
65666571
version "1.2.3"
65676572
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"

0 commit comments

Comments
 (0)