MCPcopy Create free account
hub / github.com/cli/cli / FetchRefSHA

Function FetchRefSHA

pkg/cmd/release/shared/fetch.go:138–167  ·  view source on GitHub ↗
(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, tagName string)

Source from the content-addressed store, hash-verified

136}
137
138func FetchRefSHA(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, tagName string) (string, error) {
139 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "git", "ref", fmt.Sprintf("tags/%s", tagName))
140 if err != nil {
141 return "", err
142 }
143
144 // TODO(api-client-rollout)
145 // This line of code is part of a mechanical roll out of the api client.
146 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
147 resp, err := api.NewClientFromHTTP(httpClient).RequestWithContext(ctx, repo.RepoHost(), http.MethodGet, path.String(), nil)
148 if err != nil {
149 if isNotFound(err) {
150 return "", ErrReleaseNotFound
151 }
152 return "", err
153 }
154 defer resp.Body.Close()
155
156 var ref struct {
157 Object struct {
158 SHA string `json:"sha"`
159 } `json:"object"`
160 }
161
162 if err := json.NewDecoder(resp.Body).Decode(&ref); err != nil {
163 return "", fmt.Errorf("failed to parse ref response: %w", err)
164 }
165
166 return ref.Object.SHA, nil
167}
168
169// DigestAlgForRef returns the digest algorithm name corresponding to the given
170// git ref SHA. SHA-1 git object IDs are 40 hex characters and SHA-256 git

Callers 3

verifyRunFunction · 0.92
verifyAssetRunFunction · 0.92
TestFetchRefSHAFunction · 0.85

Calls 10

JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
RequestWithContextMethod · 0.80
isNotFoundFunction · 0.70
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

TestFetchRefSHAFunction · 0.68