Skip to content

Commit d5e03d5

Browse files
authored
Update CustomOrgRoles and CustomRepoRoles to include all fields returned by the GitHub API (#3216)
Fixes: #3214.
1 parent 9f5309e commit d5e03d5

File tree

4 files changed

+254
-13
lines changed

4 files changed

+254
-13
lines changed

github/github-accessors.go

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/orgs_custom_roles.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ type OrganizationCustomRoles struct {
1818

1919
// CustomOrgRoles represents custom organization role available in specified organization.
2020
type CustomOrgRoles struct {
21-
ID *int64 `json:"id,omitempty"`
22-
Name *string `json:"name,omitempty"`
23-
Description *string `json:"description,omitempty"`
24-
Permissions []string `json:"permissions,omitempty"`
21+
ID *int64 `json:"id,omitempty"`
22+
Name *string `json:"name,omitempty"`
23+
Description *string `json:"description,omitempty"`
24+
Permissions []string `json:"permissions,omitempty"`
25+
Org *Organization `json:"organization,omitempty"`
26+
CreatedAt *Timestamp `json:"created_at,omitempty"`
27+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
28+
Source *string `json:"source,omitempty"`
29+
BaseRole *string `json:"base_role,omitempty"`
2530
}
2631

2732
// OrganizationCustomRepoRoles represents custom repository roles available in specified organization.
@@ -34,11 +39,14 @@ type OrganizationCustomRepoRoles struct {
3439
// See https://docs.github.com/enterprise-cloud@latest/organizations/managing-peoples-access-to-your-organization-with-roles/managing-custom-repository-roles-for-an-organization
3540
// for more information.
3641
type CustomRepoRoles struct {
37-
ID *int64 `json:"id,omitempty"`
38-
Name *string `json:"name,omitempty"`
39-
Description *string `json:"description,omitempty"`
40-
BaseRole *string `json:"base_role,omitempty"`
41-
Permissions []string `json:"permissions,omitempty"`
42+
ID *int64 `json:"id,omitempty"`
43+
Name *string `json:"name,omitempty"`
44+
Description *string `json:"description,omitempty"`
45+
BaseRole *string `json:"base_role,omitempty"`
46+
Permissions []string `json:"permissions,omitempty"`
47+
Org *Organization `json:"organization,omitempty"`
48+
CreatedAt *Timestamp `json:"created_at,omitempty"`
49+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
4250
}
4351

4452
// CreateOrUpdateOrgRoleOptions represents options required to create or update a custom organization role.

github/orgs_custom_roles_test.go

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"net/http"
1212
"testing"
13+
"time"
1314

1415
"github.com/google/go-cmp/cmp"
1516
)
@@ -20,7 +21,30 @@ func TestOrganizationsService_ListRoles(t *testing.T) {
2021

2122
mux.HandleFunc("/orgs/o/organization-roles", func(w http.ResponseWriter, r *http.Request) {
2223
testMethod(t, r, "GET")
23-
fmt.Fprint(w, `{"total_count": 1, "roles": [{ "id": 1, "name": "Auditor", "permissions": ["read_audit_logs"]}]}`)
24+
fmt.Fprint(w, `{"total_count": 1, "roles": [
25+
{
26+
"id": 1,
27+
"name": "Auditor",
28+
"permissions": ["read_audit_logs"],
29+
"organization": {
30+
"login": "l",
31+
"id": 1,
32+
"node_id": "n",
33+
"avatar_url": "a",
34+
"html_url": "h",
35+
"name": "n",
36+
"company": "c",
37+
"blog": "b",
38+
"location": "l",
39+
"email": "e"
40+
},
41+
"created_at": "2024-07-21T19:33:08Z",
42+
"updated_at": "2024-07-21T19:33:08Z",
43+
"source": "Organization",
44+
"base_role": "admin"
45+
}
46+
]
47+
}`)
2448
})
2549

2650
ctx := context.Background()
@@ -29,7 +53,32 @@ func TestOrganizationsService_ListRoles(t *testing.T) {
2953
t.Errorf("Organizations.ListRoles returned error: %v", err)
3054
}
3155

32-
want := &OrganizationCustomRoles{TotalCount: Int(1), CustomRepoRoles: []*CustomOrgRoles{{ID: Int64(1), Name: String("Auditor"), Permissions: []string{"read_audit_logs"}}}}
56+
want := &OrganizationCustomRoles{
57+
TotalCount: Int(1),
58+
CustomRepoRoles: []*CustomOrgRoles{
59+
{
60+
ID: Int64(1),
61+
Name: String("Auditor"),
62+
Permissions: []string{"read_audit_logs"},
63+
Org: &Organization{
64+
Login: String("l"),
65+
ID: Int64(1),
66+
NodeID: String("n"),
67+
AvatarURL: String("a"),
68+
HTMLURL: String("h"),
69+
Name: String("n"),
70+
Company: String("c"),
71+
Blog: String("b"),
72+
Location: String("l"),
73+
Email: String("e"),
74+
},
75+
CreatedAt: &Timestamp{time.Date(2024, time.July, 21, 19, 33, 8, 0, time.UTC)},
76+
UpdatedAt: &Timestamp{time.Date(2024, time.July, 21, 19, 33, 8, 0, time.UTC)},
77+
Source: String("Organization"),
78+
BaseRole: String("admin"),
79+
},
80+
},
81+
}
3382
if !cmp.Equal(apps, want) {
3483
t.Errorf("Organizations.ListRoles returned %+v, want %+v", apps, want)
3584
}
@@ -169,7 +218,29 @@ func TestOrganizationsService_ListCustomRepoRoles(t *testing.T) {
169218

170219
mux.HandleFunc("/orgs/o/custom-repository-roles", func(w http.ResponseWriter, r *http.Request) {
171220
testMethod(t, r, "GET")
172-
fmt.Fprint(w, `{"total_count": 1, "custom_roles": [{ "id": 1, "name": "Developer", "base_role": "write", "permissions": ["delete_alerts_code_scanning"]}]}`)
221+
fmt.Fprint(w, `{"total_count": 1, "custom_roles": [
222+
{
223+
"id": 1,
224+
"name": "Developer",
225+
"base_role": "write",
226+
"permissions": ["delete_alerts_code_scanning"],
227+
"organization": {
228+
"login": "l",
229+
"id": 1,
230+
"node_id": "n",
231+
"avatar_url": "a",
232+
"html_url": "h",
233+
"name": "n",
234+
"company": "c",
235+
"blog": "b",
236+
"location": "l",
237+
"email": "e"
238+
},
239+
"created_at": "2024-07-21T19:33:08Z",
240+
"updated_at": "2024-07-21T19:33:08Z"
241+
}
242+
]
243+
}`)
173244
})
174245

175246
ctx := context.Background()
@@ -178,7 +249,31 @@ func TestOrganizationsService_ListCustomRepoRoles(t *testing.T) {
178249
t.Errorf("Organizations.ListCustomRepoRoles returned error: %v", err)
179250
}
180251

181-
want := &OrganizationCustomRepoRoles{TotalCount: Int(1), CustomRepoRoles: []*CustomRepoRoles{{ID: Int64(1), Name: String("Developer"), BaseRole: String("write"), Permissions: []string{"delete_alerts_code_scanning"}}}}
252+
want := &OrganizationCustomRepoRoles{
253+
TotalCount: Int(1),
254+
CustomRepoRoles: []*CustomRepoRoles{
255+
{
256+
ID: Int64(1),
257+
Name: String("Developer"),
258+
BaseRole: String("write"),
259+
Permissions: []string{"delete_alerts_code_scanning"},
260+
Org: &Organization{
261+
Login: String("l"),
262+
ID: Int64(1),
263+
NodeID: String("n"),
264+
AvatarURL: String("a"),
265+
HTMLURL: String("h"),
266+
Name: String("n"),
267+
Company: String("c"),
268+
Blog: String("b"),
269+
Location: String("l"),
270+
Email: String("e"),
271+
},
272+
CreatedAt: &Timestamp{time.Date(2024, time.July, 21, 19, 33, 8, 0, time.UTC)},
273+
UpdatedAt: &Timestamp{time.Date(2024, time.July, 21, 19, 33, 8, 0, time.UTC)},
274+
},
275+
},
276+
}
182277
if !cmp.Equal(apps, want) {
183278
t.Errorf("Organizations.ListCustomRepoRoles returned %+v, want %+v", apps, want)
184279
}

0 commit comments

Comments
 (0)