diff --git a/command/issue.go b/command/issue.go index 5eed13a13..3c7727e53 100644 --- a/command/issue.go +++ b/command/issue.go @@ -106,7 +106,7 @@ func issueList(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -167,7 +167,7 @@ func issueStatus(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -224,7 +224,7 @@ func issueView(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -340,9 +340,13 @@ func issueFromArg(apiClient *api.Client, baseRepo ghrepo.Interface, arg string) func issueCreate(cmd *cobra.Command, args []string) error { ctx := contextForCommand(cmd) + apiClient, err := apiClientForContext(ctx) + if err != nil { + return err + } // NB no auto forking like over in pr create - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -406,11 +410,6 @@ func issueCreate(cmd *cobra.Command, args []string) error { fmt.Fprintf(colorableErr(cmd), "\nCreating issue in %s\n\n", ghrepo.FullName(baseRepo)) - apiClient, err := apiClientForContext(ctx) - if err != nil { - return err - } - repo, err := api.GitHubRepo(apiClient, baseRepo) if err != nil { return err @@ -654,7 +653,7 @@ func issueClose(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -689,7 +688,7 @@ func issueReopen(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } diff --git a/command/pr.go b/command/pr.go index 2407e0867..ee529aa9f 100644 --- a/command/pr.go +++ b/command/pr.go @@ -104,7 +104,7 @@ func prStatus(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -168,7 +168,7 @@ func prList(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -307,7 +307,7 @@ func prView(cmd *cobra.Command, args []string) error { } if baseRepo == nil { - baseRepo, err = determineBaseRepo(cmd, ctx) + baseRepo, err = determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -366,7 +366,7 @@ func prClose(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -401,7 +401,7 @@ func prReopen(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -438,7 +438,7 @@ func prMerge(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } diff --git a/command/pr_checkout.go b/command/pr_checkout.go index 7da76f6ce..aa9e3afcc 100644 --- a/command/pr_checkout.go +++ b/command/pr_checkout.go @@ -34,7 +34,7 @@ func prCheckout(cmd *cobra.Command, args []string) error { } if baseRepo == nil { - baseRepo, err = determineBaseRepo(cmd, ctx) + baseRepo, err = determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } diff --git a/command/pr_review.go b/command/pr_review.go index d51aaff03..3b1a4ab88 100644 --- a/command/pr_review.go +++ b/command/pr_review.go @@ -86,16 +86,16 @@ func processReviewOpt(cmd *cobra.Command) (*api.PullRequestReviewInput, error) { func prReview(cmd *cobra.Command, args []string) error { ctx := contextForCommand(cmd) - baseRepo, err := determineBaseRepo(cmd, ctx) - if err != nil { - return fmt.Errorf("could not determine base repo: %w", err) - } - apiClient, err := apiClientForContext(ctx) if err != nil { return err } + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) + if err != nil { + return fmt.Errorf("could not determine base repo: %w", err) + } + var prNum int branchWithOwner := "" diff --git a/command/repo.go b/command/repo.go index 67e9393ea..ad208a277 100644 --- a/command/repo.go +++ b/command/repo.go @@ -339,7 +339,7 @@ func repoFork(cmd *cobra.Command, args []string) error { var repoToFork ghrepo.Interface inParent := false // whether or not we're forking the repo we're currently "in" if len(args) == 0 { - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return fmt.Errorf("unable to determine base repository: %w", err) } @@ -490,11 +490,15 @@ var Confirm = func(prompt string, result *bool) error { func repoView(cmd *cobra.Command, args []string) error { ctx := contextForCommand(cmd) + apiClient, err := apiClientForContext(ctx) + if err != nil { + return err + } var toView ghrepo.Interface if len(args) == 0 { var err error - toView, err = determineBaseRepo(cmd, ctx) + toView, err = determineBaseRepo(apiClient, cmd, ctx) if err != nil { return err } @@ -519,10 +523,6 @@ func repoView(cmd *cobra.Command, args []string) error { } } - apiClient, err := apiClientForContext(ctx) - if err != nil { - return err - } repo, err := api.GitHubRepo(apiClient, toView) if err != nil { return err diff --git a/command/root.go b/command/root.go index 8b807e622..6233be957 100644 --- a/command/root.go +++ b/command/root.go @@ -216,7 +216,7 @@ func changelogURL(version string) string { return url } -func determineBaseRepo(cmd *cobra.Command, ctx context.Context) (ghrepo.Interface, error) { +func determineBaseRepo(apiClient *api.Client, cmd *cobra.Command, ctx context.Context) (ghrepo.Interface, error) { repo, err := cmd.Flags().GetString("repo") if err == nil && repo != "" { baseRepo, err := ghrepo.FromFullName(repo) @@ -226,11 +226,6 @@ func determineBaseRepo(cmd *cobra.Command, ctx context.Context) (ghrepo.Interfac return baseRepo, nil } - apiClient, err := apiClientForContext(ctx) - if err != nil { - return nil, err - } - baseOverride, err := cmd.Flags().GetString("repo") if err != nil { return nil, err