MCPcopy Index your code
hub / github.com/google/go-github / CreateRef

Method CreateRef

github/git_refs.go:116–141  ·  view source on GitHub ↗

CreateRef creates a new ref in a repository. GitHub API docs: https://docs.github.com/rest/git/refs?apiVersion=2022-11-28#create-a-reference meta:operation POST /repos/{owner}/{repo}/git/refs

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

Source from the content-addressed store, hash-verified

114//
115//meta:operation POST /repos/{owner}/{repo}/git/refs
116func (s *GitService) CreateRef(ctx context.Context, owner, repo string, ref CreateRef) (*Reference, *Response, error) {
117 if ref.Ref == "" {
118 return nil, nil, errors.New("ref must be provided")
119 }
120
121 if ref.SHA == "" {
122 return nil, nil, errors.New("sha must be provided")
123 }
124
125 // ensure the 'refs/' prefix is present
126 ref.Ref = "refs/" + strings.TrimPrefix(ref.Ref, "refs/")
127
128 u := fmt.Sprintf("repos/%v/%v/git/refs", owner, repo)
129 req, err := s.client.NewRequest(ctx, "POST", u, ref)
130 if err != nil {
131 return nil, nil, err
132 }
133
134 var r *Reference
135 resp, err := s.client.Do(req, &r)
136 if err != nil {
137 return nil, resp, err
138 }
139
140 return r, resp, nil
141}
142
143// UpdateRef updates an existing ref in a repository.
144//

Callers 2

getRefFunction · 0.80
TestGitService_CreateRefFunction · 0.80

Calls 2

NewRequestMethod · 0.80
DoMethod · 0.45

Tested by 1

TestGitService_CreateRefFunction · 0.64