Skip to content

Commit 84ba5bc

Browse files
committed
feat: list all initia releases
1 parent 2bb1d7b commit 84ba5bc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

utils/http.go

+45
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package utils
33
import (
44
"encoding/json"
55
"fmt"
6+
"io"
67
"net/http"
8+
"strings"
79
"time"
810
)
911

@@ -56,3 +58,46 @@ func MakeGetRequest(network, endpoint, additionalPath string, params map[string]
5658

5759
return nil
5860
}
61+
62+
type InitiaRelease struct {
63+
TagName string `json:"tag_name"`
64+
Assets []struct {
65+
BrowserDownloadURL string `json:"browser_download_url"`
66+
} `json:"assets"`
67+
}
68+
69+
func ListInitiaReleases(os, arch string) error {
70+
url := "https://api.github.com/repos/initia-labs/initia/releases"
71+
resp, err := http.Get(url)
72+
if err != nil {
73+
return fmt.Errorf("failed to fetch releases: %v", err)
74+
}
75+
defer resp.Body.Close()
76+
77+
if resp.StatusCode != http.StatusOK {
78+
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
79+
}
80+
81+
body, err := io.ReadAll(resp.Body)
82+
if err != nil {
83+
return fmt.Errorf("failed to read response body: %v", err)
84+
}
85+
86+
var releases []InitiaRelease
87+
if err := json.Unmarshal(body, &releases); err != nil {
88+
return fmt.Errorf("failed to unmarshal JSON: %v", err)
89+
}
90+
91+
searchString := fmt.Sprintf("%s_%s.tar.gz", os, arch)
92+
93+
for _, release := range releases {
94+
for _, asset := range release.Assets {
95+
if strings.Contains(asset.BrowserDownloadURL, searchString) {
96+
fmt.Printf("Release: %s contains a prebuilt binary for %s_%s\n", release.TagName, os, arch)
97+
fmt.Printf("Download URL: %s\n", asset.BrowserDownloadURL)
98+
}
99+
}
100+
}
101+
102+
return nil
103+
}

0 commit comments

Comments
 (0)