Skip to content

Change the method of checking latest releases #32

@mszostok

Description

@mszostok

Description

Currently, we call the GitHub API with GET method to get info about latest release from

https://api.github.com/repos/{repo}/releases/latest

func getLatestReleaseInfo(ctx context.Context, repo string) (*ReleaseInfoResponse, error) {
url := fmt.Sprintf("https://api.github.com/repos/%s/releases/latest", repo)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
if err != nil {
return nil, err
}
req.Header.Add("Accept", "application/vnd.github+json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
rawBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("got unexpected status code %v", resp.Status)
}
var latestRelease ReleaseInfoResponse
err = json.Unmarshal(rawBody, &latestRelease)
if err != nil {
return nil, err
}
return &latestRelease, nil
}

This results in 403 when we hit the quota.

The faas-cli. Does something similar but uses HEAD method on

https://github.com/{repo}/releases/latest

As a result, the rate limiting is omitted.

https://github.com/openfaas/faas-cli/blob/927cc77f1dc2f7b8d980fb14e4d50d8839ae26b4/commands/cloud.go#L194

This has only one downside. We don't get the PublishedAt field, because of that I had to remove it from the 1.1.0 version.

Reasons

Avoid rate limiting.

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions