GetCommitRaw fetches the specified commit in raw (diff or patch) format. GitHub API docs: https://docs.github.com/rest/commits/commits?apiVersion=2022-11-28#get-a-commit meta:operation GET /repos/{owner}/{repo}/commits/{ref}
(ctx context.Context, owner, repo, sha string, opts RawOptions)
| 180 | // |
| 181 | //meta:operation GET /repos/{owner}/{repo}/commits/{ref} |
| 182 | func (s *RepositoriesService) GetCommitRaw(ctx context.Context, owner, repo, sha string, opts RawOptions) (string, *Response, error) { |
| 183 | u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, sha) |
| 184 | req, err := s.client.NewRequest(ctx, "GET", u, nil) |
| 185 | if err != nil { |
| 186 | return "", nil, err |
| 187 | } |
| 188 | |
| 189 | switch opts.Type { |
| 190 | case Diff: |
| 191 | req.Header.Set("Accept", mediaTypeV3Diff) |
| 192 | case Patch: |
| 193 | req.Header.Set("Accept", mediaTypeV3Patch) |
| 194 | default: |
| 195 | return "", nil, fmt.Errorf("unsupported raw type %v", opts.Type) |
| 196 | } |
| 197 | |
| 198 | var buf bytes.Buffer |
| 199 | resp, err := s.client.Do(req, &buf) |
| 200 | if err != nil { |
| 201 | return "", resp, err |
| 202 | } |
| 203 | |
| 204 | return buf.String(), resp, nil |
| 205 | } |
| 206 | |
| 207 | // GetCommitSHA1 gets the SHA-1 of a commit reference. If a last-known SHA1 is |
| 208 | // supplied and no new commits have occurred, a 304 Unmodified response is returned. |