Skip to content

Commit

Permalink
move determineBaseRepo to root
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Feb 12, 2020
1 parent ad17011 commit c93c5f7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 44 deletions.
44 changes: 0 additions & 44 deletions command/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,50 +67,6 @@ branch is opened.`,
RunE: prView,
}

func determineBaseRepo(cmd *cobra.Command, ctx context.Context) (*ghrepo.Interface, error) {
apiClient, err := apiClientForContext(ctx)
if err != nil {
return nil, err
}

baseOverride, err := cmd.Flags().GetString("repo")
if err != nil {
return nil, err
}

baseRepo, err := ctx.BaseRepo()
if err != nil {
return nil, err
}

preferSelf, err := cmd.Flags().GetBool("self")
if err != nil {
return nil, err
}

if preferSelf == false {
remotes, err := ctx.Remotes()
if err != nil {
return nil, err
}

// TODO given remotes:
// [upstream] cli/cli
// [origin] vilmibm/cli
// we're picking the wrong thing. i think preferSelf needs to be threaded through to
// ResolveRemotesToRepos in the same way as baseOverride.
repoContext, err := context.ResolveRemotesToRepos(remotes, apiClient, baseOverride)
if err != nil {
return nil, err
}
baseRepo, err = repoContext.BaseRepo()
}
if err != nil {
return nil, err
}
return &baseRepo, nil
}

func prStatus(cmd *cobra.Command, args []string) error {
ctx := contextForCommand(cmd)
apiClient, err := apiClientForContext(ctx)
Expand Down
45 changes: 45 additions & 0 deletions command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/cli/cli/api"
"github.com/cli/cli/context"
"github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/utils"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -151,3 +152,47 @@ func changelogURL(version string) string {
url := fmt.Sprintf("%s/releases/tag/v%s", path, strings.TrimPrefix(version, "v"))
return url
}

func determineBaseRepo(cmd *cobra.Command, ctx context.Context) (*ghrepo.Interface, error) {
apiClient, err := apiClientForContext(ctx)
if err != nil {
return nil, err
}

baseOverride, err := cmd.Flags().GetString("repo")
if err != nil {
return nil, err
}

baseRepo, err := ctx.BaseRepo()
if err != nil {
return nil, err
}

preferSelf, err := cmd.Flags().GetBool("self")
if err != nil {
return nil, err
}

if preferSelf == false {
remotes, err := ctx.Remotes()
if err != nil {
return nil, err
}

// TODO given remotes:
// [upstream] cli/cli
// [origin] vilmibm/cli
// we're picking the wrong thing. i think preferSelf needs to be threaded through to
// ResolveRemotesToRepos in the same way as baseOverride.
repoContext, err := context.ResolveRemotesToRepos(remotes, apiClient, baseOverride)
if err != nil {
return nil, err
}
baseRepo, err = repoContext.BaseRepo()
}
if err != nil {
return nil, err
}
return &baseRepo, nil
}

0 comments on commit c93c5f7

Please sign in to comment.