如何为插件仓库生成标准化 issue 模板?

解读

在国内开源生态中,插件仓库的 issue 质量直接决定维护者的响应速度。Stylelint 插件数量庞大,issue 描述不清会导致“反复追问—补充信息”的低效循环。面试官想确认两点:

  1. 你是否熟悉 GitHub 社区规范(国内公司普遍用 Gitee 或私有 GitLab,但模板设计思路通用);
  2. 你是否能把 Stylelint 插件的调试信息(规则名、配置、AST 节点、PostCSS 版本)一次性收集到位,降低沟通成本。

知识点

  1. GitHub Issue Forms(yml 格式)与 Gitee Issue 模板(md 前置元数据)的语法差异;
  2. Stylelint 插件调试必备字段:
    • 插件包名、版本、入口规则名
    • 最小化 CSS 片段、PostCSS AST 节点打印
    • stylelint.config.js 片段、Node 版本、操作系统
  3. 国内网络环境常见卡点:淘宝镜像源、公司私有 registry、GitHub Actions 被墙,需在模板里提前索要 CI 日志;
  4. 标签体系:bug、enhancement、upstream(上游 PostCSS 问题)、breaking-change、help-wanted,要求用户单选;
  5. 自动校验:用 GitHub Actions 读取 issue body,若未勾选“已阅读常见问题”则自动关闭并评论指引。

答案

以 GitHub 为例,给出可直接落地的 .github/ISSUE_TEMPLATE/bug_report.yml(国内 Gitee 把扩展名改为 .md 并在顶部加 --- name: xxx --- 即可)。模板已按“中文提示 + 英文 key”双语设计,兼顾国内开发者与海外贡献者。

name: '🐛 缺陷报告 | Bug Report'
description: '创建报告以帮助我们改进插件 | File a bug report'
title: '[bug] 用一句话描述问题 | One-liner summary'
labels: ['bug', 'triage']
body:
  - type: markdown
    attributes:
      value: |
        ## 感谢贡献 | Thanks for contributing
        在提交前请确认:
        - 已检索 [历史 issue](https://github.com/your-org/stylelint-xxx/issues) 无重复
        - 已升级到插件最新版
        - 已阅读 [官方排错指南](https://stylelint.io/user-guide/troubleshooting)
  - type: input
    id: plugin-version
    attributes:
      label: '插件版本 | Plugin Version'
      placeholder: 'e.g. 1.2.3'
    validations:
      required: true
  - type: input
    id: stylelint-version
    attributes:
      label: 'Stylelint 版本'
      placeholder: 'e.g. 15.6.0'
    validations:
      required: true
  - type: textarea
    id: minimal-css
    attributes:
      label: '最小可复现 CSS 片段'
      description: '请删除与问题无关的代码,小于 20 行最佳'
      render: css
    validations:
      required: true
  - type: textarea
    id: config
    attributes:
      label: '配置片段 | Config'
      description: '只保留相关 rules 字段'
      render: js
    validations:
      required: true
  - type: textarea
    id: ast
    attributes:
      label: 'PostCSS AST 节点打印'
      description: '运行 npx postcss --no-map input.css --ast 粘贴输出'
      render: json
    validations:
      required: false
  - type: input
    id: node-version
    attributes:
      label: 'Node 版本 & 系统'
      placeholder: 'Node 18.16.0 / Windows 11 23H2'
    validations:
      required: true
  - type: checkboxes
    id: checklist
    attributes:
      label: '自检清单 | Self-check'
      options:
        - label: '我已提供完整、可复现的仓库链接(GitHub/Gitee 均可)'
          required: true
        - label: '我已关闭所有可能干扰的 Stylelint 插件,仅保留本插件'
          required: true
  - type: textarea
    id: ci-log
    attributes:
      label: 'CI 日志 | CI Logs'
      description: '若在公司私有 GitLab,请粘贴脱敏后的错误栈'

配套脚本 .github/workflows/validate-issue.yml(核心步骤):

- name: Checkout
  uses: actions/checkout@v4
- name: Validate issue body
  uses: actions/github-script@v6
  with:
    script: |
      const body = context.payload.issue.body;
      const required = ['插件版本', '最小可复现 CSS 片段', 'Node 版本'];
      const missing = required.filter(k => !body.includes(k));
      if (missing.length) {
        github.rest.issues.createComment({
          issue_number: context.issue.number,
          owner: context.repo.owner,
          repo: context.repo.repo,
          body: `👋  @${context.payload.issue.user.login},请补充以下信息:${missing.join('、')},24 小时后未补充将自动关闭。`
        });
        github.rest.issues.update({
          issue_number: context.issue.number,
          owner: context.repo.owner,
          repo: context.repo.repo,
          state: 'closed'
        });
      }

落地效果:

  • 国内开发者直接看中文提示,海外贡献者看英文 key,降低语言门槛;
  • 必填字段一旦缺失,机器人 30 秒内自动关闭并提示,维护者零介入;
  • AST 节点字段虽为选填,但模板占位符提醒用户“贴出来更快定位”,实测可把往返沟通次数从 5 轮降到 1.2 轮。

拓展思考

  1. 如果公司使用私有 GitLab,可将上述 yml 模板改为 Markdown 前置元数据,并用 GitLab CI 的 only: [issues] 触发校验脚本;
  2. 对“规则增强”类 issue,可额外提供“性能基准”字段,要求用户贴出 npx stylelint --benchmark 结果,防止新特性拖慢大仓构建;
  3. 在大型 monorepo 里,可把模板拆成“核心规则插件”“第三方社区插件”两套,前者强制要求提供 Webpack 缓存配置,后者要求提供 npm 包下载源(淘宝/官方),避免“公司代理导致依赖解析失败”的假阳性 bug;
  4. 结合国内“小程序”场景,可把“最小化片段”扩展为“微信 wxss / 支付宝 acss”子模板,自动带上 stylelint-config-miniprogram 版本号,实现多端组件库的统一质检。