diff --git a/command/issue.go b/command/issue.go index 5de86da91..0bc870dcc 100644 --- a/command/issue.go +++ b/command/issue.go @@ -227,7 +227,7 @@ func issueList(cmd *cobra.Command, args []string) error { } if web { - issueListURL := generateRepoURL(baseRepo, "issues") + issueListURL := ghrepo.GenerateRepoURL(baseRepo, "issues") openURL, err := listURLWithQuery(issueListURL, filterOptions{ entity: "issue", state: state, @@ -504,7 +504,7 @@ func issueCreate(cmd *cobra.Command, args []string) error { } if isWeb, err := cmd.Flags().GetBool("web"); err == nil && isWeb { - openURL := generateRepoURL(baseRepo, "issues/new") + openURL := ghrepo.GenerateRepoURL(baseRepo, "issues/new") if title != "" || body != "" { milestone := "" if len(milestoneTitles) > 0 { @@ -582,7 +582,7 @@ func issueCreate(cmd *cobra.Command, args []string) error { } if action == PreviewAction { - openURL := generateRepoURL(baseRepo, "issues/new") + openURL := ghrepo.GenerateRepoURL(baseRepo, "issues/new") milestone := "" if len(milestoneTitles) > 0 { milestone = milestoneTitles[0] @@ -618,14 +618,6 @@ func issueCreate(cmd *cobra.Command, args []string) error { return nil } -func generateRepoURL(repo ghrepo.Interface, p string, args ...interface{}) string { - baseURL := fmt.Sprintf("https://%s/%s/%s", repo.RepoHost(), repo.RepoOwner(), repo.RepoName()) - if p != "" { - return baseURL + "/" + fmt.Sprintf(p, args...) - } - return baseURL -} - func addMetadataToIssueParams(client *api.Client, baseRepo ghrepo.Interface, params map[string]interface{}, tb *issueMetadataState) error { if !tb.HasMetadata() { return nil diff --git a/command/pr.go b/command/pr.go index 9978d18be..6d276d833 100644 --- a/command/pr.go +++ b/command/pr.go @@ -235,7 +235,7 @@ func prList(cmd *cobra.Command, args []string) error { } if web { - prListURL := generateRepoURL(baseRepo, "pulls") + prListURL := ghrepo.GenerateRepoURL(baseRepo, "pulls") openURL, err := listURLWithQuery(prListURL, filterOptions{ entity: "pr", state: state, diff --git a/command/pr_create.go b/command/pr_create.go index b66a7ff5d..97dc018d1 100644 --- a/command/pr_create.go +++ b/command/pr_create.go @@ -447,7 +447,7 @@ func withPrAndIssueQueryParams(baseURL, title, body string, assignees, labels, p } func generateCompareURL(r ghrepo.Interface, base, head, title, body string, assignees, labels, projects []string, milestone string) (string, error) { - u := generateRepoURL(r, "compare/%s...%s?expand=1", base, head) + u := ghrepo.GenerateRepoURL(r, "compare/%s...%s?expand=1", base, head) url, err := withPrAndIssueQueryParams(u, title, body, assignees, labels, projects, milestone) if err != nil { return "", err diff --git a/internal/ghrepo/repo.go b/internal/ghrepo/repo.go index fbe748204..9b0a7ac30 100644 --- a/internal/ghrepo/repo.go +++ b/internal/ghrepo/repo.go @@ -77,6 +77,14 @@ func IsSame(a, b Interface) bool { normalizeHostname(a.RepoHost()) == normalizeHostname(b.RepoHost()) } +func GenerateRepoURL(repo Interface, p string, args ...interface{}) string { + baseURL := fmt.Sprintf("https://%s/%s/%s", repo.RepoHost(), repo.RepoOwner(), repo.RepoName()) + if p != "" { + return baseURL + "/" + fmt.Sprintf(p, args...) + } + return baseURL +} + type ghRepo struct { owner string name string diff --git a/pkg/cmd/repo/view/view.go b/pkg/cmd/repo/view/view.go index f3a5cb998..aaa553371 100644 --- a/pkg/cmd/repo/view/view.go +++ b/pkg/cmd/repo/view/view.go @@ -97,7 +97,7 @@ func viewRun(opts *ViewOptions) error { return err } - openURL := generateRepoURL(toView, "") + openURL := ghrepo.GenerateRepoURL(toView, "") if opts.Web { if opts.IO.IsStdoutTTY() { fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", displayURL(openURL)) @@ -192,14 +192,6 @@ func isURL(arg string) bool { return strings.HasPrefix(arg, "http:/") || strings.HasPrefix(arg, "https:/") } -func generateRepoURL(repo ghrepo.Interface, p string, args ...interface{}) string { - baseURL := fmt.Sprintf("https://%s/%s/%s", repo.RepoHost(), repo.RepoOwner(), repo.RepoName()) - if p != "" { - return baseURL + "/" + fmt.Sprintf(p, args...) - } - return baseURL -} - func displayURL(urlStr string) string { u, err := url.Parse(urlStr) if err != nil {