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

Function fetchCommitSHA

pkg/cmd/extension/http.go:195–225  ·  view source on GitHub ↗

fetchCommitSHA finds full commit SHA from a target ref in a repo

(httpClient *http.Client, baseRepo ghrepo.Interface, targetRef string)

Source from the content-addressed store, hash-verified

193
194// fetchCommitSHA finds full commit SHA from a target ref in a repo
195func fetchCommitSHA(httpClient *http.Client, baseRepo ghrepo.Interface, targetRef string) (string, error) {
196 url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(baseRepo.RepoHost()), "repos", baseRepo.RepoOwner(), baseRepo.RepoName(), "commits", targetRef)
197 if err != nil {
198 return "", err
199 }
200 req, err := http.NewRequest("GET", url.String(), nil)
201 if err != nil {
202 return "", err
203 }
204
205 req.Header.Set("Accept", "application/vnd.github.v3.sha")
206 resp, err := httpClient.Do(req)
207 if err != nil {
208 return "", err
209 }
210
211 defer resp.Body.Close()
212 if resp.StatusCode == 422 {
213 return "", commitNotFoundErr
214 }
215 if resp.StatusCode > 299 {
216 return "", api.HandleHTTPError(resp)
217 }
218
219 body, err := io.ReadAll(resp.Body)
220 if err != nil {
221 return "", err
222 }
223
224 return string(body), nil
225}

Callers 1

installGitMethod · 0.85

Calls 10

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
StringMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected