@@ -97,21 +97,26 @@ type tag struct {
9797}
9898
9999func GetLatestTag (tool types.Tool ) (string , error ) {
100- r , ok := getLatestRelease (tool )
100+ r , ok , err := getLatestRelease (tool )
101+ if err != nil {
102+ return "" , err
103+ }
104+
101105 if ! ok {
102106 return "" , fmt .Errorf ("failed to get latest release for %s" , tool .Name )
103107 }
108+
104109 return r .label , nil
105110}
106111
107- func getLatestRelease (tool types.Tool ) (* release , bool ) {
112+ func getLatestRelease (tool types.Tool ) (* release , bool , error ) {
108113 if tool .Source .Repo == nil || ! strings .HasPrefix (tool .Source .Repo .Root , "https://github.com/" ) {
109- return nil , false
114+ return nil , false , nil
110115 }
111116
112117 parts := strings .Split (strings .TrimPrefix (strings .TrimSuffix (tool .Source .Repo .Root , ".git" ), "https://" ), "/" )
113118 if len (parts ) != 3 {
114- return nil , false
119+ return nil , false , fmt . Errorf ( "invalid GitHub URL: %s" , tool . Source . Repo . Root )
115120 }
116121
117122 client := http.Client {
@@ -124,41 +129,39 @@ func getLatestRelease(tool types.Tool) (*release, bool) {
124129
125130 resp , err := client .Get (fmt .Sprintf ("https://api.github.com/repos/%s/%s/tags" , account , repo ))
126131 if err != nil {
127- // ignore error
128- return nil , false
132+ return nil , false , fmt .Errorf ("failed to get tags: %w" , err )
129133 }
130134 defer resp .Body .Close ()
131135 if resp .StatusCode != http .StatusOK {
132- return nil , false
136+ return nil , false , fmt . Errorf ( "unexpected status when getting tags: %s" , resp . Status )
133137 }
134138
135139 var tags []tag
136140 if err := json .NewDecoder (resp .Body ).Decode (& tags ); err != nil {
137- return nil , false
141+ return nil , false , fmt . Errorf ( "failed to decode GitHub tags: %w" , err )
138142 }
139143 for _ , tag := range tags {
140144 if tag .Commit .Sha == tool .Source .Repo .Revision {
141145 return & release {
142146 account : account ,
143147 repo : repo ,
144148 label : tag .Name ,
145- }, true
149+ }, true , nil
146150 }
147151 }
148152
149153 resp , err = client .Get (fmt .Sprintf ("https://github.com/%s/%s/releases/latest" , account , repo ))
150154 if err != nil {
151- // ignore error
152- return nil , false
155+ return nil , false , fmt .Errorf ("failed to get latest release: %w" , err )
153156 }
154157 defer resp .Body .Close ()
155158 if resp .StatusCode != http .StatusFound {
156- return nil , false
159+ return nil , false , fmt . Errorf ( "unexpected status when getting latest release: %s" , resp . Status )
157160 }
158161
159162 target := resp .Header .Get ("Location" )
160163 if target == "" {
161- return nil , false
164+ return nil , false , nil
162165 }
163166
164167 parts = strings .Split (target , "/" )
@@ -168,7 +171,7 @@ func getLatestRelease(tool types.Tool) (*release, bool) {
168171 account : account ,
169172 repo : repo ,
170173 label : label ,
171- }, true
174+ }, true , nil
172175}
173176
174177func get (ctx context.Context , url string ) (* http.Response , error ) {
@@ -249,7 +252,8 @@ func (r *Runtime) Binary(ctx context.Context, tool types.Tool, _, toolSource str
249252 return false , nil , nil
250253 }
251254
252- rel , ok := getLatestRelease (tool )
255+ // ignore the error
256+ rel , ok , _ := getLatestRelease (tool )
253257 if ! ok {
254258 return false , nil , nil
255259 }
@@ -286,7 +290,8 @@ func (r *Runtime) DownloadCredentialHelper(ctx context.Context, tool types.Tool,
286290 return nil
287291 }
288292
289- rel , ok := getLatestRelease (tool )
293+ // ignore the error
294+ rel , ok , _ := getLatestRelease (tool )
290295 if ! ok {
291296 return fmt .Errorf ("failed to find %s release" , r .ID ())
292297 }
0 commit comments