✨ feat: add PR body scaffold command - #33
Conversation
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
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.
ShigureNyako
left a comment
There was a problem hiding this comment.
结论:REQUEST_CHANGES。
说明:受 GitHub 账户限制影响,我当前登录账号就是该 PR 的作者账号,GitHub 不允许对自己的 PR 提交 Request changes 状态,所以这里只能用 COMMENT 形式提交正式 review;但从代码评审结论上看,我的意见仍然是需要先修改再合并。
关键问题有两点:
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。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。
这两个点都会直接影响功能正确性,而且当前新增测试也没有覆盖到这些路径。建议把路径探测和对应回归测试补齐后再合。
这种如果确实支持的话,确实得加一下,文档在这里 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>
|
已按本轮 review 更新并推送到同一 PR,commit: 这次主要改了三点:
已回复并 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 麻烦帮忙再看一轮,谢谢。 |
|
@codex review |
There was a problem hiding this comment.
💡 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".
Co-authored-by: Nyakku Shigure <38436475+SigureMo@users.noreply.github.com>
|
继续跟进了一轮,已推送到同一 PR:
这轮相关 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-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
left a comment
There was a problem hiding this comment.
结论: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 的识别与对应回归测试补上;这点修好后,我这边再过一轮。
| return "".join(chars) | ||
|
|
||
|
|
||
| def extract_markdown_section_titles(text: str) -> list[str]: |
There was a problem hiding this comment.
这里的 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 的识别,并加一个对应的回归测试。
ShigureNyako
left a comment
There was a problem hiding this comment.
结论:REQUEST_CHANGES。
说明:这次我复核的是 PR #33 已合入后的最终结果。由于该 PR 已经 merge,GitHub 的 review 状态已不会阻止合并;但从代码质量结论上看,我仍认为这里存在一个应该尽快补 follow-up 的功能性问题。
本轮复核结论:最近几轮关于 template 路径发现、CLI 参数收敛、README / skill 一致性、以及 non-404 lookup error 处理,整体都已经收敛到比较清晰的最小实现;但 section 去重这一核心行为在真实仓库上仍有缺口。
关键问题:
-
src/gh_llm/pr_body.py的extract_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,并增加对应回归测试。
动机
gh-llm目前擅长阅读 PR / Issue 和发起 review,但在创建 PR 前整理正文这一步还缺少直接支持。这个 PR 为 issue #17 增加一个最小完整的 PR body scaffold 能力,减少跨仓库贡献时手工查模板、补 section、拼
gh pr create --body-file ...命令的重复工作。方案
本 PR 新增
gh-llm pr body-template命令,并围绕它补齐最小实现:.github/PULL_REQUEST_TEMPLATE/目录时,按字母序选择一个 markdown/text 模板--requirements/--requirement/--require-section追加必填 section,避免已有模板缺段落.md文件,并输出 ready-to-run 的gh pr create --body-file ...命令验证结果
已执行:
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)gh pr create --body-file ...命令关联 issue
Closes #17.