From 9e98dd914688d52559c1d1b71fbb620e72ba5558 Mon Sep 17 00:00:00 2001 From: Travis Tomsu Date: Wed, 10 Jan 2024 09:48:25 -0500 Subject: [PATCH] Add suspended as option to AdminService.CreateUser() --- github/admin_users.go | 12 +++++++----- github/admin_users_test.go | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/github/admin_users.go b/github/admin_users.go index 0d3fe9fafc1..be0f225fcb9 100644 --- a/github/admin_users.go +++ b/github/admin_users.go @@ -13,8 +13,9 @@ import ( // createUserRequest is a subset of User and is used internally // by CreateUser to pass only the known fields for the endpoint. type createUserRequest struct { - Login *string `json:"login,omitempty"` - Email *string `json:"email,omitempty"` + Login *string `json:"login,omitempty"` + Email *string `json:"email,omitempty"` + Suspended *bool `json:"suspended,omitempty"` } // CreateUser creates a new user in GitHub Enterprise. @@ -22,12 +23,13 @@ type createUserRequest struct { // GitHub API docs: https://docs.github.com/enterprise-server@3.11/rest/enterprise-admin/users#create-a-user // //meta:operation POST /admin/users -func (s *AdminService) CreateUser(ctx context.Context, login, email string) (*User, *Response, error) { +func (s *AdminService) CreateUser(ctx context.Context, login, email string, suspended bool) (*User, *Response, error) { u := "admin/users" userReq := &createUserRequest{ - Login: &login, - Email: &email, + Login: &login, + Email: &email, + Suspended: &suspended, } req, err := s.client.NewRequest("POST", u, userReq) diff --git a/github/admin_users_test.go b/github/admin_users_test.go index 2dac611709e..a61a06522d2 100644 --- a/github/admin_users_test.go +++ b/github/admin_users_test.go @@ -25,7 +25,7 @@ func TestAdminUsers_Create(t *testing.T) { assertNilError(t, json.NewDecoder(r.Body).Decode(v)) testMethod(t, r, "POST") - want := &createUserRequest{Login: String("github"), Email: String("email@domain.com")} + want := &createUserRequest{Login: String("github"), Email: String("email@domain.com"), Suspended: Bool(false)} if !cmp.Equal(v, want) { t.Errorf("Request body = %+v, want %+v", v, want) } @@ -34,7 +34,7 @@ func TestAdminUsers_Create(t *testing.T) { }) ctx := context.Background() - org, _, err := client.Admin.CreateUser(ctx, "github", "email@domain.com") + org, _, err := client.Admin.CreateUser(ctx, "github", "email@domain.com", false) if err != nil { t.Errorf("Admin.CreateUser returned error: %v", err) } @@ -46,7 +46,7 @@ func TestAdminUsers_Create(t *testing.T) { const methodName = "CreateUser" testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Admin.CreateUser(ctx, "github", "email@domain.com") + got, resp, err := client.Admin.CreateUser(ctx, "github", "email@domain.com", false) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) }