Authelia 代码生成器 authelia-gen:`github issue-templates bug-report` 命令全解析
2026/9/13 2:12:38 网站建设 项目流程

Authelia 代码生成器 authelia-gen:github issue-templates bug-report命令全解析

【免费下载链接】autheliaThe Single Sign-On Multi-Factor portal for web apps. OpenID Certified™ and Post-Quantum Cryptography Ready.项目地址: https://gitcode.com/GitHub_Trending/au/authelia

导读

authelia-gen github issue-templates bug-report是 Authelia 仓库内置的代码生成器authelia-gen提供的一条子命令,用于自动生成 GitHub 仓库的 Bug Report(缺陷报告)Issue 模板文件(默认输出为.github/ISSUE_TEMPLATE/bug-report.yml)。该命令并非"写死"一份静态模板,而是实时读取仓库 Git 标签、计算受支持版本列表与默认代理列表,再通过 Go 模板引擎渲染出一份结构完整、自带标签、包含严格提交前置检查清单的bug-report.yml。阅读本文后,你将掌握该命令的完整用法、全部参数含义、底层实现逻辑与调用链,并能在本地复现生成过程、按需定制输出。

本文以 authelia-gen_github_issue-templates_bug-report.md 为骨架,结合仓库中 cmd_github.go、cmd_root.go、types.go 及模板文件 github_issue_template_bug_report.yml.tmpl 等源码进行纵深扩充。

命令概览与定位

bug-report位于authelia-gen命令树的第三层:

authelia-gen └── github # Generate GitHub files └── issue-templates # Generate GitHub issue templates ├── bug-report # Generate GitHub bug report issue template └── feature-request # Generate GitHub feature request issue template

从源码看,newGitHubCmd 注册github子命令,newGitHubIssueTemplatesCmd 注册issue-templates,而 newGitHubIssueTemplatesBugReportCmd 则注册本命令bug-report。三者均设置了DisableAutoGenTag: true,表明这些命令是手工定义、而非 Cobra 自动生成帮助页的命令。

基本调用形式(与文档一致):

authelia-gen github issue-templates bug-report [flags]

其唯一"专属"选项是标准的帮助参数:

-h, --help help for bug-report

继承自父命令的全局参数

bug-report本身没有业务参数,但会继承authelia-gen根命令的全部持久化参数(Persistent Flags,定义于 cmd_root.go)。这些参数在本命令中真正被使用的有三个:--cwd--dir.root--version-count以及输出文件路径参数--file.bug-report。其余参数属于其他生成器(如文档、代码、JSON Schema 生成器)所需,此处一并继承但通常不会影响 bug-report 的输出。

影响 bug-report 输出的核心参数

