Skip to content

Commit 2838241

Browse files
authored
feat: Support must_include and must_exclude regex as an array (#575)
* Support must_include array on changeset * Add changelog entry * Add array support for `must_exclude` * Fix wrong changelog entry for this branch * Added documentation for must_exclude and must_include * Add must_exclude array support for changeset * Add string, array support to other validators * Changelog reflect PR title
1 parent 01fd21a commit 2838241

File tree

16 files changed

+149
-64
lines changed

16 files changed

+149
-64
lines changed

__tests__/unit/validators/changeset.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@ test('validate returns correctly', async () => {
1818
expect(validation.status).toBe('fail')
1919
})
2020

21+
test('supports arrays', async () => {
22+
const changeset = new Changeset()
23+
const settings = {
24+
do: 'changeset',
25+
must_include: {
26+
regex: [
27+
'a.js',
28+
'b.js',
29+
'c.md'
30+
]
31+
}
32+
}
33+
34+
let validation = await changeset.processValidate(createMockContext(['package-lock.json', 'yarn.lock', 'package.json', 'a.js']), settings)
35+
expect(validation.status).toBe('pass')
36+
37+
validation = await changeset.processValidate(createMockContext(['package-lock.json', 'yarn.lock', 'package.json', 'b.js']), settings)
38+
expect(validation.status).toBe('pass')
39+
40+
validation = await changeset.processValidate(createMockContext(['package-lock.json', 'yarn.lock', 'package.json']), settings)
41+
expect(validation.status).toBe('fail')
42+
})
43+
2144
test('fail gracefully if invalid regex', async () => {
2245
const changeset = new Changeset()
2346
const settings = {

__tests__/unit/validators/options_processor/options/must_exclude.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,17 @@ test('that regex_flag works as expected', async () => {
5656
const res = mustExclude.process(validatorContext, input, rule)
5757
expect(res.status).toBe('pass')
5858
})
59+
60+
test('return pass if input array meets the criteria', async () => {
61+
const rule = { must_exclude: { regex: ['test', 'D'] } }
62+
const input = ['A', 'B', 'C']
63+
const res = mustExclude.process(validatorContext, input, rule)
64+
expect(res.status).toBe('pass')
65+
})
66+
67+
test('return fail if input array does not meet the criteria', async () => {
68+
const rule = { must_exclude: { regex: ['^the', 'F', 'G'] } }
69+
const input = ['A', 'B', 'the test']
70+
const res = mustExclude.process(validatorContext, input, rule)
71+
expect(res.status).toBe('fail')
72+
})

__tests__/unit/validators/options_processor/options/must_include.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,18 @@ test('that regex_flag works as expected', async () => {
5757
const res = mustInclude.process(validatorContext, input, rule)
5858
expect(res.status).toBe('fail')
5959
})
60+
61+
test('return pass if input array meets the criteria', async () => {
62+
const rule = { must_include: { regex: ['^the\\stest$', 'nothing'] } }
63+
const input = ['A', 'B', 'the test']
64+
const res = mustInclude.process(validatorContext, input, rule)
65+
expect(res.status).toBe('pass')
66+
})
67+
68+
test('return fail if input array does not meet the criteria', async () => {
69+
const rule = { must_include: { regex: ['test', 'another'], message: 'failed array Test' } }
70+
const input = ['E', 'F']
71+
const res = mustInclude.process(validatorContext, input, rule)
72+
expect(res.status).toBe('fail')
73+
expect(res.description).toBe('failed array Test')
74+
})

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CHANGELOG
22
=====================================
3+
| August 6, 2021 : feat: Support must_include and must_exclude regex as an array `#575 <https://github.com/mergeability/mergeable/pull/575>`_
34
| July 19, 2021 : feat: Add ignore_drafts option to ignore drafts in stale validator `#565 <https://github.com/mergeability/mergeable/issues/565>`_
45
| July 12, 2021 : feat: Filter specific status of files in changeset `#550 <https://github.com/mergeability/mergeable/issues/550>`_
56
| June 26, 2021 : feat: Add `payload` filter `#398 <https://github.com/mergeability/mergeable/issues/398>`_

docs/options/must_exclude.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ MustExclude
1111
message: |
1212
Your pull request doesn't adhere to the branch naming convention described <a href="some link">there</a>!k
1313

14+
You can also use an array of regex matchers. If any of them match, the validation will fail.
15+
16+
::
17+
18+
- do: headRef
19+
must_exclude:
20+
regex:
21+
- "^bug"
22+
- "^breaking"
23+
- "^test"
24+
message: |
25+
Your pull request doesn't adhere to the branch naming convention described <a href="some link">there</a>!k
26+
1427
.. list-table:: Supported Params
1528
:widths: 25 50 25 25
1629
:header-rows: 1
@@ -20,9 +33,9 @@ MustExclude
2033
- Required
2134
- Default Message
2235
* - regex
23-
- Regex enabled message to validate input with
36+
- Regex or array enabled message to validate input with
2437
- Yes
25-
-
38+
-
2639
* - message
2740
- Message to show if the validation fails
2841
- No

docs/options/must_include.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ MustInclude
1111
message: |
1212
Your pull request doesn't adhere to the branch naming convention described <a href="some link">there</a>!k
1313

14+
You can also use an array of regex matchers. If any of them match, the validation will pass.
15+
16+
::
17+
18+
- do: headRef
19+
must_include:
20+
regex:
21+
- "^feature"
22+
- "^hotfix"
23+
- "^fix"
24+
message: |
25+
Your pull request doesn't adhere to the branch naming convention described <a href="some link">there</a>!k
26+
1427
.. list-table:: Supported Params
1528
:widths: 25 50 25 25
1629
:header-rows: 1
@@ -20,9 +33,9 @@ MustInclude
2033
- Required
2134
- Default Message
2235
* - regex
23-
- Regex enabled message to validate input with
36+
- Regex or array enabled message to validate input with
2437
- Yes
25-
-
38+
-
2639
* - message
2740
- Message to show if the validation fails
2841
- No

lib/validators/baseRef.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ class BaseRef extends Validator {
99
]
1010
this.supportedSettings = {
1111
must_include: {
12-
regex: 'string',
12+
regex: ['string', 'array'],
1313
regex_flag: 'string',
1414
message: 'string'
1515
},
1616
must_exclude: {
17-
regex: 'string',
17+
regex: ['string', 'array'],
1818
regex_flag: 'string',
1919
message: 'string'
2020
}

lib/validators/changeset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class Changeset extends Validator {
1313
message: 'string'
1414
},
1515
must_include: {
16-
regex: 'string',
16+
regex: ['string', 'array'],
1717
regex_flag: 'string',
1818
message: 'string'
1919
},
2020
must_exclude: {
21-
regex: 'string',
21+
regex: ['string', 'array'],
2222
regex_flag: 'string',
2323
message: 'string'
2424
},

lib/validators/contents.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class Contents extends Validator {
1919
ignore: 'array'
2020
},
2121
must_include: {
22-
regex: 'string',
22+
regex: ['string', 'array'],
2323
regex_flag: 'string',
2424
message: 'string'
2525
},
2626
must_exclude: {
27-
regex: 'string',
27+
regex: ['string', 'array'],
2828
regex_flag: 'string',
2929
message: 'string'
3030
},

lib/validators/description.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class Description extends Validator {
1919
message: 'string'
2020
},
2121
must_include: {
22-
regex: 'string',
22+
regex: ['string', 'array'],
2323
regex_flag: 'string',
2424
message: 'string'
2525
},
2626
must_exclude: {
27-
regex: 'string',
27+
regex: ['string', 'array'],
2828
regex_flag: 'string',
2929
message: 'string'
3030
},

0 commit comments

Comments
 (0)