Skip to content

✨ feat: add PR body scaffold command - #33

Merged
SigureMo merged 5 commits into
ShigureLab:mainfrom
ShigureNyako:feat/pr-body-template-scaffold
Mar 21, 2026
Merged

✨ feat: add PR body scaffold command#33
SigureMo merged 5 commits into
ShigureLab:mainfrom
ShigureNyako:feat/pr-body-template-scaffold

Conversation

@ShigureNyako

Copy link
Copy Markdown
Member

动机

gh-llm 目前擅长阅读 PR / Issue 和发起 review,但在创建 PR 前整理正文这一步还缺少直接支持。
这个 PR 为 issue #17 增加一个最小完整的 PR body scaffold 能力,减少跨仓库贡献时手工查模板、补 section、拼 gh pr create --body-file ... 命令的重复工作。

方案

本 PR 新增 gh-llm pr body-template 命令,并围绕它补齐最小实现:

  • 自动尝试读取仓库常见位置的 PR 模板
  • 当仓库存在 .github/PULL_REQUEST_TEMPLATE/ 目录时,按字母序选择一个 markdown/text 模板
  • 支持通过 --requirements / --requirement / --require-section 追加必填 section,避免已有模板缺段落
  • 当仓库没有 PR 模板时,自动生成可编辑 scaffold
  • 将结果写入指定文件或临时 .md 文件,并输出 ready-to-run 的 gh pr create --body-file ... 命令
  • 补充 README 用法说明与 CLI / helper 单测

验证结果

已执行:

uv run ruff check
uv run pyright
uv run pytest -q
uv run gh-llm pr body-template --repo ShigureLab/gh-llm --requirements 'Motivation,Validation,Related Issues' --output /tmp/gh-llm-pr-body-preview.md

结果:

  • ruff check 通过
  • pyright 通过
  • pytest -q 通过(56 passed)
  • 手动运行新命令成功生成 scaffold,并输出可直接执行的 gh pr create --body-file ... 命令

关联 issue

Closes #17.

@ShigureNyako

Copy link
Copy Markdown
Member Author

已完成自 review,并确认本 PR 的实现范围聚焦在 issue #17

@SigureMo 麻烦帮忙 review,谢谢!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c890d43b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gh_llm/github_api.py Outdated
Comment thread src/gh_llm/github_api.py Outdated
Comment thread README.md
Comment thread src/gh_llm/commands/pr.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new gh-llm pr body-template command to generate an editable PR body scaffold by loading a repository PR template when available and ensuring required sections are present, addressing issue #17.

Changes:

  • Introduces PR body scaffold generation utilities (section parsing/normalization, template augmentation).
  • Adds GitHub API support for discovering and fetching PR templates from common paths (including template directories).
  • Wires the new CLI subcommand, updates README usage, and adds unit tests covering CLI and helper behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/gh_llm/pr_body.py Implements scaffold generation + required-section parsing and normalization helpers.
src/gh_llm/github_api.py Adds PR template discovery/fetching via the GitHub Contents API and refactors contents decoding.
src/gh_llm/commands/pr.py Adds pr body-template CLI command, output file handling, and prints a ready-to-run gh pr create --body-file ... command.
tests/test_pr_body.py Adds focused tests for section parsing/normalization and scaffold behavior.
tests/test_cli.py Extends the CLI test harness to mock /contents/ and adds end-to-end tests for the new command.
README.md Documents the new command usage and expected behavior fallback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/gh_llm/github_api.py

@ShigureNyako ShigureNyako left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:REQUEST_CHANGES

说明:受 GitHub 账户限制影响,我当前登录账号就是该 PR 的作者账号,GitHub 不允许对自己的 PR 提交 Request changes 状态,所以这里只能用 COMMENT 形式提交正式 review;但从代码评审结论上看,我的意见仍然是需要先修改再合并。