参数简写默认值作用
-C, --cwd string-C设置执行git命令的工作目录(CWD),用于读取 Git 标签
-d, --dir.root string-d./仓库根目录,输出文件的基准路径
--file.bug-report string.github/ISSUE_TEMPLATE/bug-report.ymlBug Report Issue 模板文件的输出路径(相对于dir.root
--version-count int5生成版本下拉列表时回溯的最大 minor 版本数量

其中--file.bug-report与常量fileGitHubIssueTemplateBR(定义于 const.go)对应,注册代码见 cmd_root.go。

其他继承参数(供参考,不影响本命令)

--dir.authentication string The authentication directory in relation to the root (default "internal/authentication") --dir.docs string The directory with the docs (default "docs") --dir.docs.adr string The directory with the ADR data (default "reference/architecture-decision-log") --dir.docs.cli-reference string The directory to store the markdown in (default "reference/cli") --dir.docs.content string The directory with the docs content (default "content") --dir.docs.data string The directory with the docs data (default "data") --dir.docs.static string The directory with the docs static files (default "static") --dir.docs.static.json-schemas string The directory with the docs static JSONSchema files (default "schemas") --dir.locales string The locales directory in relation to the root (default "internal/server/locales") --dir.schema string The schema directory in relation to the root (default "internal/configuration/schema") --dir.web string The repository web directory in relation to the root directory (default "web") -X, --exclude strings Sets the names of excluded generators --file.commit-lint-config string The commit lint javascript configuration file in relation to the root (default "commitlint.config.mjs") --file.configuration-keys string Sets the path of the keys file (default "internal/configuration/schema/keys.go") --file.docs-commit-msg-guidelines string The commit message guidelines documentation file in relation to the root (default "docs/content/contributing/guidelines/commit-message.md") --file.docs.data.keys string Sets the path of the docs keys file (default "configkeys.json") --file.docs.data.languages string The languages docs data file in relation to the docs data folder (default "languages.json") --file.docs.data.misc string The misc docs data file in relation to the docs data folder (default "misc.json") --file.docs.static.json-schemas.configuration string Sets the path of the configuration JSONSchema (default "configuration") --file.docs.static.json-schemas.exports.identifiers string Sets the path of the identifiers export JSONSchema (default "exports.identifiers") --file.docs.static.json-schemas.exports.totp string Sets the path of the TOTP export JSONSchema (default "exports.totp") --file.docs.static.json-schemas.exports.webauthn string Sets the path of the WebAuthn export JSONSchema (default "exports.webauthn") --file.docs.static.json-schemas.user-database string Sets the path of the user database JSONSchema (default "user-database") --file.feature-request string Sets the path of the feature request issue template file (default ".github/ISSUE_TEMPLATE/feature-request.yml") --file.scripts.gen string Sets the path of the authelia-scripts gen file (default "cmd/authelia-scripts/cmd/gen.go") --file.server.generated string Sets the path of the server generated file (default "internal/server/gen.go") --file.web.i18n string The i18n typescript configuration file in relation to the web directory (default "src/i18n/index.ts") --file.web.package string The node package configuration file in relation to the web directory (default "package.json") --latest Enables latest functionality with several generators like the JSON Schema generator --next Enables next functionality with several generators like the JSON Schema generator --package.configuration.keys string Sets the package name of the keys file (default "schema") --package.scripts.gen string Sets the package name of the authelia-scripts gen file (default "cmd") --versions strings The versions to run the generator for, the special versions current and next are mutually exclusive

命令执行流程与源码级原理

1. 读取参数

命令入口为 cmdGitHubIssueTemplatesBugReportRunE。它依次读取四个关键参数:

  • --cwdcmdFlagCwd):git 命令的工作目录;
  • --dir.rootcmdFlagRoot):仓库根目录;
  • --file.bug-reportcmdFlagBugReport):输出文件路径;
  • --version-countcmdFlagVersionCount):版本回溯数量。

2. 读取 Git 标签并筛选版本

调用 getGitTags 执行:

git [-C <cwd>] tag --sort=-creatordate

即按创建时间倒序取得全部标签,取第一个标签(最新的 tag)解析为语义化版本latest。随后计算最低边界版本:

minimum := latest.Copy() minimum.Patch = 0 minimum.Minor -= versions // versions 即 --version-count,默认 5

即把latest的 Patch 清零、Minor 减去version-count,得到minimum。接着遍历全部标签,仅保留满足以下条件的版本进入tagsRecent列表:

  • 能成功解析为语义化版本;
  • version.IsStable()为真(跳过预发布/不稳定版本);
  • version.GreaterThanOrEqual(minimum)(处于最近 N 个 minor 版本范围内)。

这些版本会最终渲染进模板的Version下拉框中,保证 Issue 中只能选择已发布的稳定版本,而不会出现 "latest" 这类占位值。语义化版本解析与比较复用的是 internal/model 包中的model.SemanticVersion(见 cmd_github.go 的使用方式)。

3. 组装模板数据并渲染

构造模板数据 tmplIssueTemplateData:

