@github/issue-parser

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

转换 JSON 的版本响应

中文使用文档
文档目录12 节
  1. 关于
  2. 安装
  3. 示例
  4. 使用量
  5. parseIssue
  6. parseTemplate(template?: string)
  7. 转换
  8. 单行
  9. 多线
  10. 下拉选择
  11. 复选框
  12. 输入

问题窗体解析器

Check dist/ Code Coverage CodeQL Continuous Integration Continuous Delivery Linter

转换 JSON 的版本响应

关于

此软件包可用于将 GitHub 问题解析为机器可读 JSON 处理。 特别是,它旨在与 发行表格 使问题机构实现基本转变,从而实现一致性 JSON输出.

使用问题表格提交的问题采用结构化的Markdown格式. 再见 由于发行机构没有被用户大量修改, 我们可以可靠地分析 问题体变成 JSON 对象.

安装

npm i @github/issue-parser

示例

以下是一个简单的例子,说明如何在您的工程中使用此软件包.

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

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

假设问题和模板看起来像这些例子:

结果 issue 对象的外观如下:

{
  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'
}

使用量

parseIssue

这是软件包的主要功能. 这需要两个论点:

  • issue: string - 要解析的问题的正文
  • template: string - (可选) 用于创建 问题
  • options?: { slugify?: boolean } - (备选)附加解析选项 处理问题主体时使用

如果 template 将尝试改变 以 type 财产的财产 模板中的特定字段。 如果 template 数值被省略,全部解析 值将作为字符串返回。 关于转型的信息 应用,参见 转换 节.

分析选项

  • slugify: boolean - 如果设置为 true,任何未在 问题表格模板(如果提供了)将转换为 弹片 使用 拼写 软件包。 否则 原始头值将作为对象键使用.

parseTemplate(template?: string)

分析一个问题窗体模板并返回对象。 这个可以用来匹配 与字段一起在问题机构形成响应,以便您能够执行 额外验证.

当解析一个问题和相关的形式模板时,此软件包将 尝试将字段ID与响应值相匹配。 如果找到匹配的字段 ID将在解析对象密钥中使用(而不是来自 缩放反应)。 如果没有匹配,则以页眉文字作为对象 键.

例如,如果您有下列问题表模板:

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

以及以下议题机构:

### The Name of the Thing

this-thing

### The Nickname of the Thing

thing

由此产生的问题将是:

{
  // 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"
}

转换

以下变化将视 输入类型。 该类型取自发行表格模板. 供参考 每个特定类型,见 GitHub 形式方案语法。 。 。 .

单行

类型 : input

在此之前:

This is a response

之后( 无更改 ) :

This is a response

多线

类型 : textarea

[注]

在多行响应中保留了空行.

在此之前:

First line :D

Third line!

之后:

First line :D\n\nThird line!

下拉选择

类型 : dropdown

在此之前:

red, blue, green

之后:

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

复选框

类型 : checkboxes

在此之前:

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

之后:

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

输入

在以下情况下,产出JSON中将省去一个输入:

假设示例
无效的标题## This is invalid
空标题###
This is a value
无值### This is a heading
### This is another
This is a value

通常,如果提交表单时带有空字段,则将包含在 根据表格中的输入类型,将问题机构作为以下之一: 模板.

类型无答复
dropdownNone
input_No response_
textarea_No response_
### Dropdown Field

None

### Input or Textarea Field

_No response_

### Checkboxes Field

- [ ] Item A
- [ ] Item B

这些将按输入类型转换为以下之一 问题表格模板中指定的:

类型产出
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 是什么?

转换 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 和提交记录判断。