关键问题有两点:

  1. src/gh_llm/github_api.py:1405-1416 只探测了 *.md 形式的直接模板,漏掉了 .txt。我在这个分支上实测 uv run gh-llm pr body-template --repo DocRaptor/docraptor-ruby 会输出 template_found: false,但该仓库实际有 .github/pull_request_template.txt
  2. src/gh_llm/github_api.py:1418-1422 只扫描了 .github/PULL_REQUEST_TEMPLATE/,没有覆盖 GitHub 文档同样支持的仓库根目录和 docs/ 下的 PULL_REQUEST_TEMPLATE/。我实测 uv run gh-llm pr body-template --repo FQ-Studio-SV/SysAcopio 也会误判为 template_found: false,而该仓库实际有 PULL_REQUEST_TEMPLATE/template.md

这两个点都会直接影响功能正确性,而且当前新增测试也没有覆盖到这些路径。建议把路径探测和对应回归测试补齐后再合。

@SigureMo

Copy link
Copy Markdown
Contributor

pull_request_template.txt

这种如果确实支持的话,确实得加一下,文档在这里 https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository

Co-authored-by: Nyakku Shigure <38436475+SigureMo@users.noreply.github.com>
@ShigureNyako

Copy link
Copy Markdown
Member Author

已按本轮 review 更新并推送到同一 PR,commit: 657123c

这次主要改了三点:

  1. 扩大 PR template 发现范围:补上 .txt、mixed-case direct template,以及仓库根目录 / docs/ 下的 PULL_REQUEST_TEMPLATE/
  2. 简化 CLI 参数:只保留 --requirements
  3. 把这部分工作流补进 skills/github-conversation/SKILL.md,README 保留 quick start 并指向 skill 文档

已回复并 resolve 本轮相关 review thread。

本地验证已重新执行:

uv run ruff check
uv run pyright
uv run pytest -q
uv run gh-llm pr body-template --repo DocRaptor/docraptor-ruby --output /tmp/docraptor-pr-body.md
uv run gh-llm pr body-template --repo FQ-Studio-SV/SysAcopio --output /tmp/sysacopio-pr-body.md

@SigureMo 麻烦帮忙再看一轮,谢谢。

Comment thread src/gh_llm/github_api.py Outdated
@SigureMo

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 657123cb19

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gh_llm/github_api.py Outdated
Comment thread src/gh_llm/github_api.py
@ShigureNyako

Copy link
Copy Markdown
Member Author

继续跟进了一轮,已推送到同一 PR:

  • 076c1b5:把 direct template probe 改成由共享常量组合生成,不再手写路径列表
  • bc65bd7:merge upstream/main,顺手把 PR 的 merge conflict 清掉了
  • e949648:只有 template path 404 才当作“无模板”,其他 lookup 错误会直接向上抛出

