Skip to content

Commit

Permalink
Update method call
Browse files Browse the repository at this point in the history
  • Loading branch information
ncalteen committed Sep 24, 2023
1 parent d000f7e commit 174e321
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 22 deletions.
6 changes: 2 additions & 4 deletions .github/validator/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
validators:
- field: read_team
script: team.js
method: exists
script: team
- field: write_team
script: team.js
method: exists
script: team
2 changes: 1 addition & 1 deletion .github/validator/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* which type(s) to expect, and how to handle them.
* @returns {Promise<string>} An error message if validation fails, 'success' otherwise
*/
export async function exists(field) {
module.exports = async (field) => {
const { Octokit } = require('@octokit/rest')

// You will need to set any required environment variables in the GitHub
Expand Down
14 changes: 0 additions & 14 deletions __tests__/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ describe('validate', () => {
jest.spyOn(dropdown, 'validateDropdown').mockImplementation()
jest.spyOn(checkboxes, 'validateCheckboxes').mockImplementation()
jest.spyOn(fs, 'existsSync').mockReturnValue(true)
jest.spyOn(require(`${process.cwd()}/.github/validator/team`), 'exists')

const mocktokit = {
rest: {
Expand Down Expand Up @@ -130,12 +129,6 @@ describe('validate', () => {
)

expect(errors).toEqual([])
expect(
require(`${process.cwd()}/.github/validator/team`).exists
).toHaveBeenCalledWith('IssueOps-Demo-Readers')
expect(
require(`${process.cwd()}/.github/validator/team`).exists
).toHaveBeenCalledWith('IssueOps-Demo-Writers')
})

it('fails custom validation if config is present and inputs are invalid', async () => {
Expand All @@ -144,7 +137,6 @@ describe('validate', () => {
jest.spyOn(dropdown, 'validateDropdown').mockImplementation()
jest.spyOn(checkboxes, 'validateCheckboxes').mockImplementation()
jest.spyOn(fs, 'existsSync').mockReturnValue(true)
jest.spyOn(require(`${process.cwd()}/.github/validator/team`), 'exists')

const mocktokit = {
rest: {
Expand Down Expand Up @@ -182,11 +174,5 @@ describe('validate', () => {
'Invalid read_team: Team IssueOps-Demo-Readers does not exist',
'Invalid write_team: Team IssueOps-Demo-Writers does not exist'
])
expect(
require(`${process.cwd()}/.github/validator/team`).exists
).toHaveBeenCalledWith('IssueOps-Demo-Readers')
expect(
require(`${process.cwd()}/.github/validator/team`).exists
).toHaveBeenCalledWith('IssueOps-Demo-Writers')
})
})
2 changes: 1 addition & 1 deletion dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function validate(
const script = require(`${workspace}/.github/validator/${validator.script}`)

// Run the method, passing in the issue data for that field (if any)
const result = await script[validator.method](issue[validator.field])
const result = await script(issue[validator.field])

// If the script returns an error, add it to the list
if (result !== 'success')
Expand Down

0 comments on commit 174e321

Please sign in to comment.