MCPcopy
hub / github.com/cli/cli / FetchRefSHA

Function FetchRefSHA

pkg/cmd/release/shared/fetch.go:138–171  ·  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 := fmt.Sprintf("repos/%s/%s/git/ref/tags/%s", repo.RepoOwner(), repo.RepoName(), tagName)
140 req, err := http.NewRequestWithContext(ctx, "GET", ghinstance.RESTPrefix(repo.RepoHost())+path, nil)
141 if err != nil {
142 return "", err
143 }
144
145 resp, err := httpClient.Do(req)
146 if err != nil {
147 return "", err
148 }
149 defer resp.Body.Close()
150
151 if resp.StatusCode == http.StatusNotFound {
152 _, _ = io.Copy(io.Discard, resp.Body)
153 return "", ErrReleaseNotFound
154 }
155
156 if resp.StatusCode > 299 {
157 return "", api.HandleHTTPError(resp)
158 }
159
160 var ref struct {
161 Object struct {
162 SHA string `json:"sha"`
163 } `json:"object"`
164 }
165
166 if err := json.NewDecoder(resp.Body).Decode(&ref); err != nil {
167 return "", fmt.Errorf("failed to parse ref response: %w", err)
168 }
169
170 return ref.Object.SHA, nil
171}
172
173// DigestAlgForRef returns the digest algorithm name corresponding to the given
174// 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 9

RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65
CopyMethod · 0.45

Tested by 1

TestFetchRefSHAFunction · 0.68