@@ -37,16 +37,16 @@ func (o GitObject) String() string {
3737 return Stringify (o )
3838}
3939
40- // createRefRequest represents the payload for creating a reference.
41- type createRefRequest struct {
42- Ref * string `json:"ref"`
43- SHA * string `json:"sha"`
40+ // CreateRef represents the payload for creating a reference.
41+ type CreateRef struct {
42+ Ref string `json:"ref"`
43+ SHA string `json:"sha"`
4444}
4545
46- // updateRefRequest represents the payload for updating a reference.
47- type updateRefRequest struct {
48- SHA * string `json:"sha"`
49- Force * bool `json:"force"`
46+ // UpdateRef represents the payload for updating a reference.
47+ type UpdateRef struct {
48+ SHA string `json:"sha"`
49+ Force * bool `json:"force,omitempty "`
5050}
5151
5252// GetRef fetches a single reference in a repository.
@@ -127,20 +127,20 @@ func (s *GitService) ListMatchingRefs(ctx context.Context, owner, repo string, o
127127// GitHub API docs: https://docs.github.com/rest/git/refs#create-a-reference
128128//
129129//meta:operation POST /repos/{owner}/{repo}/git/refs
130- func (s * GitService ) CreateRef (ctx context.Context , owner , repo string , ref * Reference ) (* Reference , * Response , error ) {
131- if ref == nil {
132- return nil , nil , errors .New ("reference must be provided" )
133- }
134- if ref .Ref == nil {
130+ func (s * GitService ) CreateRef (ctx context.Context , owner , repo string , ref CreateRef ) (* Reference , * Response , error ) {
131+ if ref .Ref == "" {
135132 return nil , nil , errors .New ("ref must be provided" )
136133 }
137134
135+ if ref .SHA == "" {
136+ return nil , nil , errors .New ("sha must be provided" )
137+ }
138+
139+ // ensure the 'refs/' prefix is present
140+ ref .Ref = "refs/" + strings .TrimPrefix (ref .Ref , "refs/" )
141+
138142 u := fmt .Sprintf ("repos/%v/%v/git/refs" , owner , repo )
139- req , err := s .client .NewRequest ("POST" , u , & createRefRequest {
140- // back-compat with previous behavior that didn't require 'refs/' prefix
141- Ref : Ptr ("refs/" + strings .TrimPrefix (* ref .Ref , "refs/" )),
142- SHA : ref .Object .SHA ,
143- })
143+ req , err := s .client .NewRequest ("POST" , u , ref )
144144 if err != nil {
145145 return nil , nil , err
146146 }
@@ -159,20 +159,18 @@ func (s *GitService) CreateRef(ctx context.Context, owner, repo string, ref *Ref
159159// GitHub API docs: https://docs.github.com/rest/git/refs#update-a-reference
160160//
161161//meta:operation PATCH /repos/{owner}/{repo}/git/refs/{ref}
162- func (s * GitService ) UpdateRef (ctx context.Context , owner , repo string , ref * Reference , force bool ) (* Reference , * Response , error ) {
163- if ref == nil {
164- return nil , nil , errors .New ("reference must be provided" )
165- }
166- if ref .Ref == nil {
162+ func (s * GitService ) UpdateRef (ctx context.Context , owner , repo , ref string , updateRef UpdateRef ) (* Reference , * Response , error ) {
163+ if ref == "" {
167164 return nil , nil , errors .New ("ref must be provided" )
168165 }
169166
170- refPath := strings .TrimPrefix (* ref .Ref , "refs/" )
167+ if updateRef .SHA == "" {
168+ return nil , nil , errors .New ("sha must be provided" )
169+ }
170+
171+ refPath := strings .TrimPrefix (ref , "refs/" )
171172 u := fmt .Sprintf ("repos/%v/%v/git/refs/%v" , owner , repo , refURLEscape (refPath ))
172- req , err := s .client .NewRequest ("PATCH" , u , & updateRefRequest {
173- SHA : ref .Object .SHA ,
174- Force : & force ,
175- })
173+ req , err := s .client .NewRequest ("PATCH" , u , updateRef )
176174 if err != nil {
177175 return nil , nil , err
178176 }
0 commit comments