MCPcopy Create free account
hub / github.com/google/go-github / GetCommitSHA1

Method GetCommitSHA1

github/repos_commits.go:213–233  ·  view source on GitHub ↗

GetCommitSHA1 gets the SHA-1 of a commit reference. If a last-known SHA1 is supplied and no new commits have occurred, a 304 Unmodified response is returned. GitHub API docs: https://docs.github.com/rest/commits/commits?apiVersion=2022-11-28#get-a-commit meta:operation GET /repos/{owner}/{repo}/co

(ctx context.Context, owner, repo, ref, lastSHA string)

Source from the content-addressed store, hash-verified

211//
212//meta:operation GET /repos/{owner}/{repo}/commits/{ref}
213func (s *RepositoriesService) GetCommitSHA1(ctx context.Context, owner, repo, ref, lastSHA string) (string, *Response, error) {
214 u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, refURLEscape(ref))
215
216 req, err := s.client.NewRequest(ctx, "GET", u, nil)
217 if err != nil {
218 return "", nil, err
219 }
220 if lastSHA != "" {
221 req.Header.Set("If-None-Match", `"`+lastSHA+`"`)
222 }
223
224 req.Header.Set("Accept", mediaTypeV3SHA)
225
226 var buf bytes.Buffer
227 resp, err := s.client.Do(req, &buf)
228 if err != nil {
229 return "", resp, err
230 }
231
232 return buf.String(), resp, nil
233}
234
235// CompareCommits compares a range of commits with each other.
236//

Calls 4

refURLEscapeFunction · 0.85
NewRequestMethod · 0.80
DoMethod · 0.45
StringMethod · 0.45