use PR template when opening PRs#77
Open
skarim wants to merge 2 commits intoskarim/submit-draftfrom
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for automatically using a repository’s default pull request template as the body when creating PRs via gh stack submit and gh stack link, aligning CLI behavior with GitHub UI / gh pr create expectations. This introduces a small PR-template discovery helper and a new git operation for reliably locating the repo root (including worktrees).
Changes:
- Added PR template discovery (
internal/pr.FindTemplate) with standard GitHub search locations and casing. - Updated
submitandlinkPR-creation flows to prefer the discovered template as the PR body and suppress the attribution footer when a template is used. - Added
git.RootDir()to resolve repository root viagit rev-parse --show-toplevel, plus unit/integration test coverage for template behavior.
Show a summary per file
| File | Description |
|---|---|
| internal/pr/template.go | Implements PR template discovery by searching standard paths under the repo root. |
| internal/pr/template_test.go | Adds unit tests for template discovery ordering, casing, and empty-file behavior. |
| internal/git/mock_ops.go | Extends MockOps to support the new RootDir() operation in tests. |
| internal/git/gitops.go | Extends git Ops interface and default implementation with RootDir() via rev-parse --show-toplevel. |
| internal/git/git.go | Exposes package-level git.RootDir() wrapper. |
| cmd/submit.go | Looks up PR template once per run and passes it into PR body generation during PR creation. |
| cmd/submit_test.go | Extends PR body tests and adds integration coverage ensuring templates are used and footers are suppressed. |
| cmd/link.go | Adds best-effort template lookup and uses it when creating missing PRs. |
| cmd/link_test.go | Adds integration tests for template usage (branch args) and footer fallback (PR-number args / no repo). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 9/9 changed files
- Comments generated: 2
Comment on lines
+12
to
+16
| root := t.TempDir() | ||
| dir := filepath.Join(root, ".github") | ||
| os.MkdirAll(dir, 0o755) | ||
| os.WriteFile(filepath.Join(dir, "pull_request_template.md"), []byte("## Description\n\nFill in details."), 0o644) | ||
|
|
c4d183c to
2fb3a99
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use PR templates when opening PRs in
submitorlinkSummary
When creating PRs via
gh stack submitorgh stack link, we now automatically detect and use the repository's pull request template as the PR body. This matches the behavior users expect from GitHub's web UI andgh pr create.Changes
internal/pr/template.go): Searches for the default PR template in the standard GitHub locations (.github/, repo root,docs/), matching both lower and uppercase filenames.submitcommand (cmd/submit.go): Looks up the template once before creating PRs. When a template is found, it is used as the PR body and the attribution footer is omitted.linkcommand (cmd/link.go): Same template lookup for newly created PRs. Gracefully skips if not in a git repo (e.g. PR-number-only invocations).generatePRBodynow accepts atemplateContentparameter. When non-empty, the template is used as the body without the attribution footer. When empty, behavior is unchanged (commit body + footer).git.RootDir()(internal/git/): New method on theOpsinterface usinggit rev-parse --show-toplevelto reliably resolve the repo root (handles worktrees correctly).Template search order
.github/pull_request_template.md.github/PULL_REQUEST_TEMPLATE.mdpull_request_template.mdPULL_REQUEST_TEMPLATE.mddocs/pull_request_template.mddocs/PULL_REQUEST_TEMPLATE.mdThe first non-empty file found is used.
Testing
TestGeneratePRBodywith template and no-template casessubmitandlinkverifying template usage and footer suppressionStack created with GitHub Stacks CLI • Give Feedback 💬