7
7
"crypto/sha256"
8
8
_ "embed"
9
9
"encoding/hex"
10
+ "encoding/json"
10
11
"errors"
11
12
"fmt"
12
13
"io"
@@ -89,6 +90,13 @@ func (r release) srcBinName() string {
89
90
runtime .GOARCH + suffix
90
91
}
91
92
93
+ type tag struct {
94
+ Name string `json:"name,omitempty"`
95
+ Commit struct {
96
+ Sha string `json:"sha,omitempty"`
97
+ } `json:"commit"`
98
+ }
99
+
92
100
func getLatestRelease (tool types.Tool ) (* release , bool ) {
93
101
if tool .Source .Repo == nil || ! strings .HasPrefix (tool .Source .Repo .Root , "https://github.com/" ) {
94
102
return nil , false
@@ -105,7 +113,30 @@ func getLatestRelease(tool types.Tool) (*release, bool) {
105
113
},
106
114
}
107
115
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 ))
109
140
if err != nil || resp .StatusCode != http .StatusFound {
110
141
// ignore error
111
142
return nil , false
@@ -117,7 +148,6 @@ func getLatestRelease(tool types.Tool) (*release, bool) {
117
148
return nil , false
118
149
}
119
150
120
- account , repo := parts [1 ], parts [2 ]
121
151
parts = strings .Split (target , "/" )
122
152
label := parts [len (parts )- 1 ]
123
153
0 commit comments