mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
improve github archive download error reporting
This commit is contained in:
parent
524c820a94
commit
2b485512c0
1 changed files with 8 additions and 1 deletions
|
|
@ -52,15 +52,22 @@ func downloadGitHubArchive(filepath string, url string) (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
color.Cyan("GET %s %d", url, resp.StatusCode)
|
color.Cyan("GET %s %d", url, resp.StatusCode)
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return "", errors.New(fmt.Sprintf("unexpected status code %d", resp.StatusCode))
|
||||||
|
}
|
||||||
|
|
||||||
// GitHub conveniently uses the commit SHA1 at the ETag
|
// GitHub conveniently uses the commit SHA1 at the ETag
|
||||||
// signature for the archive. This is needed when doing `jb update`
|
// signature for the archive. This is needed when doing `jb update`
|
||||||
// to resolve a ref (ie. "master") to a commit SHA1 for the lock file
|
// to resolve a ref (ie. "master") to a commit SHA1 for the lock file
|
||||||
etagValue := resp.Header.Get(http.CanonicalHeaderKey("ETag"))
|
etagValue := resp.Header.Get(http.CanonicalHeaderKey("ETag"))
|
||||||
|
if etagValue == "" {
|
||||||
|
return "", errors.New("ETag header is missing from response")
|
||||||
|
}
|
||||||
|
|
||||||
commitShaPattern, _ := regexp.Compile("^\"([0-9a-f]{40})\"$")
|
commitShaPattern, _ := regexp.Compile("^\"([0-9a-f]{40})\"$")
|
||||||
m := commitShaPattern.FindStringSubmatch(etagValue)
|
m := commitShaPattern.FindStringSubmatch(etagValue)
|
||||||
if len(m) < 2 {
|
if len(m) < 2 {
|
||||||
return "", errors.New(fmt.Sprintf("unexpected etag format: %s", etagValue))
|
return "", errors.New(fmt.Sprintf("etag value \"%s\" does not look like a SHA1", etagValue))
|
||||||
}
|
}
|
||||||
commitSha := m[1]
|
commitSha := m[1]
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue