GetRef fetches a single reference in a repository. The ref must be formatted as `heads/ ` for branches and `tags/ ` for tags. GitHub API docs: https://docs.github.com/rest/git/refs?apiVersion=2022-11-28#get-a-reference meta:operation GET /repos/{owner}/{repo}/git/ref/{ref}
(ctx context.Context, owner, repo, ref string)
| 56 | // |
| 57 | //meta:operation GET /repos/{owner}/{repo}/git/ref/{ref} |
| 58 | func (s *GitService) GetRef(ctx context.Context, owner, repo, ref string) (*Reference, *Response, error) { |
| 59 | ref = strings.TrimPrefix(ref, "refs/") |
| 60 | u := fmt.Sprintf("repos/%v/%v/git/ref/%v", owner, repo, refURLEscape(ref)) |
| 61 | req, err := s.client.NewRequest(ctx, "GET", u, nil) |
| 62 | if err != nil { |
| 63 | return nil, nil, err |
| 64 | } |
| 65 | |
| 66 | var r *Reference |
| 67 | resp, err := s.client.Do(req, &r) |
| 68 | if err != nil { |
| 69 | return nil, resp, err |
| 70 | } |
| 71 | |
| 72 | return r, resp, nil |
| 73 | } |
| 74 | |
| 75 | // refURLEscape escapes every path segment of the given ref. Those must |
| 76 | // not contain escaped "/" - as "%2F" - or github will not recognize it. |