1- package stack
1+ package cmd
22
33import (
44 "fmt"
@@ -7,15 +7,16 @@ import (
77 "github.com/cli/go-gh/v2/pkg/prompter"
88 "github.com/github/gh-stack/internal/config"
99 "github.com/github/gh-stack/internal/git"
10+ "github.com/github/gh-stack/internal/stack"
1011)
1112
12- // ResolveStack finds the stack for the given branch, handling ambiguity when
13+ // resolveStack finds the stack for the given branch, handling ambiguity when
1314// a branch (typically a trunk) belongs to multiple stacks. If exactly one
1415// stack matches, it is returned directly. If multiple stacks match, the user
1516// is prompted to select one and the working tree is switched to the top branch
1617// of the selected stack. Returns nil with no error if no stack contains the
1718// branch.
18- func (sf * StackFile ) ResolveStack ( branch string , cfg * config.Config ) (* Stack , error ) {
19+ func resolveStack (sf * stack. StackFile , branch string , cfg * config.Config ) (* stack. Stack , error ) {
1920 stacks := sf .FindAllStacksForBranch (branch )
2021
2122 switch len (stacks ) {
@@ -56,3 +57,33 @@ func (sf *StackFile) ResolveStack(branch string, cfg *config.Config) (*Stack, er
5657
5758 return s , nil
5859}
60+
61+ // syncStackPRs discovers and updates pull request metadata for branches in a stack.
62+ // For each branch, it queries GitHub for the most recent PR and updates the
63+ // PullRequestRef including merge status. Branches with already-merged PRs are skipped.
64+ func syncStackPRs (cfg * config.Config , s * stack.Stack ) {
65+ client , err := cfg .GitHubClient ()
66+ if err != nil {
67+ return
68+ }
69+
70+ for i := range s .Branches {
71+ b := & s .Branches [i ]
72+
73+ if b .PullRequest != nil && b .PullRequest .Merged {
74+ continue
75+ }
76+
77+ pr , err := client .FindAnyPRForBranch (b .Branch )
78+ if err != nil || pr == nil {
79+ continue
80+ }
81+
82+ b .PullRequest = & stack.PullRequestRef {
83+ Number : pr .Number ,
84+ ID : pr .ID ,
85+ URL : pr .URL ,
86+ Merged : pr .Merged ,
87+ }
88+ }
89+ }
0 commit comments