Skip to content

Commit

Permalink
feat: use cross platform fetcher for github
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jan 31, 2025
1 parent d5e266a commit 3e089f3
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@ import (
"net/http"
"regexp"
"strings"

"github.com/tinfoilanalytics/verifier/util"
)

// FetchLatestRelease gets the latest release and attestation digest of a repo
func FetchLatestRelease(repo string) (string, string, error) {
url := "https://api.github.com/repos/" + repo + "/releases/latest"
releaseResponse, err := http.Get(url)
releaseResponse, err := util.NewFetcher().Get(url)
if err != nil {
return "", "", err
}
if releaseResponse.StatusCode != 200 {
return "", "", fmt.Errorf("failed to fetch latest release: %s", releaseResponse.Status)
}

var responseJSON struct {
TagName string `json:"tag_name"`
Body string `json:"body"`
}
if err := json.NewDecoder(releaseResponse.Body).Decode(&responseJSON); err != nil {
if err := json.Unmarshal(releaseResponse, &responseJSON); err != nil {
return "", "", err
}

Expand Down Expand Up @@ -54,20 +53,18 @@ func FetchLatestRelease(repo string) (string, string, error) {
// FetchAttestationBundle fetches the sigstore bundle from a repo for a given repo and EIF hash
func FetchAttestationBundle(repo, digest string) ([]byte, error) {
url := "https://api.github.com/repos/" + repo + "/attestations/sha256:" + digest
bundleResponse, err := http.Get(url)
bundleResponse, err := util.NewFetcher().Get(url)
if err != nil {
return nil, err
}
if bundleResponse.StatusCode != 200 {
return nil, fmt.Errorf("failed to fetch sigstore bundle: %s", bundleResponse.Status)
}

var responseJSON struct {
Attestations []struct {
Bundle json.RawMessage `json:"bundle"`
} `json:"attestations"`
}
if err := json.NewDecoder(bundleResponse.Body).Decode(&responseJSON); err != nil {

if err := json.Unmarshal(bundleResponse, &responseJSON); err != nil {
return nil, err
}

Expand Down

0 comments on commit 3e089f3

Please sign in to comment.