Skip to content

Commit

Permalink
Add testing workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ncalteen committed Sep 24, 2023
1 parent 3443cdb commit 5cedf28
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .github/workflows/issue-created.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Issue Opened/Edited

# This workflow will run when an issue is opened or edited
on:
issues:
types:
- opened
- edited

jobs:
validate:
name: Parse and Validate Issue
runs-on: ubuntu-latest

# The validation job will only run if the issue has specific label(s). In
# this case, the issue must have the `issueops:new-thing` label.
if: |
contains(github.event.issue.labels.*.name, 'issueops:new-thing')
steps:
# This is required to access the repository's files. Specifically, the
# issue forms template and the additional validation configuration.
- name: Checkout Repository
id: checkout
uses: actions/checkout@v4

# If your validation scripts include any third-party dependencies, you
# will need to install them. First, setup Node.js on the runner.
- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v3
with:
node-version: 20
cache: npm

# Next, install the dependencies from `package.json`.
- name: Install Dependencies
id: install
run: npm install

# Parse the issue body and convert it to JSON.
- name: Parse Issue Body
id: parse
uses: issue-ops/[email protected]
with:
body: ${{ github.event.issue.body }}
issue_form_template: example-request.yml
workspace: ${{ github.workspace }}

# Validate the parsed issue body against the issue form template and any
# custom validation scripts.
- name: Validate Issue
id: validate
uses: issue-ops/[email protected]
with:
issue_form_template: example-template.yml
parsed_issue_body: ${{ steps.parse.outputs.json }}
workspace: ${{ github.workspace }}

- name: Output Validation Results
id: output
run: |
echo "Result: ${{ steps.validate.outputs.result }}"
echo "Errors: ${{ steps.validate.outputs.errors }}"
6 changes: 5 additions & 1 deletion src/validate/textarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ export function validateTextarea(
errors: string[]
): void {
// Required input does not exist
if (props.required && (!issue[key] || issue[key] === ''))
if (props.required && !issue[key])
errors.push(`Missing required input: ${key}`)

// Required input is an empty string
if (props.required && issue[key] === '')
errors.push(`Empty required input: ${key}`)

// Textareas must be strings
if (issue[key] && typeof issue[key] !== 'string')
errors.push(`Textarea response is not a string: ${key}`)
Expand Down

0 comments on commit 5cedf28

Please sign in to comment.