如何设置 issue 模板?
解读
在国内一线互联网公司的 Go 后端面试中,面试官问“如何设置 issue 模板”并不是想听你背诵 GitHub 文档,而是考察三件事:
- 你是否具备“工程化”意识:知道开源项目或企业内部仓库需要统一、低沟通成本的 issue 格式;
- 你是否熟悉 GitHub/GitLab 的社区协作流程,能否把最佳实践落地到 Gin 这样的高 Star 项目;
- 你是否能结合 Gin 自身特点(路由性能、中间件、版本兼容性)给出“可落地”的模板设计,而不是泛泛而谈。
因此,回答要体现“场景 → 规范 → 工具 → 落地”四步闭环,并给出可直接拷贝使用的模板文件内容。
知识点
- GitHub Issue Template 体系:.github/ISSUE_TEMPLATE 目录、YAML front matter、label 自动打标、assignee 自动指派。
- GitLab 等价实现:.gitlab/issue_templates/ 目录 + .gitlab-ci.yml 中通过 rules:template 字段调用。
- 模板分类:Bug Report、Feature Request、Performance Regression、Security Report、Question(国内一般用前两种即可,安全类需走私有渠道)。
- YAML front matter 关键字段:name、description、title、labels、assignees、body(type: textarea/input/markdown)。
- Gin 常见定位信息:go version、gin version、os/arch、最小可复现代码(main.go)、压测命令(wrk/hey)、pprof 文件、中间件列表、是否使用 gin-contrib 组件。
- 国内补充字段:是否公司内网(无法访问外网)、是否经过代码审计、是否涉及等保/国密算法改造。
- 自动化校验:GitHub Actions 判断 issue 是否按模板填写,未填写自动打上 needs-info 标签并提醒。
答案
下面给出可直接放到 gin 官方仓库 .github/ISSUE_TEMPLATE/ 目录下的两套模板,兼顾国内面试“能背、能写、能扩展”的要求。
- bug_report.yml(GitHub 原生 YAML 模板)
name: Bug Report
description: 报告一个可复现的缺陷
title: "[Bug]: "
labels: ["bug", "needs-triage"]
body:
- type: markdown
attributes:
value: |
感谢向 Gin 社区反馈问题!在提交前请确认:
- 已搜索历史 issue(含 closed)
- 已升级到最新 release 版本
- 已提供最小可复现代码仓库(推荐单独建 github.com/yourname/gin-bug-demo)
- type: input
id: version
attributes:
label: Gin 版本
placeholder: v1.9.1
validations:
required: true
- type: textarea
id: reproduce
attributes:
label: 复现步骤
placeholder: |
1. go run main.go
2. curl http://localhost:8080/xxx
3. 出现 panic: runtime error: index out of range
validations:
required: true
- type: textarea
id: expect
attributes:
label: 期望行为
placeholder: 正常返回 200
- type: textarea
id: pprof
attributes:
label: 性能相关补充
placeholder: 如 CPU 火焰图、heap 文件,请直接粘贴文件链接或附件
- type: checkboxes
id: checklist
attributes:
label: 自检清单
options:
- label: 我已提供 go env 完整输出
required: true
- label: 我已提供 go.mod
required: true
- feature_request.yml
name: Feature Request
description: 提议一个新特性或增强
title: "[Feat]: "
labels: ["enhancement"]
body:
- type: textarea
id: background
attributes:
label: 背景
placeholder: 描述业务场景、痛点
- type: textarea
id: proposal
attributes:
label: 提案
placeholder: API 设计、中间件签名、是否破坏兼容性
- type: dropdown
id: break
attributes:
label: 是否破坏兼容性
options:
- 不破坏
- 破坏,但提供编译期警告
- 破坏,必须主版本号升级
- type: input
id: pr
attributes:
label: 是否愿意提交 PR
placeholder: 是/否,预计工期
落地步骤(面试时口述即可):
- 在仓库根目录新建 .github/ISSUE_TEMPLATE 目录;
- 将上述两个 yml 文件放入,push 到 main 分支;
- 在 Settings → Features → Issues 中勾选 “Use new issue templates”;
- 配套 Actions:.github/workflows/issue-check.yml,检测未按模板填写自动评论并打上 needs-info,3 天后无回复自动关闭。
拓展思考
- 如果企业使用私有 GitLab,可将模板放在 .gitlab/issue_templates/,并在提交 MR 时通过 CI 模板变量 ISSUE_TEMPLATE 指定,实现“issue-MR-评审”一体化。
- 对于 Gin 这样的高性能框架,可额外提供“性能回归模板”,强制要求提供 wrk -t12 -c400 -d30s 的 baseline 与 regression 数据,并上传 go test -benchmem -cpuprofile 输出,方便 maintainer 一键定位。
- 国内金融、政企场景需满足等保 2.0,可在模板中增加“是否涉及用户敏感数据”“是否已脱敏”复选框,规避合规风险。
- 面试加分项:提到“模板只是入口”,真正的闭环是“模板 → 机器人校验 → 标签自动化 → 发布计划看板(GitHub Project)”,让面试官看到你具备“开源治理”与“内部开源”双视角。