@@ -34,51 +34,50 @@ func ListOrganizationRoleAssignments(ctx context.Context, githubClient model.Git
3434 return nil , err
3535 }
3636
37- // 3) For each role, gather assigned teams and users
38- var assignments []GitHubRoleAssignment
37+ // 3) For each role, gather assigned teams and users, then produce output
38+ var allAssignments []GitHubOrganizationRoleAssignment
3939
4040 for _ , role := range orgRoles {
4141 teams , err := fetchTeamsAssignedToRole (sdk , organizationName , role .ID )
4242 if err != nil {
4343 fmt .Println (err )
4444 continue
4545 }
46- teamIDs := make ([] int , 0 , len ( teams ))
46+ // Create one JSON object per assigned team
4747 for _ , t := range teams {
48- teamIDs = append (teamIDs , t .ID )
48+ allAssignments = append (allAssignments , GitHubOrganizationRoleAssignment {
49+ RoleID : role .ID ,
50+ OrganizationID : orgID ,
51+ PrincipalType : "team" ,
52+ PrincipalID : t .ID ,
53+ })
4954 }
5055
5156 users , err := fetchUsersAssignedToRole (sdk , organizationName , role .ID )
5257 if err != nil {
5358 return nil , err
5459 }
55- userIDs := make ([] int , 0 , len ( users ))
60+ // Create one JSON object per assigned user
5661 for _ , u := range users {
57- userIDs = append (userIDs , u .ID )
62+ allAssignments = append (allAssignments , GitHubOrganizationRoleAssignment {
63+ RoleID : role .ID ,
64+ OrganizationID : orgID ,
65+ PrincipalType : "user" ,
66+ PrincipalID : u .ID ,
67+ })
5868 }
59-
60- assignments = append (assignments , GitHubRoleAssignment {
61- RoleID : role .ID ,
62- OrganizationID : orgID ,
63- CreatedAt : role .CreatedAt ,
64- UpdatedAt : role .UpdatedAt ,
65- ListOfTeams : teamIDs ,
66- ListOfUsers : userIDs ,
67- })
6869 }
6970
70- for _ , a := range assignments {
71+ for _ , a := range allAssignments {
7172 id := fmt .Sprintf ("%d/%d" , a .OrganizationID , a .RoleID )
7273 value := models.Resource {
7374 ID : id ,
7475 Description : model.OrganizationRoleAssignmentDescription {
7576 RoleId : a .RoleID ,
7677 OrganizationId : a .OrganizationID ,
7778 Organization : organizationName ,
78- ListOfTeams : a .ListOfTeams ,
79- ListOfUsers : a .ListOfUsers ,
80- CreatedAt : a .CreatedAt ,
81- UpdatedAt : a .UpdatedAt ,
79+ PrincipalType : a .PrincipalType ,
80+ PrincipalId : a .PrincipalID ,
8281 },
8382 }
8483
@@ -109,18 +108,6 @@ type orgRoleListResponseForAssignment struct {
109108 Roles []OrgRoleForAssignment `json:"roles"`
110109}
111110
112- // GitHubRoleAssignment captures which teams and which users are assigned to a single org role
113- type GitHubRoleAssignment struct {
114- RoleID int `json:"role_id"`
115- OrganizationID int `json:"organization_id"`
116- CreatedAt time.Time `json:"created_at,omitempty"`
117- UpdatedAt time.Time `json:"updated_at,omitempty"`
118-
119- ListOfTeams []int `json:"list_of_teams"`
120- ListOfUsers []int `json:"list_of_users"`
121- }
122-
123- // Minimal structs for teams and users assigned to roles
124111type GitHubTeam struct {
125112 ID int `json:"id"`
126113}
@@ -129,6 +116,15 @@ type GitHubUser struct {
129116 ID int `json:"id"`
130117}
131118
119+ // GitHubOrganizationRoleAssignment is the final output format:
120+ // one object per "principal" (team or user) assigned to a role.
121+ type GitHubOrganizationRoleAssignment struct {
122+ RoleID int `json:"role_id"`
123+ OrganizationID int `json:"organization_id"`
124+ PrincipalType string `json:"principal_type"` // "team" or "user"
125+ PrincipalID int `json:"principal_id"`
126+ }
127+
132128// -----------------------------------------------------
133129// Implementation: Org ID, Roles, Assignments
134130// -----------------------------------------------------
0 commit comments