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

Example of how to download a release asset #57

Merged
merged 1 commit into from Jul 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions example_gh_test.go
Expand Up @@ -2,6 +2,7 @@ package gh

import (
"fmt"
"io"
"log"
"os"
"time"
Expand Down Expand Up @@ -56,6 +57,42 @@ func ExampleRESTClient_advanced() {
fmt.Println(response)
}

// Get release asset from cli/cli repository using REST API.
func ExampleRESTClient_request() {
opts := api.ClientOptions{
Headers: map[string]string{"Accept": "application/octet-stream"},
}
client, err := RESTClient(&opts)
if err != nil {
log.Fatal(err)
}

// URL to cli/cli release v2.14.2 checksums.txt
assetURL := "repos/cli/cli/releases/assets/71589494"
resp, err := client.Request("GET", assetURL, nil)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()

if resp.StatusCode > 299 {
log.Fatal("server error")
}

f, err := os.CreateTemp("", "*_checksums.txt")
if err != nil {
log.Fatal(err)
}
defer f.Close()

_, err = io.Copy(f, resp.Body)
if err != nil {
log.Fatal(err)
}

fmt.Printf("Asset downloaded to %s\n", f.Name())
}

// Query tags from cli/cli repository using GQL API.
func ExampleGQLClient_simple() {
client, err := GQLClient(nil)
Expand Down