diff --git a/github/github-accessors.go b/github/github-accessors.go index e192e57d774..cdd754644d0 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -45702,6 +45702,14 @@ func (u *UnauthenticatedRateLimitedTransport) GetClientSecret() string { return u.ClientSecret } +// GetReason returns the Reason field if it's non-nil, zero value otherwise. +func (u *UnsuspendUserRequest) GetReason() string { + if u == nil || u.Reason == nil { + return "" + } + return *u.Reason +} + // GetConditions returns the Conditions field. func (u *UpdateActionsPolicyRequest) GetConditions() *ActionsPolicyConditions { if u == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index e86fbcce1fc..7f0ec880522 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -56962,6 +56962,17 @@ func TestUnauthenticatedRateLimitedTransport_GetClientSecret(tt *testing.T) { u.GetClientSecret() } +func TestUnsuspendUserRequest_GetReason(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UnsuspendUserRequest{Reason: &zeroValue} + u.GetReason() + u = &UnsuspendUserRequest{} + u.GetReason() + u = nil + u.GetReason() +} + func TestUpdateActionsPolicyRequest_GetConditions(tt *testing.T) { tt.Parallel() u := &UpdateActionsPolicyRequest{} diff --git a/github/users_administration.go b/github/users_administration.go index 34e603ab61e..46e72bd73bf 100644 --- a/github/users_administration.go +++ b/github/users_administration.go @@ -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"` +} + // 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 } diff --git a/github/users_administration_test.go b/github/users_administration_test.go index 563975823b8..ef82676b6f8 100644 --- a/github/users_administration_test.go +++ b/github/users_administration_test.go @@ -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) + } +}