← Winnitude! Search  ·  Reader Mode (1741 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 97 LINKS

GitHub - github/issue-parser: Convert issue form responses to JSON

Repository navigation

issue-parser
Public

About

Convert issue form responses to JSON

Resources

Readme MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy Activity Custom properties

Stars

33 stars

Watchers

4 watching

Forks

3 forks Report repository
Branches

Tags
Go to Branches page Go to Tags page

Latest commit

 

History


161 Commits
View commit history for this file.

Folders and files

Name Name Last commit message Last commit date
.github .github    
.vscode .vscode    
__fixtures__ __fixtures__    
__tests__ __tests__    
badges badges    
dist dist    
src src    
.gitattributes .gitattributes    
.gitignore .gitignore    
.markdown-lint.yml .markdown-lint.yml    
.mega-linter.yml .mega-linter.yml    
.node-version .node-version    
.prettierignore .prettierignore    
.prettierrc.yml .prettierrc.yml    
.yaml-lint.yml .yaml-lint.yml    
CODEOWNERS CODEOWNERS    
CODE_OF_CONDUCT CODE_OF_CONDUCT    
CONTRIBUTING CONTRIBUTING    
LICENSE LICENSE    
README.md README.md    
SECURITY SECURITY    
eslint.config.mjs eslint.config.mjs    
jest.config.ts jest.config.ts    
package-lock.json package-lock.json    
package.json package.json    
rollup.config.ts rollup.config.ts    
tsconfig.base.json tsconfig.base.json    
tsconfig.eslint.json tsconfig.eslint.json    
tsconfig.json tsconfig.json    

Repository files navigation

Issue Forms Parser

Convert issue form responses to JSON

About

This package can be used to parse GitHub issues into machine-readable JSON for processing. In particular, it is designed to work with issue forms to perform basic transformations on the issue body, resulting in a consistent JSON output.

Issues submitted using issue forms use a structured Markdown format. So long as the issue body is not heavily modified by the user, we can reliably parse the issue body into a JSON object.

Installation

npm i @github/issue-parser

Example

Here is a simple example of how to use this package in your project.

import { parseIssue } from '@github/issue-parser'

const issue = parseIssue('<issue body>', '<template>')

Assuming the issue and template look like these examples:

The resulting issue object will look like the following:

{
  name: 'this-thing',
  nickname: 'thing',
  color: ['blue'],
  shape: ['square'],
  sounds: ['re', 'mi'],
  topics: [],
  description: 'This is a description.\n\nIt has multiple lines!',
  notes: '- Note\n- Another note\n- Lots of notes',
  code: 'const thing = new Thing()\nthing.doThing()',
  'code-string': 'thing.toString()',
  'is-thing': {
    selected: ['Yes'],
    unselected: ['No']
  },
  'is-thing-useful': {
    selected: ['Sometimes'],
    unselected: ['Yes', 'No']
  },
  'read-team': 'IssueOps-Demo-Readers',
  'write-team': 'IssueOps-Demo-Writers'
}

Usage

parseIssue

This is the main function of the package. It takes two arguments:

  • issue: string - The body of the issue to be parsed
  • template: string - (Optional) The issue form template used to create the issue
  • options?: { slugify?: boolean } - (Optional) Additional parsing options to use when processing the issue body

If the template value is provided, the package will attempt to transform the issue response values into different types based on the type property of the specific field in the template. If the template value is omitted, all parsed values will be returned as strings. For information on the transformations that are applied, see the Transformations section.

Parsing Options

  • slugify: boolean - If set to true, any parsed keys that are not found in the issue forms template (if provided) will be converted to slugs using the slugify package. Otherwise, the original header value will be used as the object key.

parseTemplate(template?: string)

Parses an issue form template and returns an object. This can be used to match form responses in the issue body with the fields, so that you can perform additional validation.

When parsing an issue and the associated form template, this package will attempt to match field IDs with response values. If a match is found, the field ID will be used in the parsed object keys (instead of the header value from the markdown response). If no match is found, the header text is used as the object key.

For example, if you have the following issue form template:

name: Example Request
description: Submit an example request
title: '[Request] Example'

body:
  - type: input
    id: name
    attributes:
      label: The Name of the Thing
      description: The name of the thing you want to create.
      placeholder: this-is-the-thing
    validations:
      required: true

And the following issue body:

### The Name of the Thing

this-thing

### The Nickname of the Thing

thing

The resulting parsed issue would be:

Transformations

The following transformations will take place for responses, depending on the input type. The type is inferred from the issue form template. For information on each specific type, see Syntax for GitHub's form schema .

Single Line

Type: input

Before:

This is a response

After (no change):

This is a response

Multiline

Type: textarea

Note

Empty lines are preserved in multiline responses.

Before:

First line :D

Third line!

After:

First line :D\n\nThird line!

Dropdown Selections

Type: dropdown

Before:

red, blue, green

After:

["red", "blue", "green"]

Checkboxes

Type: checkboxes

Before:

- [x] Pick me!
- [ ] Don't pick me D:

After:

{
  "selected": ["Pick me!"],
  "unselected": ["Don't pick me D:"]
}

Omitting Inputs

In the following situations, an input will be omitted from the output JSON:

Scenario Example
Invalid Heading ## This is invalid
Empty Heading ###
This is a value
No Value ### This is a heading
### This is another
This is a value

Normally, if a form is submitted with empty field(s), they will be included in the issue body as one of the following, depending on the input type in the form template.

Type No Response
dropdown None
input _No response_
textarea _No response_
### Dropdown Field

None

### Input or Textarea Field

_No response_

### Checkboxes Field

- [ ] Item A
- [ ] Item B

These will be converted to one of the following, based on the type of input specified in the issue form template:

Type Output
checkboxes { "selected": [], "unselected": []}
dropdown []
input undefined
textarea undefined

About

Convert issue form responses to JSON

Resources

Readme MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy Activity Custom properties

Stars

33 stars

Watchers

4 watching

Forks

3 forks Report repository

Releases

Packages

Used by

Contributors

Languages