Skip to content

Commit dc02366

Browse files
committed
move generateRepoURL to ghrepo
1 parent 895af99 commit dc02366

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

command/issue.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func issueList(cmd *cobra.Command, args []string) error {
227227
}
228228

229229
if web {
230-
issueListURL := generateRepoURL(baseRepo, "issues")
230+
issueListURL := ghrepo.GenerateRepoURL(baseRepo, "issues")
231231
openURL, err := listURLWithQuery(issueListURL, filterOptions{
232232
entity: "issue",
233233
state: state,
@@ -504,7 +504,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
504504
}
505505

506506
if isWeb, err := cmd.Flags().GetBool("web"); err == nil && isWeb {
507-
openURL := generateRepoURL(baseRepo, "issues/new")
507+
openURL := ghrepo.GenerateRepoURL(baseRepo, "issues/new")
508508
if title != "" || body != "" {
509509
milestone := ""
510510
if len(milestoneTitles) > 0 {
@@ -582,7 +582,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
582582
}
583583

584584
if action == PreviewAction {
585-
openURL := generateRepoURL(baseRepo, "issues/new")
585+
openURL := ghrepo.GenerateRepoURL(baseRepo, "issues/new")
586586
milestone := ""
587587
if len(milestoneTitles) > 0 {
588588
milestone = milestoneTitles[0]
@@ -618,14 +618,6 @@ func issueCreate(cmd *cobra.Command, args []string) error {
618618
return nil
619619
}
620620

621-
func generateRepoURL(repo ghrepo.Interface, p string, args ...interface{}) string {
622-
baseURL := fmt.Sprintf("https://%s/%s/%s", repo.RepoHost(), repo.RepoOwner(), repo.RepoName())
623-
if p != "" {
624-
return baseURL + "/" + fmt.Sprintf(p, args...)
625-
}
626-
return baseURL
627-
}
628-
629621
func addMetadataToIssueParams(client *api.Client, baseRepo ghrepo.Interface, params map[string]interface{}, tb *issueMetadataState) error {
630622
if !tb.HasMetadata() {
631623
return nil

command/pr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func prList(cmd *cobra.Command, args []string) error {
235235
}
236236

237237
if web {
238-
prListURL := generateRepoURL(baseRepo, "pulls")
238+
prListURL := ghrepo.GenerateRepoURL(baseRepo, "pulls")
239239
openURL, err := listURLWithQuery(prListURL, filterOptions{
240240
entity: "pr",
241241
state: state,

command/pr_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func withPrAndIssueQueryParams(baseURL, title, body string, assignees, labels, p
447447
}
448448

449449
func generateCompareURL(r ghrepo.Interface, base, head, title, body string, assignees, labels, projects []string, milestone string) (string, error) {
450-
u := generateRepoURL(r, "compare/%s...%s?expand=1", base, head)
450+
u := ghrepo.GenerateRepoURL(r, "compare/%s...%s?expand=1", base, head)
451451
url, err := withPrAndIssueQueryParams(u, title, body, assignees, labels, projects, milestone)
452452
if err != nil {
453453
return "", err

internal/ghrepo/repo.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ func IsSame(a, b Interface) bool {
7777
normalizeHostname(a.RepoHost()) == normalizeHostname(b.RepoHost())
7878
}
7979

80+
func GenerateRepoURL(repo Interface, p string, args ...interface{}) string {
81+
baseURL := fmt.Sprintf("https://%s/%s/%s", repo.RepoHost(), repo.RepoOwner(), repo.RepoName())
82+
if p != "" {
83+
return baseURL + "/" + fmt.Sprintf(p, args...)
84+
}
85+
return baseURL
86+
}
87+
8088
type ghRepo struct {
8189
owner string
8290
name string

pkg/cmd/repo/view/view.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func viewRun(opts *ViewOptions) error {
9797
return err
9898
}
9999

100-
openURL := generateRepoURL(toView, "")
100+
openURL := ghrepo.GenerateRepoURL(toView, "")
101101
if opts.Web {
102102
if opts.IO.IsStdoutTTY() {
103103
fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", displayURL(openURL))
@@ -192,14 +192,6 @@ func isURL(arg string) bool {
192192
return strings.HasPrefix(arg, "http:/") || strings.HasPrefix(arg, "https:/")
193193
}
194194

195-
func generateRepoURL(repo ghrepo.Interface, p string, args ...interface{}) string {
196-
baseURL := fmt.Sprintf("https://%s/%s/%s", repo.RepoHost(), repo.RepoOwner(), repo.RepoName())
197-
if p != "" {
198-
return baseURL + "/" + fmt.Sprintf(p, args...)
199-
}
200-
return baseURL
201-
}
202-
203195
func displayURL(urlStr string) string {
204196
u, err := url.Parse(urlStr)
205197
if err != nil {

0 commit comments

Comments
 (0)