这轮相关 thread 已处理:

  • PRRT_kwDORQ21jc515T7C 已回复并 resolve
  • PRRT_kwDORQ21jc515V8Z 已回复并 resolve
  • PRRT_kwDORQ21jc515V8a 已回复并 resolve(暂不在 ✨ feat: add PR body scaffold command #33 内继续扩到 owner-level .github fallback,原因已在线程里说明)

本地验证重新执行:

uv run ruff check
uv run pyright
uv run pytest -q
uv run gh-llm pr body-template --repo DocRaptor/docraptor-ruby --output /tmp/docraptor-pr-body-after-error-fix.md
uv run gh-llm pr body-template --repo FQ-Studio-SV/SysAcopio --output /tmp/sysacopio-pr-body-after-error-fix.md

@SigureMo 麻烦再看一轮,谢谢。

@ShigureNyako ShigureNyako left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:REQUEST_CHANGES

说明:受当前 GitHub 账号限制影响,我当前登录账号与该 PR 作者是同一个账号,GitHub 不允许我对自己的 PR 发送 Request changes 事件;因此这里只能以 COMMENT 形式提交正式 review,但从审查结论上看,我的判断仍然是需要继续修改后再合并。

这轮我独立再看了一遍,当前实现相比上一轮已经明显收敛:

  • PR template 的探测范围和 non-404 lookup error 的处理已经补齐到一个可用的最小闭环
  • pr body-template 的 CLI 入口也简化到了 --requirements 单一参数,README 和 skills/github-conversation/SKILL.md 的示例基本一致

但我这里仍复现到一个会直接影响核心行为的边界问题:

  • src/gh_llm/pr_body.py 目前只识别 ATX(#)标题,不识别 setext(标题\n----)标题;这会让 --requirements 在已有 .txt / setext PR template 上重复追加 section。

  • 我在当前 head 上执行:

    uv run gh-llm pr body-template \
      --repo DocRaptor/docraptor-ruby \
      --requirements 'Why is this change needed?,Any screenshots?'

    可以稳定复现重复追加 Why is this change needed? / Any screenshots?,而这两个 section 在该仓库现有模板里本来就已存在。

  • 这说明“只补缺、不重复已有 section”的设计在真实仓库上还没闭环,且当前测试也没有覆盖这个场景。

建议先把 setext heading 的识别与对应回归测试补上;这点修好后,我这边再过一轮。

Comment thread src/gh_llm/pr_body.py
return "".join(chars)


def extract_markdown_section_titles(text: str) -> list[str]:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 section 提取只识别 # 风格标题,没有覆盖 setext(标题\n----)这种模板写法。这样一来,--requirements 在已有 .txt / setext 模板上会重复追加段落。

我在当前 head 上实测:

uv run gh-llm pr body-template   --repo DocRaptor/docraptor-ruby   --requirements 'Why is this change needed?,Any screenshots?'

输出里会再次追加 ## Why is this change needed?## Any screenshots?,而这两个 section 在该仓库的 .github/pull_request_template.txt 里本来就已经存在。既然这个命令的目标是“补缺而不是重复”,这里至少需要补上 setext heading 的识别,并加一个对应的回归测试。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我觉得还好……

@SigureMo
SigureMo merged commit 29285f1 into ShigureLab:main Mar 21, 2026
2 checks passed

@ShigureNyako ShigureNyako left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:REQUEST_CHANGES

说明:这次我复核的是 PR #33 已合入后的最终结果。由于该 PR 已经 merge,GitHub 的 review 状态已不会阻止合并;但从代码质量结论上看,我仍认为这里存在一个应该尽快补 follow-up 的功能性问题。

本轮复核结论:最近几轮关于 template 路径发现、CLI 参数收敛、README / skill 一致性、以及 non-404 lookup error 处理,整体都已经收敛到比较清晰的最小实现;但 section 去重这一核心行为在真实仓库上仍有缺口。

关键问题:

  • src/gh_llm/pr_body.pyextract_markdown_section_titles() 只识别 ATX(#)标题,没有识别 setext(标题下一行是 --- / ===)标题。

  • 这会导致 --requirements 在已有 .txt / setext PR template 上错误地重复追加 section,违背“只补缺、不重复已有 section”的设计目标。

  • 我在合入后的提交 29285f1 / 当前 main 上复现:

    uv run gh-llm pr body-template \
      --repo DocRaptor/docraptor-ruby \
      --requirements 'Why is this change needed?,Any screenshots?'

    结果会额外追加 ## Why is this change needed?## Any screenshots?,而这两个 section 在该仓库现有 .github/pull_request_template.txt 中原本就已经存在。

  • 当前新增测试覆盖了 ATX heading、mixed-case / .txt 路径、root/docs template directory、以及 non-404 lookup failure,但没有覆盖 setext heading 这个真实边界场景。

建议尽快补一个 follow-up:支持识别 setext heading,并增加对应回归测试。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: 增加 PR body scaffold / template fill 能力

3 participants