Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add github pat token option for downloadReleaseAssetFromURL #45

Open
gerbil opened this issue Oct 21, 2024 · 0 comments
Open

Add github pat token option for downloadReleaseAssetFromURL #45

gerbil opened this issue Oct 21, 2024 · 0 comments

Comments

@gerbil
Copy link

gerbil commented Oct 21, 2024

func downloadReleaseAssetFromURL(ctx context.Context, url string) (rc io.ReadCloser, err error) {
	client := http.DefaultClient
	req, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	req.Header.Set("Accept", "*/*")

	req.Header.Set("Authorization", "Bearer $TOKEN")
	req.Header.Set("X-GitHub-Api-Version", "2022-11-28")

	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("failed to download a release file from %s: %w", url, err)
	}
	if resp.StatusCode >= 300 {
		resp.Body.Close()
		return nil, fmt.Errorf("failed to download a release file from %s: HTTP %d", url, resp.StatusCode)
	}
	return resp.Body, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant