File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed
Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments