Skip to content

Commit

Permalink
Update validator script type
Browse files Browse the repository at this point in the history
  • Loading branch information
ncalteen committed Sep 24, 2023
1 parent 35d6a6b commit d000f7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/validator/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
validators:
- field: read_team
script: team
script: team.js
method: exists
- field: write_team
script: team
script: team.js
method: exists
18 changes: 7 additions & 11 deletions .github/validator/team.ts → .github/validator/team.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
/**
* Validation logic for GitHub Teams
*/
import { Octokit } from '@octokit/rest'

/**
* Checks if a team exists
* @param field The input field. This can be one of several types:
* @param {string | string[] | {label: string; required: boolean }} field The input field.
*
* This can be one of several types:
* - A string, which is the value of the field (e.g. "my-team").
* - An array of strings, which are the values of the field (e.g. ["my-team"]).
* - An object with a `label` and `required` property. This is used for checkboxes.
*
* You do not need to handle them all! It is up to the validator to determine
* which type(s) to expect, and how to handle them.
* @returns An error message if validation fails, 'success' otherwise
* @returns {Promise<string>} An error message if validation fails, 'success' otherwise
*/
export async function exists(
field: string | string[] | { label: string; required: boolean }
): Promise<string> {
export async function exists(field) {
const { Octokit } = require('@octokit/rest')

// You will need to set any required environment variables in the GitHub
// Actions workflow file that runs the validator action. This is how you can
// specify inputs to the custom validators. In this case, you will need to
Expand All @@ -38,7 +34,7 @@ export async function exists(
})

return 'success'
} catch (error: any) {
} catch (error) {
// If the team does not exist, return an error message
if (error.status === 404) return `Team ${field} does not exist`
// Otherwise, throw the exception
Expand Down

0 comments on commit d000f7e

Please sign in to comment.