Skip to content

Commit

Permalink
Merge pull request #943 from cli/reauth-bug
Browse files Browse the repository at this point in the history
pass apiClient to determineBaseRepo
  • Loading branch information
mislav committed May 18, 2020
2 parents d440a95 + c8c807b commit 4d11732
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 34 deletions.
21 changes: 10 additions & 11 deletions command/issue.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions command/pr.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion command/pr_checkout.go
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions command/pr_review.go
Expand Up @@ -86,14 +86,14 @@ func processReviewOpt(cmd *cobra.Command) (*api.PullRequestReviewInput, error) {

func prReview(cmd *cobra.Command, args []string) error {
ctx := contextForCommand(cmd)
baseRepo, err := determineBaseRepo(cmd, ctx)
apiClient, err := apiClientForContext(ctx)
if err != nil {
return fmt.Errorf("could not determine base repo: %w", err)
return err
}

apiClient, err := apiClientForContext(ctx)
baseRepo, err := determineBaseRepo(apiClient, cmd, ctx)
if err != nil {
return err
return fmt.Errorf("could not determine base repo: %w", err)
}

var prNum int
Expand Down
12 changes: 6 additions & 6 deletions command/repo.go
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions command/root.go
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 4d11732

Please sign in to comment.