Fix current changelog link in gh version
Also allow pre-release tags.
This commit is contained in:
parent
1c74227ed7
commit
7b28605e6f
2 changed files with 10 additions and 4 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue