Skip to content

Commit 443eb9c

Browse files
JordanSussmangmlewis
authored andcommitted
add UserSuspendOptions for user.Suspend (#1112)
1 parent fbfacb4 commit 443eb9c

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

github/github-accessors.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/users_administration.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ func (s *UsersService) DemoteSiteAdmin(ctx context.Context, user string) (*Respo
3838
return s.client.Do(ctx, req, nil)
3939
}
4040

41+
// UserSuspendOptions represents the reason a user is being suspended.
42+
type UserSuspendOptions struct {
43+
Reason *string `json:"reason,omitempty"`
44+
}
45+
4146
// Suspend a user on a GitHub Enterprise instance.
4247
//
4348
// GitHub API docs: https://developer.github.com/enterprise/v3/enterprise-admin/users/#suspend-a-user
44-
func (s *UsersService) Suspend(ctx context.Context, user string) (*Response, error) {
49+
func (s *UsersService) Suspend(ctx context.Context, user string, opt *UserSuspendOptions) (*Response, error) {
4550
u := fmt.Sprintf("users/%v/suspended", user)
4651

47-
req, err := s.client.NewRequest("PUT", u, nil)
52+
req, err := s.client.NewRequest("PUT", u, opt)
4853
if err != nil {
4954
return nil, err
5055
}

github/users_administration_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ package github
77

88
import (
99
"context"
10+
"encoding/json"
1011
"net/http"
12+
"reflect"
1113
"testing"
1214
)
1315

@@ -50,7 +52,31 @@ func TestUsersService_Suspend(t *testing.T) {
5052
w.WriteHeader(http.StatusNoContent)
5153
})
5254

53-
_, err := client.Users.Suspend(context.Background(), "u")
55+
_, err := client.Users.Suspend(context.Background(), "u", nil)
56+
if err != nil {
57+
t.Errorf("Users.Suspend returned error: %v", err)
58+
}
59+
}
60+
61+
func TestUsersServiceReason_Suspend(t *testing.T) {
62+
client, mux, _, teardown := setup()
63+
defer teardown()
64+
65+
input := &UserSuspendOptions{Reason: String("test")}
66+
67+
mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) {
68+
v := new(UserSuspendOptions)
69+
json.NewDecoder(r.Body).Decode(v)
70+
71+
testMethod(t, r, "PUT")
72+
if !reflect.DeepEqual(v, input) {
73+
t.Errorf("Request body = %+v, want %+v", v, input)
74+
}
75+
76+
w.WriteHeader(http.StatusNoContent)
77+
})
78+
79+
_, err := client.Users.Suspend(context.Background(), "u", input)
5480
if err != nil {
5581
t.Errorf("Users.Suspend returned error: %v", err)
5682
}

0 commit comments

Comments
 (0)