diff --git a/.golangci.yml b/.golangci.yml index adb297b6ebd..c00c80ada65 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -223,7 +223,6 @@ linters: - EncryptedSecret - EnterpriseSecurityAnalysisSettings - Hook - - ImpersonateUserOptions - Import - InstallationTokenListRepoOptions - InstallationTokenOptions @@ -274,7 +273,6 @@ linters: - CreateCodespaceOptions - CreateOrUpdateIssueTypesOptions - CreateOrgInvitationOptions - - ImpersonateUserOptions - InstallationTokenListRepoOptions - InstallationTokenOptions - LockIssueOptions diff --git a/github/admin_users.go b/github/admin_users.go index 9468f077f15..61844112e28 100644 --- a/github/admin_users.go +++ b/github/admin_users.go @@ -61,9 +61,10 @@ func (s *AdminService) DeleteUser(ctx context.Context, username string) (*Respon return resp, nil } -// ImpersonateUserOptions represents the scoping for the OAuth token. -type ImpersonateUserOptions struct { - Scopes []string `json:"scopes,omitempty"` +// CreateUserImpersonationRequest represents the scoping for the OAuth token. +// Note that `Scopes` is a required field. +type CreateUserImpersonationRequest struct { + Scopes []string `json:"scopes"` } // OAuthAPP represents the GitHub Site Administrator OAuth app. @@ -98,7 +99,7 @@ type UserAuthorization struct { // GitHub API docs: https://docs.github.com/enterprise-server@3.21/rest/enterprise-admin/users#create-an-impersonation-oauth-token // //meta:operation POST /admin/users/{username}/authorizations -func (s *AdminService) CreateUserImpersonation(ctx context.Context, username string, body *ImpersonateUserOptions) (*UserAuthorization, *Response, error) { +func (s *AdminService) CreateUserImpersonation(ctx context.Context, username string, body CreateUserImpersonationRequest) (*UserAuthorization, *Response, error) { u := fmt.Sprintf("admin/users/%v/authorizations", username) req, err := s.client.NewRequest(ctx, "POST", u, body) diff --git a/github/admin_users_test.go b/github/admin_users_test.go index bf462a8b2de..5a0ed0536f5 100644 --- a/github/admin_users_test.go +++ b/github/admin_users_test.go @@ -75,11 +75,11 @@ func TestUserImpersonation_Create(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - opt := &ImpersonateUserOptions{Scopes: []string{"repo"}} + body := CreateUserImpersonationRequest{Scopes: []string{"repo"}} mux.HandleFunc("/admin/users/github/authorizations", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - testJSONBody(t, r, opt) + testJSONBody(t, r, body) fmt.Fprint(w, `{"id": 1234, "url": "https://example.com/authorizations", "app": { @@ -101,7 +101,7 @@ func TestUserImpersonation_Create(t *testing.T) { }) ctx := t.Context() - auth, _, err := client.Admin.CreateUserImpersonation(ctx, "github", opt) + auth, _, err := client.Admin.CreateUserImpersonation(ctx, "github", body) if err != nil { t.Errorf("Admin.CreateUserImpersonation returned error: %v", err) } @@ -130,12 +130,12 @@ func TestUserImpersonation_Create(t *testing.T) { const methodName = "CreateUserImpersonation" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Admin.CreateUserImpersonation(ctx, "\n", opt) + _, _, err = client.Admin.CreateUserImpersonation(ctx, "\n", body) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Admin.CreateUserImpersonation(ctx, "github", opt) + got, resp, err := client.Admin.CreateUserImpersonation(ctx, "github", body) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } diff --git a/github/github-accessors.go b/github/github-accessors.go index ac6b242f8a0..355b7e92e08 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -12006,6 +12006,14 @@ func (c *CreateUpdateEnvironment) GetWaitTimer() int { return *c.WaitTimer } +// GetScopes returns the Scopes slice if it's non-nil, nil otherwise. +func (c *CreateUserImpersonationRequest) GetScopes() []string { + if c == nil || c.Scopes == nil { + return nil + } + return c.Scopes +} + // GetEmail returns the Email field if it's non-nil, zero value otherwise. func (c *CreateUserRequest) GetEmail() string { if c == nil || c.Email == nil { @@ -18902,14 +18910,6 @@ func (i *ImmutableReleaseSettings) GetSelectedRepositoriesURL() string { return *i.SelectedRepositoriesURL } -// GetScopes returns the Scopes slice if it's non-nil, nil otherwise. -func (i *ImpersonateUserOptions) GetScopes() []string { - if i == nil || i.Scopes == nil { - return nil - } - return i.Scopes -} - // GetAuthorsCount returns the AuthorsCount field if it's non-nil, zero value otherwise. func (i *Import) GetAuthorsCount() int { if i == nil || i.AuthorsCount == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index fdc048b3a0d..c7891f2ad70 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -15223,6 +15223,17 @@ func TestCreateUpdateEnvironment_GetWaitTimer(tt *testing.T) { c.GetWaitTimer() } +func TestCreateUserImpersonationRequest_GetScopes(tt *testing.T) { + tt.Parallel() + zeroValue := []string{} + c := &CreateUserImpersonationRequest{Scopes: zeroValue} + c.GetScopes() + c = &CreateUserImpersonationRequest{} + c.GetScopes() + c = nil + c.GetScopes() +} + func TestCreateUserRequest_GetEmail(tt *testing.T) { tt.Parallel() var zeroValue string @@ -23757,17 +23768,6 @@ func TestImmutableReleaseSettings_GetSelectedRepositoriesURL(tt *testing.T) { i.GetSelectedRepositoriesURL() } -func TestImpersonateUserOptions_GetScopes(tt *testing.T) { - tt.Parallel() - zeroValue := []string{} - i := &ImpersonateUserOptions{Scopes: zeroValue} - i.GetScopes() - i = &ImpersonateUserOptions{} - i.GetScopes() - i = nil - i.GetScopes() -} - func TestImport_GetAuthorsCount(tt *testing.T) { tt.Parallel() var zeroValue int