@@ -96,7 +96,21 @@ func (s *OrganizationsService) ListRoles(ctx context.Context, org string) (*Orga
96
96
func (s * OrganizationsService ) CreateCustomOrgRole (ctx context.Context , org string , opts * CreateOrUpdateOrgRoleOptions ) (* CustomOrgRoles , * Response , error ) {
97
97
u := fmt .Sprintf ("orgs/%v/organization-roles" , org )
98
98
99
- req , err := s .client .NewRequest ("POST" , u , opts )
99
+ var params interface {}
100
+ params = opts
101
+
102
+ // For empty Permissions property change the type of the property, so it will not be omitted during coversion to JSON.
103
+ if opts != nil && opts .Permissions != nil && len (opts .Permissions ) == 0 {
104
+ params = struct {
105
+ * CreateOrUpdateOrgRoleOptions
106
+ Permissions []string `json:"permissions"`
107
+ }{
108
+ CreateOrUpdateOrgRoleOptions : opts ,
109
+ Permissions : opts .Permissions ,
110
+ }
111
+ }
112
+
113
+ req , err := s .client .NewRequest ("POST" , u , params )
100
114
if err != nil {
101
115
return nil , nil , err
102
116
}
@@ -119,7 +133,21 @@ func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org stri
119
133
func (s * OrganizationsService ) UpdateCustomOrgRole (ctx context.Context , org string , roleID int64 , opts * CreateOrUpdateOrgRoleOptions ) (* CustomOrgRoles , * Response , error ) {
120
134
u := fmt .Sprintf ("orgs/%v/organization-roles/%v" , org , roleID )
121
135
122
- req , err := s .client .NewRequest ("PATCH" , u , opts )
136
+ var params interface {}
137
+ params = opts
138
+
139
+ // For empty Permissions property change the type of the property, so it will not be omitted during coversion to JSON.
140
+ if opts != nil && opts .Permissions != nil && len (opts .Permissions ) == 0 {
141
+ params = struct {
142
+ * CreateOrUpdateOrgRoleOptions
143
+ Permissions []string `json:"permissions"`
144
+ }{
145
+ CreateOrUpdateOrgRoleOptions : opts ,
146
+ Permissions : opts .Permissions ,
147
+ }
148
+ }
149
+
150
+ req , err := s .client .NewRequest ("PATCH" , u , params )
123
151
if err != nil {
124
152
return nil , nil , err
125
153
}
@@ -188,7 +216,21 @@ func (s *OrganizationsService) ListCustomRepoRoles(ctx context.Context, org stri
188
216
func (s * OrganizationsService ) CreateCustomRepoRole (ctx context.Context , org string , opts * CreateOrUpdateCustomRepoRoleOptions ) (* CustomRepoRoles , * Response , error ) {
189
217
u := fmt .Sprintf ("orgs/%v/custom-repository-roles" , org )
190
218
191
- req , err := s .client .NewRequest ("POST" , u , opts )
219
+ var params interface {}
220
+ params = opts
221
+
222
+ // For empty Permissions property change the type of the property, so it will not be omitted during coversion to JSON.
223
+ if opts != nil && opts .Permissions != nil && len (opts .Permissions ) == 0 {
224
+ params = struct {
225
+ * CreateOrUpdateCustomRepoRoleOptions
226
+ Permissions []string `json:"permissions"`
227
+ }{
228
+ CreateOrUpdateCustomRepoRoleOptions : opts ,
229
+ Permissions : opts .Permissions ,
230
+ }
231
+ }
232
+
233
+ req , err := s .client .NewRequest ("POST" , u , params )
192
234
if err != nil {
193
235
return nil , nil , err
194
236
}
@@ -211,7 +253,21 @@ func (s *OrganizationsService) CreateCustomRepoRole(ctx context.Context, org str
211
253
func (s * OrganizationsService ) UpdateCustomRepoRole (ctx context.Context , org string , roleID int64 , opts * CreateOrUpdateCustomRepoRoleOptions ) (* CustomRepoRoles , * Response , error ) {
212
254
u := fmt .Sprintf ("orgs/%v/custom-repository-roles/%v" , org , roleID )
213
255
214
- req , err := s .client .NewRequest ("PATCH" , u , opts )
256
+ var params interface {}
257
+ params = opts
258
+
259
+ // For empty Permissions property change the type of the property, so it will not be omitted during coversion to JSON.
260
+ if opts != nil && opts .Permissions != nil && len (opts .Permissions ) == 0 {
261
+ params = struct {
262
+ * CreateOrUpdateCustomRepoRoleOptions
263
+ Permissions []string `json:"permissions"`
264
+ }{
265
+ CreateOrUpdateCustomRepoRoleOptions : opts ,
266
+ Permissions : opts .Permissions ,
267
+ }
268
+ }
269
+
270
+ req , err := s .client .NewRequest ("PATCH" , u , params )
215
271
if err != nil {
216
272
return nil , nil , err
217
273
}
0 commit comments