From 07656f5109accc9b4c5ca1b2c789e54ac2b7ea9b Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Wed, 5 Aug 2026 19:15:43 +0900 Subject: [PATCH] refactor!: Pass LDAP mapping request bodies by value via new `UpdateUserLDAPMappingRequest` and `UpdateTeamLDAPMappingRequest` UpdateUserLDAPMapping and UpdateTeamLDAPMapping reused the UserLDAPMapping and TeamLDAPMapping response types as their request bodies, but ldap_dn is the only parameter either endpoint accepts, and it is required. The new request types model that schema exactly, with a non-pointer LDAPDN, and are passed by value. The response types stay unchanged, the teamID parameter is renamed for clarity, and both old entries are removed from the .golangci.yml allowlist. BREAKING CHANGE: AdminService.UpdateUserLDAPMapping and UpdateTeamLDAPMapping now take new UpdateUserLDAPMappingRequest and UpdateTeamLDAPMappingRequest (with non-pointer LDAPDN) by value instead of *UserLDAPMapping and *TeamLDAPMapping. --- .golangci.yml | 2 -- github/admin.go | 18 +++++++++++++++--- github/admin_test.go | 8 ++++---- github/github-accessors.go | 16 ++++++++++++++++ github/github-accessors_test.go | 16 ++++++++++++++++ 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 606de964e46..500111fff38 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -258,13 +258,11 @@ linters: - Subscription - TeamAddTeamMembershipOptions - TeamAddTeamRepoOptions - - TeamLDAPMapping - TeamProjectOptions - UpdateCodespaceOptions - UpdateDefaultSetupConfigurationOptions - UpdateProjectItemOptions - User - - UserLDAPMapping - UserSuspendOptions - WorkflowsPermissionsOpt # Body type names exempt from the "Options" suffix rule. diff --git a/github/admin.go b/github/admin.go index ef23a95f368..df89abcfc3d 100644 --- a/github/admin.go +++ b/github/admin.go @@ -36,6 +36,12 @@ func (m TeamLDAPMapping) String() string { return Stringify(m) } +// UpdateTeamLDAPMappingRequest represents a request to update the mapping +// between a GitHub team and an LDAP group. +type UpdateTeamLDAPMappingRequest struct { + LDAPDN string `json:"ldap_dn"` +} + // UserLDAPMapping represents the mapping between a GitHub user and an LDAP user. type UserLDAPMapping struct { ID *int64 `json:"id,omitempty"` @@ -62,6 +68,12 @@ func (m UserLDAPMapping) String() string { return Stringify(m) } +// UpdateUserLDAPMappingRequest represents a request to update the mapping +// between a GitHub user and an LDAP user. +type UpdateUserLDAPMappingRequest struct { + LDAPDN string `json:"ldap_dn"` +} + // Enterprise represents the GitHub enterprise profile. type Enterprise struct { ID *int `json:"id,omitempty"` @@ -85,7 +97,7 @@ func (m Enterprise) String() string { // GitHub API docs: https://docs.github.com/enterprise-server@3.21/rest/enterprise-admin/ldap#update-ldap-mapping-for-a-user // //meta:operation PATCH /admin/ldap/users/{username}/mapping -func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, body *UserLDAPMapping) (*UserLDAPMapping, *Response, error) { +func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, body UpdateUserLDAPMappingRequest) (*UserLDAPMapping, *Response, error) { u := fmt.Sprintf("admin/ldap/users/%v/mapping", user) req, err := s.client.NewRequest(ctx, "PATCH", u, body) if err != nil { @@ -106,8 +118,8 @@ func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, b // GitHub API docs: https://docs.github.com/enterprise-server@3.21/rest/enterprise-admin/ldap#update-ldap-mapping-for-a-team // //meta:operation PATCH /admin/ldap/teams/{team_id}/mapping -func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, team int64, body *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) { - u := fmt.Sprintf("admin/ldap/teams/%v/mapping", team) +func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, teamID int64, body UpdateTeamLDAPMappingRequest) (*TeamLDAPMapping, *Response, error) { + u := fmt.Sprintf("admin/ldap/teams/%v/mapping", teamID) req, err := s.client.NewRequest(ctx, "PATCH", u, body) if err != nil { return nil, nil, err diff --git a/github/admin_test.go b/github/admin_test.go index 347134ff49e..ca4fd3e4d56 100644 --- a/github/admin_test.go +++ b/github/admin_test.go @@ -17,8 +17,8 @@ func TestAdminService_UpdateUserLDAPMapping(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &UserLDAPMapping{ - LDAPDN: Ptr("uid=asdf,ou=users,dc=github,dc=com"), + input := UpdateUserLDAPMappingRequest{ + LDAPDN: "uid=asdf,ou=users,dc=github,dc=com", } mux.HandleFunc("/admin/ldap/users/u/mapping", func(w http.ResponseWriter, r *http.Request) { @@ -60,8 +60,8 @@ func TestAdminService_UpdateTeamLDAPMapping(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &TeamLDAPMapping{ - LDAPDN: Ptr("cn=Enterprise Ops,ou=teams,dc=github,dc=com"), + input := UpdateTeamLDAPMappingRequest{ + LDAPDN: "cn=Enterprise Ops,ou=teams,dc=github,dc=com", } mux.HandleFunc("/admin/ldap/teams/1/mapping", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/github-accessors.go b/github/github-accessors.go index c8ce45d38a0..c7b472ac943 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -43838,6 +43838,22 @@ func (u *UpdateRunnerGroupRequest) GetVisibility() string { return *u.Visibility } +// GetLDAPDN returns the LDAPDN field. +func (u *UpdateTeamLDAPMappingRequest) GetLDAPDN() string { + if u == nil { + return "" + } + return u.LDAPDN +} + +// GetLDAPDN returns the LDAPDN field. +func (u *UpdateUserLDAPMappingRequest) GetLDAPDN() string { + if u == nil { + return "" + } + return u.LDAPDN +} + // GetLicense returns the License field. func (u *UploadLicenseOptions) GetLicense() string { if u == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index c5eb447e439..c164347030c 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -54936,6 +54936,22 @@ func TestUpdateRunnerGroupRequest_GetVisibility(tt *testing.T) { u.GetVisibility() } +func TestUpdateTeamLDAPMappingRequest_GetLDAPDN(tt *testing.T) { + tt.Parallel() + u := &UpdateTeamLDAPMappingRequest{} + u.GetLDAPDN() + u = nil + u.GetLDAPDN() +} + +func TestUpdateUserLDAPMappingRequest_GetLDAPDN(tt *testing.T) { + tt.Parallel() + u := &UpdateUserLDAPMappingRequest{} + u.GetLDAPDN() + u = nil + u.GetLDAPDN() +} + func TestUploadLicenseOptions_GetLicense(tt *testing.T) { tt.Parallel() u := &UploadLicenseOptions{}