data := &tmplIssueTemplateData{ Labels: []string{labelTypeBugUnconfirmed.String(), labelStatusNeedsTriage.String(), labelPriorityNormal.String()}, Versions: tagsRecent, Proxies: []string{"Caddy", "Traefik", "Envoy", "Istio", "NGINX", "SWAG", "NGINX Proxy Manager", "HAProxy"}, }

三个字段含义如下:

  • Labels:写入 YAML 头部的labels列表。根据 types.go 中的标签定义,这三者最终格式为:

    • labelTypeBugUnconfirmedtype/bug/unconfirmed
    • labelStatusNeedsTriagestatus/needs-triage
    • labelPriorityNormalpriority/3/normal

    即新提交的 Bug Report 会自动带上"类型:Bug(未确认)""状态:待分流""优先级:普通"三枚标签,便于维护者按状态机管理。

  • Versions:上一步筛选出的稳定版本列表,渲染为 Version 下拉选项。

  • Proxies:默认反向代理列表,涵盖 Caddy、Traefik、Envoy、Istio、NGINX、SWAG、NGINX Proxy Manager、HAProxy 八个常见部署代理。

模板本身通过//go:embed templates/*嵌入二进制,templates.go 中注册:

tmplGitHubIssueTemplateBug = template.Must(newTMPL("github_issue_template_bug_report.yml"))

模板文件为 github_issue_template_bug_report.yml.tmpl,使用 Go 标准库text/template渲染,并注入了joinX等辅助函数(见 templates.go)。

4. 写出文件

输出路径由filepath.Join(dirRoot, file)拼接(dirRoot来自--dir.rootfile来自--file.bug-report),随后os.Create创建文件并把渲染结果写入。默认情况下即生成.github/ISSUE_TEMPLATE/bug-report.yml

生成的模板内容详解

渲染后的bug-report.yml遵循 GitHub Issues 的 YAML 表单规范,包含前置说明、表单字段、提交前检查清单三个部分。以下是关键字段的完整说明(对照模板源码 github_issue_template_bug_report.yml.tmpl):

头部与标签

--- name: 'Bug Report' description: 'Report a bug' labels: - 'type/bug/unconfirmed' - 'status/needs-triage' - 'priority/3/normal'

引导说明(markdown 字段)

模板在开头嵌入了一段 markdown 引导,要求提交者遵守 7 条前置要求:

  1. 安全漏洞不得通过此渠道上报(应走安全策略);
  2. 尽量提供足够信息以便复现与快速修复;
  3. 先确认不存在重复 Issue;
  4. 只允许填写已发布的稳定版本;未发布、未打 tag 或 beta 版本应通过 Discussion 上报;
  5. 仅报告 Authelia 应用本身的 Bug——第三方软件问题、文档错误、功能理解偏差等应改走 Discussion;
  6. 阅读 Troubleshooting 参考指南:日志不得随意截断,按 Logs 章节要求提供完整日志;若需脱敏请遵循 Sanitization 章节;
  7. 若为重定向类问题,建议附带 HTTP Archive File(HAR)。

表单字段

