Skip to content

Commit

Permalink
Add suspended as option to AdminService.CreateUser()
Browse files Browse the repository at this point in the history
  • Loading branch information
ttomsu committed Jan 10, 2024
1 parent 207a38d commit 9e98dd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions github/admin_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ 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.
//
// 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)
Expand Down
6 changes: 3 additions & 3 deletions github/admin_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 9e98dd9

Please sign in to comment.