From 18b19e074da2c2f04af78c59c75d0a168662aed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 16 Dec 2020 17:07:41 +0100 Subject: [PATCH] Fix link in `version` output It now correctly links to the tagged release instead of to the latest release. --- pkg/cmd/version/version.go | 5 +++-- pkg/cmd/version/version_test.go | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/version/version.go b/pkg/cmd/version/version.go index 040a3132e..d473ab0b2 100644 --- a/pkg/cmd/version/version.go +++ b/pkg/cmd/version/version.go @@ -26,11 +26,12 @@ func NewCmdVersion(f *cmdutil.Factory, version, buildDate string) *cobra.Command func Format(version, buildDate string) string { version = strings.TrimPrefix(version, "v") + var dateStr string if buildDate != "" { - version = fmt.Sprintf("%s (%s)", version, buildDate) + dateStr = fmt.Sprintf(" (%s)", buildDate) } - return fmt.Sprintf("gh version %s\n%s\n", version, changelogURL(version)) + return fmt.Sprintf("gh version %s%s\n%s\n", version, dateStr, changelogURL(version)) } func changelogURL(version string) string { diff --git a/pkg/cmd/version/version_test.go b/pkg/cmd/version/version_test.go index 9a1d49db3..be1065dfd 100644 --- a/pkg/cmd/version/version_test.go +++ b/pkg/cmd/version/version_test.go @@ -4,6 +4,13 @@ import ( "testing" ) +func TestFormat(t *testing.T) { + expects := "gh version 1.4.0 (2020-12-15)\nhttps://github.com/cli/cli/releases/tag/v1.4.0\n" + if got := Format("1.4.0", "2020-12-15"); got != expects { + t.Errorf("Format() = %q, wants %q", got, expects) + } +} + func TestChangelogURL(t *testing.T) { tag := "0.3.2" url := "https://github.com/cli/cli/releases/tag/v0.3.2"