Skip to content

Commit 1921a74

Browse files
committed
Add changelog func
1 parent 869f50e commit 1921a74

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

command/root.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"os"
7+
"regexp"
78
"strings"
89

910
"github.com/github/gh-cli/api"
@@ -56,7 +57,7 @@ var versionCmd = &cobra.Command{
5657
Use: "version",
5758
Hidden: true,
5859
Run: func(cmd *cobra.Command, args []string) {
59-
fmt.Printf("gh version %s\n", RootCmd.Version)
60+
fmt.Printf("gh version %s\n%s\n", RootCmd.Version, changelogURL(RootCmd.Version))
6061
},
6162
}
6263

@@ -128,3 +129,15 @@ func colorableErr(cmd *cobra.Command) io.Writer {
128129
}
129130
return err
130131
}
132+
133+
func changelogURL(version string) string {
134+
path := "https://github.com/github/homebrew-gh"
135+
r := regexp.MustCompile(`^v\d+\.\d+.\d+$`)
136+
if !r.MatchString(version) {
137+
return fmt.Sprintf("%s/releases/latest", path)
138+
}
139+
140+
tag := version
141+
url := fmt.Sprintf("%s/releases/tag/%s", path, tag)
142+
return url
143+
}

command/root_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package command
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
func TestChangelogURL(t *testing.T) {
9+
tag := "v0.3.2"
10+
url := fmt.Sprintf("https://github.com/github/homebrew-gh/releases/tag/v0.3.2")
11+
result := changelogURL(tag)
12+
if result != url {
13+
t.Errorf("expected %s to create url %s but got %s", tag, url, result)
14+
}
15+
16+
tag = "0.3.5-90-gdd3f0e0"
17+
url = fmt.Sprintf("https://github.com/github/homebrew-gh/releases/latest")
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+
23+
tag = "deadbeef"
24+
url = fmt.Sprintf("https://github.com/github/homebrew-gh/releases/latest")
25+
result = changelogURL(tag)
26+
if result != url {
27+
t.Errorf("expected %s to create url %s but got %s", tag, url, result)
28+
}
29+
}

0 commit comments

Comments
 (0)