@github/issue-parser

中文文档
2.0.0发布于 2025/02/14MITES Module近 30 天下载 5189

Convert issue form responses to JSON

原始使用文档
文档目录12 节
  1. About
  2. Installation
  3. Example
  4. Usage
  5. parseIssue
  6. parseTemplate(template?: string)
  7. Transformations
  8. Single Line
  9. Multiline
  10. Dropdown Selections
  11. Checkboxes
  12. Omitting Inputs

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:

ScenarioExample
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.

TypeNo Response
dropdownNone
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:

TypeOutput
checkboxes{ "selected": [], "unselected": []}
dropdown[]
inputundefined
textareaundefined

版本与发布记录

@github/issue-parser 共发布 4 个版本,首次发布于 2024/11/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.0latest2025/02/141.8 年前
1.0.12025/01/171.8 年前
1.0.02024/11/052 年前
0.1.02024/11/052 年前

关于 @github/issue-parser 的常见问题

@github/issue-parser 是什么?

Convert issue form responses to JSON

如何安装 @github/issue-parser?

在项目目录运行 npm install @github/issue-parser,或使用 pnpm add / yarn add / bun add。

@github/issue-parser 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/github__issue-parser 是否存在。

@github/issue-parser 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@github/issue-parser 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@github/issue-parser 可以商用吗?

@github/issue-parser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@github/issue-parser 的下载量有多少?

根据 npm 官方下载统计,@github/issue-parser 在 2026/10/17 – 2026/11/15 这 30 天内被下载 5,189 次,日均约 173 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@github/issue-parser 还在维护吗?

最新版本 2.0.0 发布于 2025/02/14(1.8 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/11/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。