Skip to content

Commit 727992e

Browse files
authored
Merge pull request #118 from issue-ops/ncalteen/opt
Skip validators for fields not present in the issue
2 parents 998c5e1 + 9f182ea commit 727992e

File tree

7 files changed

+48
-5
lines changed

7 files changed

+48
-5
lines changed

__tests__/validate.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,36 @@ describe('validate()', () => {
185185

186186
existsSyncSpy.mockRestore()
187187
})
188+
189+
it('Skips running custom validators for fields not in the issue', async () => {
190+
const existsSyncSpy = jest.spyOn(fs, 'existsSync').mockReturnValue(true)
191+
const fsReadFileSyncSpy = jest
192+
.spyOn(fs, 'readFileSync')
193+
.mockReturnValue('validators:\n - field: test\n script: test.js\n')
194+
195+
const errors: string[] = await validate(
196+
{
197+
'read-team': {
198+
label: 'test',
199+
type: 'input',
200+
required: true
201+
},
202+
'write-team': {
203+
label: 'test',
204+
type: 'input',
205+
required: true
206+
}
207+
},
208+
{
209+
'read-team': 'IssueOps-Demo-Readers',
210+
'write-team': 'IssueOps-Demo-Writers'
211+
},
212+
process.cwd()
213+
)
214+
215+
expect(errors).toEqual([])
216+
217+
existsSyncSpy.mockRestore()
218+
fsReadFileSyncSpy.mockRestore()
219+
})
188220
})

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "issue-ops-validator",
33
"description": "Validate issue form submissions",
4-
"version": "3.1.1",
4+
"version": "3.2.0",
55
"author": "Nick Alteen <[email protected]>",
66
"type": "module",
77
"homepage": "https://github.com/issue-ops/validator#readme",

src/validate.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ export async function validate(
4646
)
4747

4848
for (const validator of config.validators) {
49+
if (Object.keys(issue).includes(validator.field) === false) {
50+
core.info(
51+
`Field '${validator.field}' not found in issue, skipping validator`
52+
)
53+
continue
54+
}
55+
4956
core.info(
5057
`Running custom validator '${validator.script}' on '${validator.field}'`
5158
)

0 commit comments

Comments
 (0)