Skip to content

use PR template when opening PRs#77

Open
skarim wants to merge 2 commits intoskarim/submit-draftfrom
skarim/pr-template
Open

use PR template when opening PRs#77
skarim wants to merge 2 commits intoskarim/submit-draftfrom
skarim/pr-template

Conversation

@skarim
Copy link
Copy Markdown
Collaborator

@skarim skarim commented May 5, 2026

Use PR templates when opening PRs in submit or link

Summary

When creating PRs via gh stack submit or gh 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 and gh pr create.

Changes

  • PR template discovery (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.
  • submit command (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.
  • link command (cmd/link.go): Same template lookup for newly created PRs. Gracefully skips if not in a git repo (e.g. PR-number-only invocations).
  • generatePRBody now accepts a templateContent parameter. 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 the Ops interface using git rev-parse --show-toplevel to reliably resolve the repo root (handles worktrees correctly).

Template search order

  1. .github/pull_request_template.md
  2. .github/PULL_REQUEST_TEMPLATE.md
  3. pull_request_template.md
  4. PULL_REQUEST_TEMPLATE.md
  5. docs/pull_request_template.md
  6. docs/PULL_REQUEST_TEMPLATE.md

The first non-empty file found is used.

Testing

  • 7 unit tests for template discovery (priority, casing, empty files, missing templates)
  • Updated TestGeneratePRBody with template and no-template cases
  • Integration tests for both submit and link verifying template usage and footer suppression

Stack created with GitHub Stacks CLIGive Feedback 💬

@skarim skarim force-pushed the skarim/pr-template branch from d30cbfb to f14e36a Compare May 5, 2026 12:23
@skarim skarim changed the title use pr template when opening prs use PR template when opening PRs May 5, 2026
@skarim skarim marked this pull request as ready for review May 5, 2026 12:26
Copilot AI review requested due to automatic review settings May 5, 2026 12:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 submit and link PR-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 via git 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 thread internal/pr/template.go Outdated
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)

@skarim skarim force-pushed the skarim/pr-template branch from f14e36a to 3ff8f7b Compare May 5, 2026 19:13
@skarim skarim force-pushed the skarim/submit-draft branch from c4d183c to 2fb3a99 Compare May 5, 2026 19:13
@skarim skarim force-pushed the skarim/pr-template branch from 3ff8f7b to 63439c6 Compare May 5, 2026 19:17
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

2 participants