Skip to content

Commit

Permalink
use resolve remotes code in issue commands
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Feb 12, 2020
1 parent f653dbb commit ad17011
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
37 changes: 22 additions & 15 deletions command/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ func init() {
issueCreateCmd.Flags().StringP("body", "b", "",
"Supply a body. Will prompt for one otherwise.")
issueCreateCmd.Flags().BoolP("web", "w", false, "Open the browser to create an issue")
issueCreateCmd.Flags().BoolP("self", "S", false, "Query current repository instead of forked parent")

issueCmd.AddCommand(issueListCmd)
issueListCmd.Flags().StringP("assignee", "a", "", "Filter by assignee")
issueListCmd.Flags().StringSliceP("label", "l", nil, "Filter by label")
issueListCmd.Flags().StringP("state", "s", "", "Filter by state: {open|closed|all}")
issueListCmd.Flags().IntP("limit", "L", 30, "Maximum number of issues to fetch")
issueListCmd.Flags().BoolP("self", "S", false, "Query current repository instead of forked parent")

issueViewCmd.Flags().BoolP("preview", "p", false, "Display preview of issue content")
issueViewCmd.Flags().BoolP("self", "S", false, "Query current repository instead of forked parent")

issueStatusCmd.Flags().BoolP("self", "S", false, "Query current repository instead of forked parent")
}

var issueCmd = &cobra.Command{
Expand Down Expand Up @@ -83,7 +88,7 @@ func issueList(cmd *cobra.Command, args []string) error {
return err
}

baseRepo, err := ctx.BaseRepo()
baseRepo, err := determineBaseRepo(cmd, ctx)
if err != nil {
return err
}
Expand All @@ -108,9 +113,9 @@ func issueList(cmd *cobra.Command, args []string) error {
return err
}

fmt.Fprintf(colorableErr(cmd), "\nIssues for %s\n\n", ghrepo.FullName(baseRepo))
fmt.Fprintf(colorableErr(cmd), "\nIssues for %s\n\n", ghrepo.FullName(*baseRepo))

issues, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit)
issues, err := api.IssueList(apiClient, *baseRepo, state, labels, assignee, limit)
if err != nil {
return err
}
Expand Down Expand Up @@ -158,7 +163,7 @@ func issueStatus(cmd *cobra.Command, args []string) error {
return err
}

baseRepo, err := ctx.BaseRepo()
baseRepo, err := determineBaseRepo(cmd, ctx)
if err != nil {
return err
}
Expand All @@ -168,15 +173,15 @@ func issueStatus(cmd *cobra.Command, args []string) error {
return err
}

issuePayload, err := api.IssueStatus(apiClient, baseRepo, currentUser)
issuePayload, err := api.IssueStatus(apiClient, *baseRepo, currentUser)
if err != nil {
return err
}

out := colorableOut(cmd)

fmt.Fprintln(out, "")
fmt.Fprintf(out, "Relevant issues in %s\n", ghrepo.FullName(baseRepo))
fmt.Fprintf(out, "Relevant issues in %s\n", ghrepo.FullName(*baseRepo))
fmt.Fprintln(out, "")

printHeader(out, "Issues assigned to you")
Expand Down Expand Up @@ -210,16 +215,17 @@ func issueStatus(cmd *cobra.Command, args []string) error {
func issueView(cmd *cobra.Command, args []string) error {
ctx := contextForCommand(cmd)

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

baseRepo, err := determineBaseRepo(cmd, ctx)
if err != nil {
return err
}

issue, err := issueFromArg(apiClient, baseRepo, args[0])
issue, err := issueFromArg(apiClient, *baseRepo, args[0])
if err != nil {
return err
}
Expand Down Expand Up @@ -278,12 +284,13 @@ func issueFromArg(apiClient *api.Client, baseRepo ghrepo.Interface, arg string)
func issueCreate(cmd *cobra.Command, args []string) error {
ctx := contextForCommand(cmd)

baseRepo, err := ctx.BaseRepo()
// NB no auto forking like over in pr create
baseRepo, err := determineBaseRepo(cmd, ctx)
if err != nil {
return err
}

fmt.Fprintf(colorableErr(cmd), "\nCreating issue in %s\n\n", ghrepo.FullName(baseRepo))
fmt.Fprintf(colorableErr(cmd), "\nCreating issue in %s\n\n", ghrepo.FullName(*baseRepo))

var templateFiles []string
if rootDir, err := git.ToplevelDir(); err == nil {
Expand All @@ -293,7 +300,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {

if isWeb, err := cmd.Flags().GetBool("web"); err == nil && isWeb {
// TODO: move URL generation into GitHubRepository
openURL := fmt.Sprintf("https://github.com/%s/issues/new", ghrepo.FullName(baseRepo))
openURL := fmt.Sprintf("https://github.com/%s/issues/new", ghrepo.FullName(*baseRepo))
if len(templateFiles) > 1 {
openURL += "/choose"
}
Expand All @@ -306,12 +313,12 @@ func issueCreate(cmd *cobra.Command, args []string) error {
return err
}

repo, err := api.GitHubRepo(apiClient, baseRepo)
repo, err := api.GitHubRepo(apiClient, *baseRepo)
if err != nil {
return err
}
if !repo.HasIssuesEnabled {
return fmt.Errorf("the '%s' repository has disabled issues", ghrepo.FullName(baseRepo))
return fmt.Errorf("the '%s' repository has disabled issues", ghrepo.FullName(*baseRepo))
}

action := SubmitAction
Expand Down Expand Up @@ -352,7 +359,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
if action == PreviewAction {
openURL := fmt.Sprintf(
"https://github.com/%s/issues/new/?title=%s&body=%s",
ghrepo.FullName(baseRepo),
ghrepo.FullName(*baseRepo),
url.QueryEscape(title),
url.QueryEscape(body),
)
Expand Down
5 changes: 5 additions & 0 deletions command/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func determineBaseRepo(cmd *cobra.Command, ctx context.Context) (*ghrepo.Interfa
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
Expand Down

0 comments on commit ad17011

Please sign in to comment.