字段 ID控件类型是否必填说明
versiondropdown必填可复现 Bug 的 Authelia 版本(多选),选项由生成器实时计算
deploymentdropdown必填部署方式:Docker / Kubernetes / Bare-metal / Other
proxydropdown必填反向代理(选项来自源码中硬编码的 Proxies 列表)
proxy-versioninput可选反向代理版本(placeholder 为x.x.x
descriptiontextarea必填描述 Bug
reproductiontextarea必填分步复现步骤,要求具体、详细,避免抽象描述
expectationstextarea可选期望结果
configurationtextarea(render: yaml)可选完整 Authelia 配置文件,模板自动放入 YAML 代码块
build-infotextarea(render: shell)必填必须提供authelia build-info命令的输出
logstextarea(render: shell)必填从应用启动到问题发生为止的完整 debug/trace 日志
logs-othertextarea(render: shell)可选受影响的代理/应用自身的 debug 日志
documentationtextarea可选相关的规范或文档
aidropdown必填是否使用生成式 AI 创建该 Issue(Yes/No),受 Artificial Intelligence Policy 约束

其中build-infologs两个字段均强制必填,是 Authelia 缺陷排查中定位问题(版本、构建信息、运行时日志)的关键依据,对应命令行工具authelia build-info(实现见 internal/commands/build_info.go)。

提交前检查清单

模板末尾是一组 checkboxes,全部为必勾选项:

  • 同意遵守 Code of Conduct;
  • 确认这是 Bug 报告而非支持请求;
  • 已阅读安全策略,确认非安全问题;
  • 已包含完整配置文件,或确认与配置无关;
  • 已包含完整 debug/trace 日志,或提供build-info输出;
  • 已完整提供所有必填信息,仅按 Troubleshooting Sanitization 指南做合理脱敏;
  • 已检查相关代理/应用日志并尽可能附上;
  • 已检索相关 Issue 并查阅文档。

实际使用与验证

复现生成

在 Authelia 仓库根目录下执行:

go run ./cmd/authelia-gen github issue-templates bug-report

即可生成(或覆盖).github/ISSUE_TEMPLATE/bug-report.yml。若当前目录不是仓库根目录,可通过-d指定:

go run ./cmd/authelia-gen github issue-templates bug-report -d /path/to/authelia

若仓库的 git tag 与输出目录分离,可用-C指定 git 命令的 CWD:

go run ./cmd/authelia-gen github issue-templates bug-report -C /path/to/authelia -d /path/to/authelia

调整版本回溯范围:

go run ./cmd/authelia-gen github issue-templates bug-report --version-count 3

改变输出文件位置:

go run ./cmd/authelia-gen github issue-templates bug-report --file.bug-report .github/ISSUE_TEMPLATE/bug-report.yml

验证要点

  • 检查生成的 YAML 中labels是否包含type/bug/unconfirmedstatus/needs-triagepriority/3/normal
  • 检查version下拉框是否只包含最近 N 个 minor 的稳定版本(标签按--sort=-creatordate排序后筛选);
  • 检查proxy下拉框是否包含源码 cmd_github.go 中列出的 8 个代理。

与兄弟命令的关系

  • authelia-gen github issue-templates:父命令,一次性执行其下全部子命令(通过rootSubCommandsRunE递归执行);
  • authelia-gen github issue-templates feature-request:兄弟命令,生成功能需求模板,实现于 cmdGitHubIssueTemplatesFeatureRunE。两者的差异在于:feature-request 的标签为type/featurestatus/needs-designpriority/3/normal,版本列表为未来的 minor 版本(latest.Minor + i + 1),且不含代理列表。

典型应用场景

  • 仓库维护者:在发布新版本后重新运行该命令,确保 Version 下拉框始终与最近支持的稳定版本同步;
  • CI 自动化:将authelia-gen github issue-templates bug-report纳入发布流水线,保证 Issue 模板与版本发布保持一致,避免手工维护 YAML 出错;
  • 二次开发:如需调整默认代理列表、标签或字段,可直接修改 cmd_github.go 中cmdGitHubIssueTemplatesBugReportRunE的数据组装逻辑或模板 github_issue_template_bug_report.yml.tmpl,重新生成即可。

小结

authelia-gen github issue-templates bug-report是 Authelia 工程化工具链中"以代码生成维护仓库元数据"的典型代表:它把"版本支持范围""默认代理列表""标签规范""提交流程约束"集中收敛到源码与模板中,通过一次命令调用即可产出一份与当前发布状态实时同步的缺陷报告模板。理解这条命令,也就理解了 Authelia 如何用生成器体系(authelia-gen)保持文档、配置、CI 与 GitHub 仓库元数据的一致性。

【免费下载链接】autheliaThe Single Sign-On Multi-Factor portal for web apps. OpenID Certified™ and Post-Quantum Cryptography Ready.项目地址: https://gitcode.com/GitHub_Trending/au/authelia

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询