Repository: google/go-github
Pull request #1112 (2019-02-03 23:28:15)

add UserSuspendOptions for user.Suspend
GitHub updated the [suspend a user endpoint](https://developer.github.com/enterprise/v3/enterprise-admin/users/#suspend-a-user) to allow you to send a JSON payload containing the reason that the specified user is being suspended. If you input `""` for the reason, GitHub will default the reason to `Suspended via API by SITE_ADMINISTRATOR` in the audit log.

JordanSussman: Thanks for the feedback, @gmlewis. 

The latest commit should address the requested updates.

Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 2c6c05a1..cb2f0284 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -7324,6 +7324,14 @@ func (p *PullRequest) GetPatchURL() string {
 	return *p.PatchURL
 }
 
+// GetReviewComments returns the ReviewComments field if it's non-nil, zero value otherwise.
+func (p *PullRequest) GetReviewComments() int {
+	if p == nil || p.ReviewComments == nil {
+		return 0
+	}
+	return *p.ReviewComments
+}
+
 // GetReviewCommentsURL returns the ReviewCommentsURL field if it's non-nil, zero value otherwise.
 func (p *PullRequest) GetReviewCommentsURL() string {
 	if p == nil || p.ReviewCommentsURL == nil {
@@ -12148,6 +12156,14 @@ func (u *UserStats) GetTotalUsers() int {
 	return *u.TotalUsers
 }
 
+// GetReason returns the Reason field if it's non-nil, zero value otherwise.
+func (u *UserSuspendOptions) GetReason() string {
+	if u == nil || u.Reason == nil {
+		return ""
+	}
+	return *u.Reason
+}
+
 // GetAction returns the Action field if it's non-nil, zero value otherwise.
 func (w *WatchEvent) GetAction() string {
 	if w == nil || w.Action == nil {
diff --git a/github/pulls.go b/github/pulls.go
index aac34792..b3479dfe 100644
--- a/github/pulls.go
+++ b/github/pulls.go
@@ -52,6 +52,7 @@ type PullRequest struct {
 	CommentsURL         *string    `json:"comments_url,omitempty"`
 	ReviewCommentsURL   *string    `json:"review_comments_url,omitempty"`
 	ReviewCommentURL    *string    `json:"review_comment_url,omitempty"`
+	ReviewComments      *int       `json:"review_comments,omitempty"`
 	Assignee            *User      `json:"assignee,omitempty"`
 	Assignees           []*User    `json:"assignees,omitempty"`
 	Milestone           *Milestone `json:"milestone,omitempty"`
diff --git a/github/users_administration.go b/github/users_administration.go
index 05c7e3af..1c483a7b 100644
--- a/github/users_administration.go
+++ b/github/users_administration.go
@@ -38,13 +38,18 @@ func (s *UsersService) DemoteSiteAdmin(ctx context.Context, user string) (*Respo
 	return s.client.Do(ctx, req, nil)
 }
 
+// UserSuspendOptions represents the reason a user is being suspended.
+type UserSuspendOptions struct {
+	Reason *string `json:"reason,omitempty"`
+}
+
 // Suspend a user on a GitHub Enterprise instance.
 //
 // GitHub API docs: https://developer.github.com/enterprise/v3/enterprise-admin/users/#suspend-a-user
-func (s *UsersService) Suspend(ctx context.Context, user string) (*Response, error) {
+func (s *UsersService) Suspend(ctx context.Context, user string, opt *UserSuspendOptions) (*Response, error) {
 	u := fmt.Sprintf("users/%v/suspended", user)
 
-	req, err := s.client.NewRequest("PUT", u, nil)
+	req, err := s.client.NewRequest("PUT", u, opt)
 	if err != nil {
 		return nil, err
 	}


Test patch:
diff --git a/github/users_administration_test.go b/github/users_administration_test.go
index 4b0955e9..c1d9f975 100644
--- a/github/users_administration_test.go
+++ b/github/users_administration_test.go
@@ -7,7 +7,9 @@ package github
 
 import (
 	"context"
+	"encoding/json"
 	"net/http"
+	"reflect"
 	"testing"
 )
 
@@ -50,7 +52,31 @@ func TestUsersService_Suspend(t *testing.T) {
 		w.WriteHeader(http.StatusNoContent)
 	})
 
-	_, err := client.Users.Suspend(context.Background(), "u")
+	_, err := client.Users.Suspend(context.Background(), "u", nil)
+	if err != nil {
+		t.Errorf("Users.Suspend returned error: %v", err)
+	}
+}
+
+func TestUsersServiceReason_Suspend(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	input := &UserSuspendOptions{Reason: String("test")}
+
+	mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) {
+		v := new(UserSuspendOptions)
+		json.NewDecoder(r.Body).Decode(v)
+
+		testMethod(t, r, "PUT")
+		if !reflect.DeepEqual(v, input) {
+			t.Errorf("Request body = %+v, want %+v", v, input)
+		}
+
+		w.WriteHeader(http.StatusNoContent)
+	})
+
+	_, err := client.Users.Suspend(context.Background(), "u", input)
 	if err != nil {
 		t.Errorf("Users.Suspend returned error: %v", err)
 	}