Skip to content

Commit 6a6a6cc

Browse files
authored
Merge pull request cli#274 from cli/fix-change-link-fo-realz
Fix `gh version` printing the correct changelog link
2 parents 0a3ef15 + 2a49efc commit 6a6a6cc

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

command/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var versionOutput = ""
2424

2525
func init() {
2626
RootCmd.Version = fmt.Sprintf("%s (%s)", strings.TrimPrefix(Version, "v"), BuildDate)
27-
versionOutput = fmt.Sprintf("gh version %s\n%s\n", RootCmd.Version, changelogURL(RootCmd.Version))
27+
versionOutput = fmt.Sprintf("gh version %s\n%s\n", RootCmd.Version, changelogURL(Version))
2828
RootCmd.AddCommand(versionCmd)
2929
RootCmd.SetVersionTemplate(versionOutput)
3030

@@ -143,11 +143,11 @@ func colorableErr(cmd *cobra.Command) io.Writer {
143143

144144
func changelogURL(version string) string {
145145
path := "https://github.com/cli/cli"
146-
r := regexp.MustCompile(`^\d+\.\d+.\d+(-[\w.]+)?$`)
146+
r := regexp.MustCompile(`^v?\d+\.\d+\.\d+(-[\w.]+)?$`)
147147
if !r.MatchString(version) {
148148
return fmt.Sprintf("%s/releases/latest", path)
149149
}
150150

151-
url := fmt.Sprintf("%s/releases/tag/v%s", path, version)
151+
url := fmt.Sprintf("%s/releases/tag/v%s", path, strings.TrimPrefix(version, "v"))
152152
return url
153153
}

command/root_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ func TestChangelogURL(t *testing.T) {
1313
t.Errorf("expected %s to create url %s but got %s", tag, url, result)
1414
}
1515

16+
tag = "v0.3.2"
17+
url = fmt.Sprintf("https://github.com/cli/cli/releases/tag/v0.3.2")
18+
result = changelogURL(tag)
19+
if result != url {
20+
t.Errorf("expected %s to create url %s but got %s", tag, url, result)
21+
}
22+
1623
tag = "0.3.2-pre.1"
1724
url = fmt.Sprintf("https://github.com/cli/cli/releases/tag/v0.3.2-pre.1")
1825
result = changelogURL(tag)

0 commit comments

Comments
 (0)