Skip to content
Open
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
8 changes: 8 additions & 0 deletions github/github-accessors.go

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

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

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

12 changes: 10 additions & 2 deletions github/users_administration.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,23 @@ func (s *UsersService) Suspend(ctx context.Context, user string, body *UserSuspe
return s.client.Do(req, nil)
}

// UnsuspendUserRequest represents a request to unsuspend a user.
type UnsuspendUserRequest struct {
// Reason is the reason the user is being unsuspended, which is logged in the audit log.
// If it is not provided, it defaults to "Unsuspended via API by SITE_ADMINISTRATOR",
// where SITE_ADMINISTRATOR is the person who performed the action.
Reason *string `json:"reason,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a comment documenting its default value?

The reason the user is being unsuspended. This message will be logged in the audit log. If you don't provide a reason, it will default to "Unsuspended via API by SITE_ADMINISTRATOR", where SITE_ADMINISTRATOR is the person who performed the action.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @Not-Dhananjay-Mishra! Added a comment documenting the default value in 9b2daa6.

}

// Unsuspend a user on a GitHub Enterprise instance.
//
// GitHub API docs: https://docs.github.com/enterprise-server@3.22/rest/enterprise-admin/users#unsuspend-a-user
//
//meta:operation DELETE /users/{username}/suspended
func (s *UsersService) Unsuspend(ctx context.Context, user string) (*Response, error) {
func (s *UsersService) Unsuspend(ctx context.Context, user string, body UnsuspendUserRequest) (*Response, error) {
u := fmt.Sprintf("users/%v/suspended", user)

req, err := s.client.NewRequest(ctx, "DELETE", u, nil)
req, err := s.client.NewRequest(ctx, "DELETE", u, body)
if err != nil {
return nil, err
}
Expand Down
25 changes: 22 additions & 3 deletions github/users_administration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,37 @@ func TestUsersService_Unsuspend(t *testing.T) {
})

ctx := t.Context()
_, err := client.Users.Unsuspend(ctx, "u")
_, err := client.Users.Unsuspend(ctx, "u", UnsuspendUserRequest{})
if err != nil {
t.Errorf("Users.Unsuspend returned error: %v", err)
}

const methodName = "Unsuspend"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Users.Unsuspend(ctx, "\n")
_, err = client.Users.Unsuspend(ctx, "\n", UnsuspendUserRequest{})
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Users.Unsuspend(ctx, "u")
return client.Users.Unsuspend(ctx, "u", UnsuspendUserRequest{})
})
}

func TestUsersServiceReason_Unsuspend(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

body := UnsuspendUserRequest{Reason: new("test")}

mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testJSONBody(t, r, body)
w.WriteHeader(http.StatusNoContent)
})

ctx := t.Context()
_, err := client.Users.Unsuspend(ctx, "u", body)
if err != nil {
t.Errorf("Users.Unsuspend returned error: %v", err)
}
}
Loading