@@ -37,16 +37,16 @@ func (o GitObject) String() string {
37
37
return Stringify (o )
38
38
}
39
39
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"`
44
44
}
45
45
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 "`
50
50
}
51
51
52
52
// GetRef fetches a single reference in a repository.
@@ -127,20 +127,20 @@ func (s *GitService) ListMatchingRefs(ctx context.Context, owner, repo string, o
127
127
// GitHub API docs: https://docs.github.com/rest/git/refs#create-a-reference
128
128
//
129
129
//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 == "" {
135
132
return nil , nil , errors .New ("ref must be provided" )
136
133
}
137
134
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
+
138
142
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 )
144
144
if err != nil {
145
145
return nil , nil , err
146
146
}
@@ -159,20 +159,18 @@ func (s *GitService) CreateRef(ctx context.Context, owner, repo string, ref *Ref
159
159
// GitHub API docs: https://docs.github.com/rest/git/refs#update-a-reference
160
160
//
161
161
//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 == "" {
167
164
return nil , nil , errors .New ("ref must be provided" )
168
165
}
169
166
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/" )
171
172
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 )
176
174
if err != nil {
177
175
return nil , nil , err
178
176
}
0 commit comments