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)
| 211 | // |
| 212 | //meta:operation GET /repos/{owner}/{repo}/commits/{ref} |
| 213 | func (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 | // |