move generateRepoURL to ghrepo
This commit is contained in:
parent
895af993a5
commit
dc02366128
5 changed files with 14 additions and 22 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue