diff --git a/command/root.go b/command/root.go index 26888d699..02ffff646 100644 --- a/command/root.go +++ b/command/root.go @@ -143,12 +143,11 @@ func colorableErr(cmd *cobra.Command) io.Writer { func changelogURL(version string) string { path := "https://github.com/cli/cli" - r := regexp.MustCompile(`^v\d+\.\d+.\d+$`) + r := regexp.MustCompile(`^\d+\.\d+.\d+(-[\w.]+)?$`) if !r.MatchString(version) { return fmt.Sprintf("%s/releases/latest", path) } - tag := version - url := fmt.Sprintf("%s/releases/tag/%s", path, tag) + url := fmt.Sprintf("%s/releases/tag/v%s", path, version) return url } diff --git a/command/root_test.go b/command/root_test.go index 46da89845..1da650519 100644 --- a/command/root_test.go +++ b/command/root_test.go @@ -6,13 +6,20 @@ import ( ) func TestChangelogURL(t *testing.T) { - tag := "v0.3.2" + tag := "0.3.2" url := fmt.Sprintf("https://github.com/cli/cli/releases/tag/v0.3.2") result := changelogURL(tag) if result != url { t.Errorf("expected %s to create url %s but got %s", tag, url, result) } + tag = "0.3.2-pre.1" + url = fmt.Sprintf("https://github.com/cli/cli/releases/tag/v0.3.2-pre.1") + result = changelogURL(tag) + if result != url { + t.Errorf("expected %s to create url %s but got %s", tag, url, result) + } + tag = "0.3.5-90-gdd3f0e0" url = fmt.Sprintf("https://github.com/cli/cli/releases/latest") result = changelogURL(tag)