Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ linters:
- EncryptedSecret
- EnterpriseSecurityAnalysisSettings
- Hook
- ImpersonateUserOptions
- Import
- InstallationTokenListRepoOptions
- InstallationTokenOptions
Expand Down Expand Up @@ -274,7 +273,6 @@ linters:
- CreateCodespaceOptions
- CreateOrUpdateIssueTypesOptions
- CreateOrgInvitationOptions
- ImpersonateUserOptions
- InstallationTokenListRepoOptions
- InstallationTokenOptions
- LockIssueOptions
Expand Down
9 changes: 5 additions & 4 deletions github/admin_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions github/admin_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 8 additions & 8 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading