@@ -67,22 +67,52 @@ branch is opened.`,
6767 RunE : prView ,
6868}
6969
70- func prStatus (cmd * cobra.Command , args []string ) error {
71- ctx := contextForCommand (cmd )
70+ func determineBaseRepo (cmd * cobra.Command , ctx context.Context ) (* ghrepo.Interface , error ) {
7271 apiClient , err := apiClientForContext (ctx )
7372 if err != nil {
74- return err
73+ return nil , err
7574 }
7675
77- referSelf , _ := cmd .Flags ().GetBool ( "self " )
78- if referSelf == false {
79- ctx = context . ExpandOnline ( ctx , apiClient )
76+ baseOverride , err := cmd .Flags ().GetString ( "repo " )
77+ if err != nil {
78+ return nil , err
8079 }
8180
82- baseRepo , err := context .DetermineRepo (ctx , referSelf )
81+ baseRepo , err := ctx .BaseRepo ()
82+ if err != nil {
83+ return nil , err
84+ }
85+
86+ preferSelf , err := cmd .Flags ().GetBool ("self" )
87+ if err != nil {
88+ return nil , err
89+ }
90+
91+ if preferSelf == false {
92+ remotes , err := ctx .Remotes ()
93+ if err != nil {
94+ return nil , err
95+ }
96+
97+ repoContext , err := context .ResolveRemotesToRepos (remotes , apiClient , baseOverride )
98+ if err != nil {
99+ return nil , err
100+ }
101+ baseRepo , err = repoContext .BaseRepo ()
102+ }
103+ if err != nil {
104+ return nil , err
105+ }
106+ return & baseRepo , nil
107+ }
108+
109+ func prStatus (cmd * cobra.Command , args []string ) error {
110+ ctx := contextForCommand (cmd )
111+ apiClient , err := apiClientForContext (ctx )
83112 if err != nil {
84113 return err
85114 }
115+
86116 currentPRNumber , currentPRHeadRef , err := prSelectorForCurrentBranch (ctx )
87117 if err != nil {
88118 return err
@@ -92,15 +122,20 @@ func prStatus(cmd *cobra.Command, args []string) error {
92122 return err
93123 }
94124
95- prPayload , err := api .PullRequests (apiClient , baseRepo , currentPRNumber , currentPRHeadRef , currentUser )
125+ baseRepo , err := determineBaseRepo (cmd , ctx )
126+ if err != nil {
127+ return err
128+ }
129+
130+ prPayload , err := api .PullRequests (apiClient , * baseRepo , currentPRNumber , currentPRHeadRef , currentUser )
96131 if err != nil {
97132 return err
98133 }
99134
100135 out := colorableOut (cmd )
101136
102137 fmt .Fprintln (out , "" )
103- fmt .Fprintf (out , "Relevant pull requests in %s\n " , ghrepo .FullName (baseRepo ))
138+ fmt .Fprintf (out , "Relevant pull requests in %s\n " , ghrepo .FullName (* baseRepo ))
104139 fmt .Fprintln (out , "" )
105140
106141 printHeader (out , "Current branch" )
@@ -138,17 +173,12 @@ func prList(cmd *cobra.Command, args []string) error {
138173 return err
139174 }
140175
141- referSelf , _ := cmd .Flags ().GetBool ("self" )
142- if referSelf == false {
143- ctx = context .ExpandOnline (ctx , apiClient )
144- }
145-
146- baseRepo , err := context .DetermineRepo (ctx , referSelf )
176+ baseRepo , err := determineBaseRepo (cmd , ctx )
147177 if err != nil {
148178 return err
149179 }
150180
151- fmt .Fprintf (colorableErr (cmd ), "\n Pull requests for %s\n \n " , ghrepo .FullName (baseRepo ))
181+ fmt .Fprintf (colorableErr (cmd ), "\n Pull requests for %s\n \n " , ghrepo .FullName (* baseRepo ))
152182
153183 limit , err := cmd .Flags ().GetInt ("limit" )
154184 if err != nil {
@@ -186,8 +216,8 @@ func prList(cmd *cobra.Command, args []string) error {
186216 }
187217
188218 params := map [string ]interface {}{
189- "owner" : baseRepo .RepoOwner (),
190- "repo" : baseRepo .RepoName (),
219+ "owner" : ( * baseRepo ) .RepoOwner (),
220+ "repo" : ( * baseRepo ) .RepoName (),
191221 "state" : graphqlState ,
192222 }
193223 if len (labels ) > 0 {
@@ -260,12 +290,7 @@ func prView(cmd *cobra.Command, args []string) error {
260290 return err
261291 }
262292
263- referSelf , _ := cmd .Flags ().GetBool ("self" )
264- if referSelf == false {
265- ctx = context .ExpandOnline (ctx , apiClient )
266- }
267-
268- baseRepo , err := context .DetermineRepo (ctx , referSelf )
293+ baseRepo , err := determineBaseRepo (cmd , ctx )
269294 if err != nil {
270295 return err
271296 }
@@ -278,7 +303,7 @@ func prView(cmd *cobra.Command, args []string) error {
278303 var openURL string
279304 var pr * api.PullRequest
280305 if len (args ) > 0 {
281- pr , err = prFromArg (apiClient , baseRepo , args [0 ])
306+ pr , err = prFromArg (apiClient , * baseRepo , args [0 ])
282307 if err != nil {
283308 return err
284309 }
@@ -290,15 +315,15 @@ func prView(cmd *cobra.Command, args []string) error {
290315 }
291316
292317 if prNumber > 0 {
293- openURL = fmt .Sprintf ("https://github.com/%s/pull/%d" , ghrepo .FullName (baseRepo ), prNumber )
318+ openURL = fmt .Sprintf ("https://github.com/%s/pull/%d" , ghrepo .FullName (* baseRepo ), prNumber )
294319 if preview {
295- pr , err = api .PullRequestByNumber (apiClient , baseRepo , prNumber )
320+ pr , err = api .PullRequestByNumber (apiClient , * baseRepo , prNumber )
296321 if err != nil {
297322 return err
298323 }
299324 }
300325 } else {
301- pr , err = api .PullRequestForBranch (apiClient , baseRepo , branchWithOwner )
326+ pr , err = api .PullRequestForBranch (apiClient , * baseRepo , branchWithOwner )
302327 if err != nil {
303328 return err
304329 }
0 commit comments