MCPcopy
hub / github.com/cli/cli / fetchCommitSHA

Function fetchCommitSHA

pkg/cmd/extension/http.go:188–216  ·  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

186
187// fetchCommitSHA finds full commit SHA from a target ref in a repo
188func fetchCommitSHA(httpClient *http.Client, baseRepo ghrepo.Interface, targetRef string) (string, error) {
189 path := fmt.Sprintf("repos/%s/%s/commits/%s", baseRepo.RepoOwner(), baseRepo.RepoName(), targetRef)
190 url := ghinstance.RESTPrefix(baseRepo.RepoHost()) + path
191 req, err := http.NewRequest("GET", url, nil)
192 if err != nil {
193 return "", err
194 }
195
196 req.Header.Set("Accept", "application/vnd.github.v3.sha")
197 resp, err := httpClient.Do(req)
198 if err != nil {
199 return "", err
200 }
201
202 defer resp.Body.Close()
203 if resp.StatusCode == 422 {
204 return "", commitNotFoundErr
205 }
206 if resp.StatusCode > 299 {
207 return "", api.HandleHTTPError(resp)
208 }
209
210 body, err := io.ReadAll(resp.Body)
211 if err != nil {
212 return "", err
213 }
214
215 return string(body), nil
216}

Callers 1

installGitMethod · 0.85

Calls 8

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

Tested by

no test coverage detected