@@ -22,6 +22,8 @@ type MockGitHub struct {
2222 repositories map [int64 ]github.Repository
2323 teams map [int64 ]github.Team
2424 users map [int64 ]github.User
25+ orgRoles map [int64 ]mapset.Set [int64 ] // Maps role ID to set of user IDs
26+ SimulateOrgRolePermErr bool // Simulate permission error for org roles
2527}
2628
2729func NewMockGitHub () * MockGitHub {
@@ -33,6 +35,7 @@ func NewMockGitHub() *MockGitHub {
3335 repositories : map [int64 ]github.Repository {},
3436 teams : map [int64 ]github.Team {},
3537 users : map [int64 ]github.User {},
38+ orgRoles : map [int64 ]mapset.Set [int64 ]{},
3639 }
3740}
3841
@@ -494,6 +497,104 @@ func (mgh MockGitHub) removeRepositoryCollaborator(
494497 )
495498}
496499
500+ type OrganizationRole struct {
501+ ID int64 `json:"id"`
502+ Name string `json:"name"`
503+ Description string `json:"description"`
504+ }
505+
506+ type OrganizationRoles struct {
507+ CustomRepoRoles []* OrganizationRole `json:"roles"`
508+ }
509+
510+ func (mgh MockGitHub ) getOrgRoles (
511+ w http.ResponseWriter ,
512+ variables map [string ]string ,
513+ ) {
514+ if mgh .SimulateOrgRolePermErr {
515+ w .WriteHeader (http .StatusForbidden )
516+ return
517+ }
518+ orgID , _ := getCrossTableId (w , variables , "org" )
519+ if _ , ok := mgh .organizations [orgID ]; ! ok {
520+ w .WriteHeader (http .StatusNotFound )
521+ return
522+ }
523+
524+ // Return a mock role
525+ role := & OrganizationRole {
526+ ID : 1 ,
527+ Name : "Test Role" ,
528+ Description : "Test Role Description" ,
529+ }
530+
531+ roles := & OrganizationRoles {
532+ CustomRepoRoles : []* OrganizationRole {role },
533+ }
534+
535+ _ , _ = w .Write (mock .MustMarshal (roles ))
536+ }
537+
538+ func (mgh MockGitHub ) getOrgRoleTeams (
539+ w http.ResponseWriter ,
540+ variables map [string ]string ,
541+ ) {
542+ roleID , _ := getCrossTableId (w , variables , "role_id" )
543+ if _ , ok := mgh .orgRoles [roleID ]; ! ok {
544+ w .WriteHeader (http .StatusNotFound )
545+ return
546+ }
547+
548+ // Return empty teams list for now
549+ _ , _ = w .Write (mock .MustMarshal ([]* github.Team {}))
550+ }
551+
552+ func (mgh MockGitHub ) getOrgRoleUsers (
553+ w http.ResponseWriter ,
554+ variables map [string ]string ,
555+ ) {
556+ roleID , _ := getCrossTableId (w , variables , "role_id" )
557+ memberships , ok := mgh .orgRoles [roleID ]
558+ if ! ok {
559+ w .WriteHeader (http .StatusNotFound )
560+ return
561+ }
562+
563+ users := make ([]github.User , 0 )
564+ for _ , userID := range memberships .ToSlice () {
565+ if user , ok := mgh .users [userID ]; ok {
566+ users = append (users , user )
567+ }
568+ }
569+
570+ _ , _ = w .Write (mock .MustMarshal (users ))
571+ }
572+
573+ func (mgh MockGitHub ) addOrgRoleUser (
574+ w http.ResponseWriter ,
575+ variables map [string ]string ,
576+ ) {
577+ roleID , _ := getCrossTableId (w , variables , "role_id" )
578+ userID , _ := getUserId (w , variables )
579+
580+ if _ , ok := mgh .orgRoles [roleID ]; ! ok {
581+ mgh .orgRoles [roleID ] = mapset .NewSet [int64 ]()
582+ }
583+ mgh .orgRoles [roleID ].Add (userID )
584+ }
585+
586+ func (mgh MockGitHub ) removeOrgRoleUser (
587+ w http.ResponseWriter ,
588+ variables map [string ]string ,
589+ ) {
590+ roleID , _ := getCrossTableId (w , variables , "role_id" )
591+ userID , _ := getUserId (w , variables )
592+
593+ if memberships , ok := mgh .orgRoles [roleID ]; ok {
594+ memberships .Remove (userID )
595+ }
596+ }
597+
497598type handler = func (w http.ResponseWriter , variables map [string ]string )
498599
499600// addEndpointHandler takes a string interpolation pattern and a handler
@@ -540,6 +641,12 @@ func (mgh MockGitHub) Server() *http.Client {
540641 mock .PutReposCollaboratorsByOwnerByRepoByUsername : mgh .addRepositoryCollaborator ,
541642 DeleteOrganizationsTeamsMembershipsByOrganizationByTeamIdByUsername : mgh .removeMembership ,
542643 PutOrganizationsTeamsMembershipsByOrganizationByTeamIdByUsername : mgh .addMembership ,
644+ // Add organization role endpoints
645+ GetOrgsRolesByOrg : mgh .getOrgRoles ,
646+ GetOrgsRolesTeamsByOrgByRoleId : mgh .getOrgRoleTeams ,
647+ GetOrgsRolesUsersByOrgByRoleId : mgh .getOrgRoleUsers ,
648+ PutOrgsRolesUsersByOrgByRoleIdByUsername : mgh .addOrgRoleUser ,
649+ DeleteOrgsRolesUsersByOrgByRoleIdByUsername : mgh .removeOrgRoleUser ,
543650 }
544651
545652 options := make ([]mock.MockBackendOption , 0 )
0 commit comments