npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@github/issue-parser

v1.0.0

Published

Convert issue form responses to JSON

Downloads

179

Readme

Issue Forms Parser

Check dist/ Code Coverage CodeQL Continuous Integration Continuous Delivery Linter

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.\n\nIt's pretty cool!",
  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:

{
  // Uses the ID value from the issue form template as the key
  "name": "this-thing",
  // Uses the original header value from the issue body
  "The Nickname of the Thing": "thing"
}

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 |