@@ -12,6 +12,7 @@ import (
1212 "github.com/github/gh-stack/internal/git"
1313 "github.com/github/gh-stack/internal/github"
1414 "github.com/github/gh-stack/internal/modify"
15+ "github.com/github/gh-stack/internal/pr"
1516 "github.com/github/gh-stack/internal/stack"
1617 "github.com/spf13/cobra"
1718)
@@ -148,6 +149,12 @@ func runSubmit(cfg *config.Config, opts *submitOptions) error {
148149 cfg .Warningf ("Failed to fetch branches from %s: %v" , remote , err )
149150 }
150151
152+ // Look up the repository's PR template once before creating any PRs.
153+ var templateContent string
154+ if repoRoot , err := git .RootDir (); err == nil {
155+ templateContent = pr .FindTemplate (repoRoot )
156+ }
157+
151158 // Push each branch and create/update its PR in stack order (bottom to top).
152159 // Sequential pushing ensures each branch's base is up-to-date on the
153160 // remote before the next branch is pushed, preventing race conditions.
@@ -165,7 +172,7 @@ func runSubmit(cfg *config.Config, opts *submitOptions) error {
165172
166173 // Find or create PR, and fix base if needed
167174 baseBranch := s .ActiveBaseBranch (b .Branch )
168- if err := ensurePR (cfg , client , s , i , baseBranch , opts ); err != nil {
175+ if err := ensurePR (cfg , client , s , i , baseBranch , opts , templateContent ); err != nil {
169176 if errors .Is (err , errInterrupt ) {
170177 printInterrupt (cfg )
171178 return ErrSilent
@@ -195,7 +202,7 @@ func runSubmit(cfg *config.Config, opts *submitOptions) error {
195202// ensurePR finds or creates a PR for the branch at index i, and updates
196203// its base branch if needed. This is the single place where PR state is
197204// reconciled during submit.
198- func ensurePR (cfg * config.Config , client github.ClientOps , s * stack.Stack , i int , baseBranch string , opts * submitOptions ) error {
205+ func ensurePR (cfg * config.Config , client github.ClientOps , s * stack.Stack , i int , baseBranch string , opts * submitOptions , templateContent string ) error {
199206 b := s .Branches [i ]
200207
201208 pr , err := client .FindPRForBranch (b .Branch )
@@ -205,7 +212,7 @@ func ensurePR(cfg *config.Config, client github.ClientOps, s *stack.Stack, i int
205212 }
206213
207214 if pr == nil {
208- return createPR (cfg , client , s , i , baseBranch , opts )
215+ return createPR (cfg , client , s , i , baseBranch , opts , templateContent )
209216 }
210217
211218 // PR exists — record it and fix base if needed.
@@ -250,7 +257,7 @@ func ensurePR(cfg *config.Config, client github.ClientOps, s *stack.Stack, i int
250257}
251258
252259// createPR creates a new PR for the branch at index i.
253- func createPR (cfg * config.Config , client github.ClientOps , s * stack.Stack , i int , baseBranch string , opts * submitOptions ) error {
260+ func createPR (cfg * config.Config , client github.ClientOps , s * stack.Stack , i int , baseBranch string , opts * submitOptions , templateContent string ) error {
254261 b := s .Branches [i ]
255262
256263 title , commitBody := defaultPRTitleBody (baseBranch , b .Branch )
@@ -272,7 +279,7 @@ func createPR(cfg *config.Config, client github.ClientOps, s *stack.Stack, i int
272279 if title != originalTitle && commitBody != "" {
273280 prBody = originalTitle + "\n \n " + commitBody
274281 }
275- body := generatePRBody (prBody )
282+ body := generatePRBody (prBody , templateContent )
276283
277284 newPR , createErr := client .CreatePR (baseBranch , b .Branch , title , body , ! opts .open )
278285 if createErr != nil {
@@ -299,9 +306,14 @@ func defaultPRTitleBody(base, head string) (string, string) {
299306 return humanize (head ), ""
300307}
301308
302- // generatePRBody builds a PR description from the commit body (if any)
303- // and a footer linking to the CLI and feedback form.
304- func generatePRBody (commitBody string ) string {
309+ // generatePRBody builds a PR description. When a templateContent is provided,
310+ // it is used as the body and the attribution footer is omitted. Otherwise the
311+ // body is built from the commit body with a footer linking to the CLI.
312+ func generatePRBody (commitBody string , templateContent string ) string {
313+ if templateContent != "" {
314+ return templateContent
315+ }
316+
305317 var parts []string
306318
307319 if commitBody != "" {
0 commit comments