@@ -10,28 +10,36 @@ import (
1010 "github.com/cli/cli/context"
1111 "github.com/cli/cli/git"
1212 "github.com/cli/cli/internal/ghrepo"
13+ "github.com/spf13/cobra"
1314)
1415
15- func prFromArgs (ctx context.Context , apiClient * api.Client , repo ghrepo.Interface , args []string ) (* api.PullRequest , error ) {
16+ func prFromArgs (ctx context.Context , apiClient * api.Client , cmd * cobra.Command , args []string ) (* api.PullRequest , ghrepo.Interface , error ) {
17+ repo , err := determineBaseRepo (apiClient , cmd , ctx )
18+ if err != nil {
19+ return nil , nil , fmt .Errorf ("could not determine base repo: %w" , err )
20+ }
21+
1622 if len (args ) == 0 {
17- return prForCurrentBranch (ctx , apiClient , repo )
23+ pr , err := prForCurrentBranch (ctx , apiClient , repo )
24+ return pr , repo , err
1825 }
1926
20- // First check to see if the prString is a url
27+ // First check to see if the prString is a url, return repo from url if found
2128 prString := args [0 ]
22- pr , err := prFromURL (ctx , apiClient , repo , prString )
29+ pr , r , err := prFromURL (ctx , apiClient , prString )
2330 if pr != nil || err != nil {
24- return pr , err
31+ return pr , r , err
2532 }
2633
2734 // Next see if the prString is a number and use that to look up the url
2835 pr , err = prFromNumberString (ctx , apiClient , repo , prString )
2936 if pr != nil || err != nil {
30- return pr , err
37+ return pr , repo , err
3138 }
3239
3340 // Last see if it is a branch name
34- return api .PullRequestForBranch (apiClient , repo , "" , prString )
41+ pr , err = api .PullRequestForBranch (apiClient , repo , "" , prString )
42+ return pr , repo , err
3543}
3644
3745func prFromNumberString (ctx context.Context , apiClient * api.Client , repo ghrepo.Interface , s string ) (* api.PullRequest , error ) {
@@ -42,14 +50,16 @@ func prFromNumberString(ctx context.Context, apiClient *api.Client, repo ghrepo.
4250 return nil , nil
4351}
4452
45- func prFromURL (ctx context.Context , apiClient * api.Client , repo ghrepo. Interface , s string ) (* api.PullRequest , error ) {
53+ func prFromURL (ctx context.Context , apiClient * api.Client , s string ) (* api.PullRequest , ghrepo. Interface , error ) {
4654 r := regexp .MustCompile (`^https://github\.com/([^/]+)/([^/]+)/pull/(\d+)` )
4755 if m := r .FindStringSubmatch (s ); m != nil {
56+ repo := ghrepo .New (m [1 ], m [2 ])
4857 prNumberString := m [3 ]
49- return prFromNumberString (ctx , apiClient , repo , prNumberString )
58+ pr , err := prFromNumberString (ctx , apiClient , repo , prNumberString )
59+ return pr , repo , err
5060 }
5161
52- return nil , nil
62+ return nil , nil , nil
5363}
5464
5565func prForCurrentBranch (ctx context.Context , apiClient * api.Client , repo ghrepo.Interface ) (* api.PullRequest , error ) {
0 commit comments