From 90f6a73ba59ed0057e58f56f02201923211cc565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 22 Jan 2020 22:57:54 +0100 Subject: [PATCH] Extract helper to print a URL --- command/issue.go | 14 +++++++++----- command/pr_create.go | 6 +----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/command/issue.go b/command/issue.go index 139ab3337..67889cf53 100644 --- a/command/issue.go +++ b/command/issue.go @@ -354,11 +354,7 @@ func issueCreate(cmd *cobra.Command, args []string) error { url.QueryEscape(body), ) // TODO could exceed max url length for explorer - url, err := url.Parse(openURL) - if err != nil { - return err - } - fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s%s in your browser.\n", url.Host, url.Path) + fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(openURL)) return utils.OpenInBrowser(openURL) } else if action == SubmitAction { params := map[string]interface{}{ @@ -417,3 +413,11 @@ func labelList(issue api.Issue) string { } return list } + +func displayURL(urlStr string) string { + u, err := url.Parse(urlStr) + if err != nil { + return urlStr + } + return u.Hostname() + u.Path +} diff --git a/command/pr_create.go b/command/pr_create.go index a72dff7ff..352fe36b0 100644 --- a/command/pr_create.go +++ b/command/pr_create.go @@ -149,11 +149,7 @@ func prCreate(cmd *cobra.Command, _ []string) error { url.QueryEscape(body), ) // TODO could exceed max url length for explorer - url, err := url.Parse(openURL) - if err != nil { - return err - } - fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s%s in your browser.\n", url.Host, url.Path) + fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(openURL)) return utils.OpenInBrowser(openURL) } else { panic("Unreachable state")