Merge pull request #943 from cli/reauth-bug

pass apiClient to determineBaseRepo
This commit is contained in:
Mislav Marohnić 2020-05-18 13:16:07 +02:00 committed by GitHub
commit 4d11732a47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 35 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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 := ""

View file

@ -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

View file

@ -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