77 "crypto/sha256"
88 _ "embed"
99 "encoding/hex"
10+ "encoding/json"
1011 "errors"
1112 "fmt"
1213 "io"
@@ -89,6 +90,13 @@ func (r release) srcBinName() string {
8990 runtime .GOARCH + suffix
9091}
9192
93+ type tag struct {
94+ Name string `json:"name,omitempty"`
95+ Commit struct {
96+ Sha string `json:"sha,omitempty"`
97+ } `json:"commit"`
98+ }
99+
92100func getLatestRelease (tool types.Tool ) (* release , bool ) {
93101 if tool .Source .Repo == nil || ! strings .HasPrefix (tool .Source .Repo .Root , "https://github.com/" ) {
94102 return nil , false
@@ -105,7 +113,30 @@ func getLatestRelease(tool types.Tool) (*release, bool) {
105113 },
106114 }
107115
108- resp , err := client .Get (fmt .Sprintf ("https://github.com/%s/%s/releases/latest" , parts [1 ], parts [2 ]))
116+ account , repo := parts [1 ], parts [2 ]
117+
118+ resp , err := client .Get (fmt .Sprintf ("https://api.github.com/repos/%s/%s/tags" , account , repo ))
119+ if err != nil || resp .StatusCode != http .StatusOK {
120+ // ignore error
121+ return nil , false
122+ }
123+ defer resp .Body .Close ()
124+
125+ var tags []tag
126+ if err := json .NewDecoder (resp .Body ).Decode (& tags ); err != nil {
127+ return nil , false
128+ }
129+ for _ , tag := range tags {
130+ if tag .Commit .Sha == tool .Source .Repo .Revision {
131+ return & release {
132+ account : account ,
133+ repo : repo ,
134+ label : tag .Name ,
135+ }, true
136+ }
137+ }
138+
139+ resp , err = client .Get (fmt .Sprintf ("https://github.com/%s/%s/releases/latest" , account , repo ))
109140 if err != nil || resp .StatusCode != http .StatusFound {
110141 // ignore error
111142 return nil , false
@@ -117,7 +148,6 @@ func getLatestRelease(tool types.Tool) (*release, bool) {
117148 return nil , false
118149 }
119150
120- account , repo := parts [1 ], parts [2 ]
121151 parts = strings .Split (target , "/" )
122152 label := parts [len (parts )- 1 ]
123153
0 commit comments