MCPcopy Index your code
hub / github.com/rilldata/rill / fetchLatestVersion

Function fetchLatestVersion

cli/pkg/cmdutil/update.go:111–155  ·  view source on GitHub ↗

fetchLatestVersion fetches the latest version of Rill from Github releases.

(ctx context.Context)

Source from the content-addressed store, hash-verified

109
110// fetchLatestVersion fetches the latest version of Rill from Github releases.
111func fetchLatestVersion(ctx context.Context) (*githubReleaseInfo, error) {
112 req, err := http.NewRequestWithContext(ctx, http.MethodGet, versionCheckURI, http.NoBody)
113 if err != nil {
114 return nil, err
115 }
116
117 req.Header.Set("Content-Type", "application/json; charset=utf-8")
118 req.Header.Set("Accept", "application/vnd.github.v3+json")
119
120 getToken := func() string {
121 if t := os.Getenv("GH_TOKEN"); t != "" {
122 return t
123 }
124 return os.Getenv("GITHUB_TOKEN")
125 }
126
127 if token := getToken(); token != "" {
128 req.Header.Set("Authorization", fmt.Sprintf("token %s", token))
129 }
130
131 client := &http.Client{Timeout: time.Second * 15}
132 resp, err := client.Do(req)
133 if err != nil {
134 return nil, err
135 }
136 defer resp.Body.Close()
137
138 out, err := io.ReadAll(resp.Body)
139 if err != nil {
140 return nil, err
141 }
142
143 success := resp.StatusCode >= 200 && resp.StatusCode < 300
144 if !success {
145 return nil, fmt.Errorf("error fetching latest release: %s", string(out))
146 }
147
148 var info *githubReleaseInfo
149 err = json.Unmarshal(out, &info)
150 if err != nil {
151 return nil, err
152 }
153
154 return info, nil
155}

Callers 1

LatestVersionMethod · 0.85

Calls 4

DoMethod · 0.80
CloseMethod · 0.65
ErrorfMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected