From 6fb9ccd556820ad5a25af9f0f848092a09c8d138 Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Sat, 31 Oct 2026 20:38:11 +0900 Subject: [PATCH 1/2] feat: Add `OrganizationID`, `ProfileURL`, and `Operations` to `SCIMUserAttributes` --- github/github-accessors.go | 24 ++++++++++++++++++++++++ github/github-accessors_test.go | 33 +++++++++++++++++++++++++++++++++ github/scim.go | 7 +++++-- github/scim_test.go | 28 +++++++++++++++++++++++----- 4 files changed, 85 insertions(+), 7 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 800599d4e20..91db9e30b0f 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -42614,6 +42614,30 @@ func (s *SCIMUserAttributes) GetName() SCIMUserName { return s.Name } +// GetOperations returns the Operations slice if it's non-nil, nil otherwise. +func (s *SCIMUserAttributes) GetOperations() []*UpdateAttributeForSCIMUserOperations { + if s == nil || s.Operations == nil { + return nil + } + return s.Operations +} + +// GetOrganizationID returns the OrganizationID field if it's non-nil, zero value otherwise. +func (s *SCIMUserAttributes) GetOrganizationID() int64 { + if s == nil || s.OrganizationID == nil { + return 0 + } + return *s.OrganizationID +} + +// GetProfileURL returns the ProfileURL field if it's non-nil, zero value otherwise. +func (s *SCIMUserAttributes) GetProfileURL() string { + if s == nil || s.ProfileURL == nil { + return "" + } + return *s.ProfileURL +} + // GetRoles returns the Roles slice if it's non-nil, nil otherwise. func (s *SCIMUserAttributes) GetRoles() []*SCIMUserRole { if s == nil || s.Roles == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index d2d485e0afa..2af54b40208 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -53178,6 +53178,39 @@ func TestSCIMUserAttributes_GetName(tt *testing.T) { s.GetName() } +func TestSCIMUserAttributes_GetOperations(tt *testing.T) { + tt.Parallel() + zeroValue := []*UpdateAttributeForSCIMUserOperations{} + s := &SCIMUserAttributes{Operations: zeroValue} + s.GetOperations() + s = &SCIMUserAttributes{} + s.GetOperations() + s = nil + s.GetOperations() +} + +func TestSCIMUserAttributes_GetOrganizationID(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + s := &SCIMUserAttributes{OrganizationID: &zeroValue} + s.GetOrganizationID() + s = &SCIMUserAttributes{} + s.GetOrganizationID() + s = nil + s.GetOrganizationID() +} + +func TestSCIMUserAttributes_GetProfileURL(tt *testing.T) { + tt.Parallel() + var zeroValue string + s := &SCIMUserAttributes{ProfileURL: &zeroValue} + s.GetProfileURL() + s = &SCIMUserAttributes{} + s.GetProfileURL() + s = nil + s.GetProfileURL() +} + func TestSCIMUserAttributes_GetRoles(tt *testing.T) { tt.Parallel() zeroValue := []*SCIMUserRole{} diff --git a/github/scim.go b/github/scim.go index 6537ab4ff4c..25abfc7ae14 100644 --- a/github/scim.go +++ b/github/scim.go @@ -32,8 +32,11 @@ type SCIMUserAttributes struct { Roles []*SCIMUserRole `json:"roles,omitempty"` // (Optional, GHES only.) Active *bool `json:"active,omitempty"` // (Optional.) // Only populated as a result of calling ListSCIMProvisionedIdentitiesOptions or GetSCIMProvisioningInfoForUser: - ID *string `json:"id,omitempty"` - Meta *SCIMMeta `json:"meta,omitempty"` + ID *string `json:"id,omitempty"` + Meta *SCIMMeta `json:"meta,omitempty"` + OrganizationID *int64 `json:"organization_id,omitempty"` + ProfileURL *string `json:"profileUrl,omitempty"` + Operations []*UpdateAttributeForSCIMUserOperations `json:"operations,omitempty"` } // SCIMUserName represents SCIM user information. diff --git a/github/scim_test.go b/github/scim_test.go index 4ba1bdc8516..f63041339c2 100644 --- a/github/scim_test.go +++ b/github/scim_test.go @@ -210,7 +210,16 @@ func TestSCIMService_GetSCIMProvisioningInfoForUser(t *testing.T) { "created": ` + refTimeStr(1136178000) + `, "lastModified": ` + refTimeStr(1136178001) + `, "location": "https://api.github.com/scim/v2/organizations/octo-org/Users/edefdfedf-050c-11e7-8d32" - } + }, + "organization_id": 1, + "profileUrl": "https://example.com/mona", + "operations": [ + { + "op": "replace", + "path": "active", + "value": false + } + ] }`)) }) @@ -244,10 +253,19 @@ func TestSCIMService_GetSCIMProvisioningInfoForUser(t *testing.T) { Value: "mona@octocat.github.com", }, }, - Schemas: []string{"urn:ietf:params:scim:schemas:core:2.0:User"}, - ExternalID: new("a7d0f98382"), - Groups: nil, - Active: new(true), + Schemas: []string{"urn:ietf:params:scim:schemas:core:2.0:User"}, + ExternalID: new("a7d0f98382"), + Groups: nil, + Active: new(true), + OrganizationID: new(int64(1)), + ProfileURL: new("https://example.com/mona"), + Operations: []*UpdateAttributeForSCIMUserOperations{ + { + Op: "replace", + Path: new("active"), + Value: json.RawMessage(`false`), + }, + }, } if !cmp.Equal(user, &want) { From 6f7ada7c015118e7daf53e9ceed206bc1549a599 Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Sat, 31 Oct 2026 20:39:27 +0900 Subject: [PATCH 2/2] refactor!: Add `ProvisionAndInviteSCIMUserRequest` and pass it by value to `ProvisionAndInviteSCIMUser` --- .golangci.yml | 1 - github/github-accessors.go | 64 +++++++++++++++++++++++++ github/github-accessors_test.go | 82 +++++++++++++++++++++++++++++++++ github/scim.go | 15 +++++- github/scim_test.go | 24 +++++----- 5 files changed, 173 insertions(+), 13 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 8f84b3241cc..046200ad877 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -226,7 +226,6 @@ linters: - Repository - RepositoryContentFileOptions - RequiredStatusChecksRequest - - SCIMUserAttributes - SourceImportAuthor - Subscription # Body type names exempt from the "Options" suffix rule. diff --git a/github/github-accessors.go b/github/github-accessors.go index 91db9e30b0f..ce4dddba056 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -33230,6 +33230,70 @@ func (p *ProtectionRule) GetWaitTimer() int { return *p.WaitTimer } +// GetActive returns the Active field if it's non-nil, zero value otherwise. +func (p *ProvisionAndInviteSCIMUserRequest) GetActive() bool { + if p == nil || p.Active == nil { + return false + } + return *p.Active +} + +// GetDisplayName returns the DisplayName field if it's non-nil, zero value otherwise. +func (p *ProvisionAndInviteSCIMUserRequest) GetDisplayName() string { + if p == nil || p.DisplayName == nil { + return "" + } + return *p.DisplayName +} + +// GetEmails returns the Emails slice if it's non-nil, nil otherwise. +func (p *ProvisionAndInviteSCIMUserRequest) GetEmails() []*SCIMUserEmail { + if p == nil || p.Emails == nil { + return nil + } + return p.Emails +} + +// GetExternalID returns the ExternalID field if it's non-nil, zero value otherwise. +func (p *ProvisionAndInviteSCIMUserRequest) GetExternalID() string { + if p == nil || p.ExternalID == nil { + return "" + } + return *p.ExternalID +} + +// GetGroups returns the Groups slice if it's non-nil, nil otherwise. +func (p *ProvisionAndInviteSCIMUserRequest) GetGroups() []string { + if p == nil || p.Groups == nil { + return nil + } + return p.Groups +} + +// GetName returns the Name field. +func (p *ProvisionAndInviteSCIMUserRequest) GetName() SCIMUserName { + if p == nil { + return SCIMUserName{} + } + return p.Name +} + +// GetSchemas returns the Schemas slice if it's non-nil, nil otherwise. +func (p *ProvisionAndInviteSCIMUserRequest) GetSchemas() []string { + if p == nil || p.Schemas == nil { + return nil + } + return p.Schemas +} + +// GetUserName returns the UserName field. +func (p *ProvisionAndInviteSCIMUserRequest) GetUserName() string { + if p == nil { + return "" + } + return p.UserName +} + // GetInstallation returns the Installation field. func (p *PublicEvent) GetInstallation() *Installation { if p == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 2af54b40208..c6c4808f67d 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -41604,6 +41604,88 @@ func TestProtectionRule_GetWaitTimer(tt *testing.T) { p.GetWaitTimer() } +func TestProvisionAndInviteSCIMUserRequest_GetActive(tt *testing.T) { + tt.Parallel() + var zeroValue bool + p := &ProvisionAndInviteSCIMUserRequest{Active: &zeroValue} + p.GetActive() + p = &ProvisionAndInviteSCIMUserRequest{} + p.GetActive() + p = nil + p.GetActive() +} + +func TestProvisionAndInviteSCIMUserRequest_GetDisplayName(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &ProvisionAndInviteSCIMUserRequest{DisplayName: &zeroValue} + p.GetDisplayName() + p = &ProvisionAndInviteSCIMUserRequest{} + p.GetDisplayName() + p = nil + p.GetDisplayName() +} + +func TestProvisionAndInviteSCIMUserRequest_GetEmails(tt *testing.T) { + tt.Parallel() + zeroValue := []*SCIMUserEmail{} + p := &ProvisionAndInviteSCIMUserRequest{Emails: zeroValue} + p.GetEmails() + p = &ProvisionAndInviteSCIMUserRequest{} + p.GetEmails() + p = nil + p.GetEmails() +} + +func TestProvisionAndInviteSCIMUserRequest_GetExternalID(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &ProvisionAndInviteSCIMUserRequest{ExternalID: &zeroValue} + p.GetExternalID() + p = &ProvisionAndInviteSCIMUserRequest{} + p.GetExternalID() + p = nil + p.GetExternalID() +} + +func TestProvisionAndInviteSCIMUserRequest_GetGroups(tt *testing.T) { + tt.Parallel() + zeroValue := []string{} + p := &ProvisionAndInviteSCIMUserRequest{Groups: zeroValue} + p.GetGroups() + p = &ProvisionAndInviteSCIMUserRequest{} + p.GetGroups() + p = nil + p.GetGroups() +} + +func TestProvisionAndInviteSCIMUserRequest_GetName(tt *testing.T) { + tt.Parallel() + p := &ProvisionAndInviteSCIMUserRequest{} + p.GetName() + p = nil + p.GetName() +} + +func TestProvisionAndInviteSCIMUserRequest_GetSchemas(tt *testing.T) { + tt.Parallel() + zeroValue := []string{} + p := &ProvisionAndInviteSCIMUserRequest{Schemas: zeroValue} + p.GetSchemas() + p = &ProvisionAndInviteSCIMUserRequest{} + p.GetSchemas() + p = nil + p.GetSchemas() +} + +func TestProvisionAndInviteSCIMUserRequest_GetUserName(tt *testing.T) { + tt.Parallel() + p := &ProvisionAndInviteSCIMUserRequest{} + p.GetUserName() + p = nil + p.GetUserName() +} + func TestPublicEvent_GetInstallation(tt *testing.T) { tt.Parallel() p := &PublicEvent{} diff --git a/github/scim.go b/github/scim.go index 25abfc7ae14..3de962e33a3 100644 --- a/github/scim.go +++ b/github/scim.go @@ -122,12 +122,25 @@ func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org str return identities, resp, nil } +// ProvisionAndInviteSCIMUserRequest represents the body of a request to +// provision and invite a SCIM user. +type ProvisionAndInviteSCIMUserRequest struct { + UserName string `json:"userName"` // Configured by the admin. Could be an email, login, or username. (Required.) + Name SCIMUserName `json:"name"` // (Required.) + DisplayName *string `json:"displayName,omitempty"` // The name of the user, suitable for display to end-users. (Optional.) + Emails []*SCIMUserEmail `json:"emails"` // User emails. (Required.) + Schemas []string `json:"schemas,omitzero"` // (Optional.) + ExternalID *string `json:"externalId,omitempty"` // (Optional.) + Groups []string `json:"groups,omitzero"` // (Optional.) + Active *bool `json:"active,omitempty"` // (Optional.) +} + // ProvisionAndInviteSCIMUser provisions organization membership for a user, and sends an activation email to the email address. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim?apiVersion=2022-11-28#provision-and-invite-a-scim-user // //meta:operation POST /scim/v2/organizations/{org}/Users -func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, body *SCIMUserAttributes) (*SCIMUserAttributes, *Response, error) { +func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, body ProvisionAndInviteSCIMUserRequest) (*SCIMUserAttributes, *Response, error) { u := fmt.Sprintf("scim/v2/organizations/%v/Users", org) req, err := s.client.NewRequest(ctx, "POST", u, body) diff --git a/github/scim_test.go b/github/scim_test.go index f63041339c2..d95ab70fa73 100644 --- a/github/scim_test.go +++ b/github/scim_test.go @@ -128,14 +128,7 @@ func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - mux.HandleFunc("/scim/v2/organizations/o/Users", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "POST") - w.WriteHeader(http.StatusCreated) - fmt.Fprint(w, `{"id":"1234567890","userName":"userName"}`) - }) - - ctx := t.Context() - opts := &SCIMUserAttributes{ + body := ProvisionAndInviteSCIMUserRequest{ UserName: "userName", Name: SCIMUserName{ GivenName: "givenName", @@ -147,7 +140,16 @@ func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) { }, }, } - user, _, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts) + + mux.HandleFunc("/scim/v2/organizations/o/Users", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testJSONBody(t, r, body) + w.WriteHeader(http.StatusCreated) + fmt.Fprint(w, `{"id":"1234567890","userName":"userName"}`) + }) + + ctx := t.Context() + user, _, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", body) if err != nil { t.Errorf("SCIM.ProvisionAndInviteSCIMUser returned error: %v", err) } @@ -162,12 +164,12 @@ func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) { const methodName = "ProvisionAndInviteSCIMUser" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.SCIM.ProvisionAndInviteSCIMUser(ctx, "\n", opts) + _, _, err = client.SCIM.ProvisionAndInviteSCIMUser(ctx, "\n", body) return err }) testNewRequestAndDoFailureCategory(t, methodName, client, ScimCategory, func() (*Response, error) { - got, resp, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts) + got, resp, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", body) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) }