diff --git a/.golangci.yml b/.golangci.yml index 683c72ff4c5..02bb8bf9c44 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -219,13 +219,11 @@ linters: - InstallationTokenListRepoOptions - InstallationTokenOptions - IssueImportRequest - - LockIssueOptions - MaintenanceOptions - Organization - PagesUpdate - PagesUpdateWithoutCNAME - ProtectionRequest - - PullRequestBranchUpdateOptions - PullRequestReviewRequest - PullRequestReviewsEnforcementUpdate - Repository @@ -235,7 +233,6 @@ linters: - SourceImportAuthor - Subscription - UpdateDefaultSetupConfigurationOptions - - UserSuspendOptions - WorkflowsPermissionsOpt # Body type names exempt from the "Options" suffix rule. # TODO: fix and remove these exceptions. @@ -247,13 +244,10 @@ linters: - CreateOrUpdateIssueTypesOptions - InstallationTokenListRepoOptions - InstallationTokenOptions - - LockIssueOptions - MaintenanceOptions - - PullRequestBranchUpdateOptions - RepositoryContentFileOptions - UpdateCheckRunOptions - UpdateDefaultSetupConfigurationOptions - - UserSuspendOptions sliceofpointers: type: module description: Reports usage of []*string and slices of structs without pointers. @@ -404,7 +398,6 @@ linters: - ListSCIMProvisionedIdentitiesOptions.Filter - ListSCIMProvisionedIdentitiesOptions.StartIndex - ListUserIssuesOptions.Since - - LockIssueOptions.LockReason # TODO: Issues - MarketplacePlan.Bullets # TODO: Marketplaces - NodeQueryOptions.ClusterRoles - NodeQueryOptions.UUID diff --git a/github/github-accessors.go b/github/github-accessors.go index e192e57d774..943e983738e 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -25694,12 +25694,12 @@ func (l *LockBranch) GetEnabled() bool { return *l.Enabled } -// GetLockReason returns the LockReason field. -func (l *LockIssueOptions) GetLockReason() string { - if l == nil { +// GetLockReason returns the LockReason field if it's non-nil, zero value otherwise. +func (l *LockIssueRequest) GetLockReason() string { + if l == nil || l.LockReason == nil { return "" } - return l.LockReason + return *l.LockReason } // GetHostname returns the Hostname field if it's non-nil, zero value otherwise. @@ -33142,14 +33142,6 @@ func (p *PullRequestBranchRule) GetParameters() PullRequestRuleParameters { return p.Parameters } -// GetExpectedHeadSHA returns the ExpectedHeadSHA field if it's non-nil, zero value otherwise. -func (p *PullRequestBranchUpdateOptions) GetExpectedHeadSHA() string { - if p == nil || p.ExpectedHeadSHA == nil { - return "" - } - return *p.ExpectedHeadSHA -} - // GetMessage returns the Message field if it's non-nil, zero value otherwise. func (p *PullRequestBranchUpdateResponse) GetMessage() string { if p == nil || p.Message == nil { @@ -44238,6 +44230,14 @@ func (s *Subscription) GetURL() string { return *s.URL } +// GetReason returns the Reason field if it's non-nil, zero value otherwise. +func (s *SuspendUserRequest) GetReason() string { + if s == nil || s.Reason == nil { + return "" + } + return *s.Reason +} + // GetNodes returns the Nodes slice if it's non-nil, nil otherwise. func (s *SystemRequirements) GetNodes() []*SystemRequirementsNode { if s == nil || s.Nodes == nil { @@ -46630,6 +46630,14 @@ func (u *UpdateProvisionedOrgMembershipRequest) GetUserName() string { return u.UserName } +// GetExpectedHeadSHA returns the ExpectedHeadSHA field if it's non-nil, zero value otherwise. +func (u *UpdatePullRequestBranchRequest) GetExpectedHeadSHA() string { + if u == nil || u.ExpectedHeadSHA == nil { + return "" + } + return *u.ExpectedHeadSHA +} + // GetBody returns the Body field. func (u *UpdatePullRequestCommentRequest) GetBody() string { if u == nil { @@ -48198,14 +48206,6 @@ 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 -} - // GetBio returns the Bio field if it's non-nil, zero value otherwise. func (u *UserUpdateRequest) GetBio() string { if u == nil || u.Bio == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index e86fbcce1fc..2b9fc86879d 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -32076,9 +32076,12 @@ func TestLockBranch_GetEnabled(tt *testing.T) { l.GetEnabled() } -func TestLockIssueOptions_GetLockReason(tt *testing.T) { +func TestLockIssueRequest_GetLockReason(tt *testing.T) { tt.Parallel() - l := &LockIssueOptions{} + var zeroValue string + l := &LockIssueRequest{LockReason: &zeroValue} + l.GetLockReason() + l = &LockIssueRequest{} l.GetLockReason() l = nil l.GetLockReason() @@ -41492,17 +41495,6 @@ func TestPullRequestBranchRule_GetParameters(tt *testing.T) { p.GetParameters() } -func TestPullRequestBranchUpdateOptions_GetExpectedHeadSHA(tt *testing.T) { - tt.Parallel() - var zeroValue string - p := &PullRequestBranchUpdateOptions{ExpectedHeadSHA: &zeroValue} - p.GetExpectedHeadSHA() - p = &PullRequestBranchUpdateOptions{} - p.GetExpectedHeadSHA() - p = nil - p.GetExpectedHeadSHA() -} - func TestPullRequestBranchUpdateResponse_GetMessage(tt *testing.T) { tt.Parallel() var zeroValue string @@ -55087,6 +55079,17 @@ func TestSubscription_GetURL(tt *testing.T) { s.GetURL() } +func TestSuspendUserRequest_GetReason(tt *testing.T) { + tt.Parallel() + var zeroValue string + s := &SuspendUserRequest{Reason: &zeroValue} + s.GetReason() + s = &SuspendUserRequest{} + s.GetReason() + s = nil + s.GetReason() +} + func TestSystemRequirements_GetNodes(tt *testing.T) { tt.Parallel() zeroValue := []*SystemRequirementsNode{} @@ -58175,6 +58178,17 @@ func TestUpdateProvisionedOrgMembershipRequest_GetUserName(tt *testing.T) { u.GetUserName() } +func TestUpdatePullRequestBranchRequest_GetExpectedHeadSHA(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdatePullRequestBranchRequest{ExpectedHeadSHA: &zeroValue} + u.GetExpectedHeadSHA() + u = &UpdatePullRequestBranchRequest{} + u.GetExpectedHeadSHA() + u = nil + u.GetExpectedHeadSHA() +} + func TestUpdatePullRequestCommentRequest_GetBody(tt *testing.T) { tt.Parallel() u := &UpdatePullRequestCommentRequest{} @@ -60181,17 +60195,6 @@ func TestUserStats_GetTotalUsers(tt *testing.T) { u.GetTotalUsers() } -func TestUserSuspendOptions_GetReason(tt *testing.T) { - tt.Parallel() - var zeroValue string - u := &UserSuspendOptions{Reason: &zeroValue} - u.GetReason() - u = &UserSuspendOptions{} - u.GetReason() - u = nil - u.GetReason() -} - func TestUserUpdateRequest_GetBio(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/issues.go b/github/issues.go index 4140e3c1f20..07526ee3c4b 100644 --- a/github/issues.go +++ b/github/issues.go @@ -543,13 +543,12 @@ func (s *IssuesService) RemoveMilestone(ctx context.Context, owner, repo string, return i, resp, nil } -// LockIssueOptions specifies the optional parameters to the -// IssuesService.Lock method. -type LockIssueOptions struct { +// LockIssueRequest represents a request to lock an issue. +type LockIssueRequest struct { // LockReason specifies the reason to lock this issue. // Providing a lock reason can help make it clearer to contributors why an issue // was locked. Possible values are: "off-topic", "too heated", "resolved", and "spam". - LockReason string `json:"lock_reason,omitempty"` + LockReason *string `json:"lock_reason,omitempty"` } // Lock an issue's conversation. @@ -557,7 +556,7 @@ type LockIssueOptions struct { // GitHub API docs: https://docs.github.com/rest/issues/issues?apiVersion=2022-11-28#lock-an-issue // //meta:operation PUT /repos/{owner}/{repo}/issues/{issue_number}/lock -func (s *IssuesService) Lock(ctx context.Context, owner, repo string, number int, body *LockIssueOptions) (*Response, error) { +func (s *IssuesService) Lock(ctx context.Context, owner, repo string, number int, body LockIssueRequest) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/issues/%v/lock", owner, repo, number) req, err := s.client.NewRequest(ctx, "PUT", u, body) if err != nil { diff --git a/github/issues_test.go b/github/issues_test.go index 6952c5d5447..4fb87b38e5b 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -483,18 +483,18 @@ func TestIssuesService_Lock(t *testing.T) { }) ctx := t.Context() - if _, err := client.Issues.Lock(ctx, "o", "r", 1, nil); err != nil { + if _, err := client.Issues.Lock(ctx, "o", "r", 1, LockIssueRequest{}); err != nil { t.Errorf("Issues.Lock returned error: %v", err) } const methodName = "Lock" testBadOptions(t, methodName, func() (err error) { - _, err = client.Issues.Lock(ctx, "\n", "\n", -1, nil) + _, err = client.Issues.Lock(ctx, "\n", "\n", -1, LockIssueRequest{}) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Issues.Lock(ctx, "o", "r", 1, nil) + return client.Issues.Lock(ctx, "o", "r", 1, LockIssueRequest{}) }) } @@ -502,15 +502,16 @@ func TestIssuesService_LockWithReason(t *testing.T) { t.Parallel() client, mux, _ := setup(t) + body := LockIssueRequest{LockReason: new("off-topic")} + mux.HandleFunc("/repos/o/r/issues/1/lock", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") + testJSONBody(t, r, body) w.WriteHeader(http.StatusNoContent) }) - opt := &LockIssueOptions{LockReason: "off-topic"} - ctx := t.Context() - if _, err := client.Issues.Lock(ctx, "o", "r", 1, opt); err != nil { + if _, err := client.Issues.Lock(ctx, "o", "r", 1, body); err != nil { t.Errorf("Issues.Lock returned error: %v", err) } } diff --git a/github/pulls.go b/github/pulls.go index e244178e665..3000b93e4c8 100644 --- a/github/pulls.go +++ b/github/pulls.go @@ -326,9 +326,8 @@ func (s *PullRequestsService) Create(ctx context.Context, owner, repo string, bo return p, resp, nil } -// PullRequestBranchUpdateOptions specifies the optional parameters to the -// PullRequestsService.UpdateBranch method. -type PullRequestBranchUpdateOptions struct { +// UpdatePullRequestBranchRequest represents a request to update a pull request branch. +type UpdatePullRequestBranchRequest struct { // ExpectedHeadSHA specifies the most recent commit on the pull request's branch. // Default value is the SHA of the pull request's current HEAD ref. ExpectedHeadSHA *string `json:"expected_head_sha,omitempty"` @@ -351,7 +350,7 @@ type PullRequestBranchUpdateResponse struct { // GitHub API docs: https://docs.github.com/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request-branch // //meta:operation PUT /repos/{owner}/{repo}/pulls/{pull_number}/update-branch -func (s *PullRequestsService) UpdateBranch(ctx context.Context, owner, repo string, number int, body *PullRequestBranchUpdateOptions) (*PullRequestBranchUpdateResponse, *Response, error) { +func (s *PullRequestsService) UpdateBranch(ctx context.Context, owner, repo string, number int, body UpdatePullRequestBranchRequest) (*PullRequestBranchUpdateResponse, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%v/update-branch", owner, repo, number) req, err := s.client.NewRequest(ctx, "PUT", u, body) diff --git a/github/pulls_test.go b/github/pulls_test.go index 947fe647b62..5acc508791d 100644 --- a/github/pulls_test.go +++ b/github/pulls_test.go @@ -403,9 +403,14 @@ func TestPullRequestsService_UpdateBranch(t *testing.T) { t.Parallel() client, mux, _ := setup(t) + body := UpdatePullRequestBranchRequest{ + ExpectedHeadSHA: new("s"), + } + mux.HandleFunc("/repos/o/r/pulls/1/update-branch", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") testHeader(t, r, "Accept", mediaTypeUpdatePullRequestBranchPreview) + testJSONBody(t, r, body) fmt.Fprint(w, ` { "message": "Updating pull request branch.", @@ -413,12 +418,8 @@ func TestPullRequestsService_UpdateBranch(t *testing.T) { }`) }) - opts := &PullRequestBranchUpdateOptions{ - ExpectedHeadSHA: new("s"), - } - ctx := t.Context() - pull, _, err := client.PullRequests.UpdateBranch(ctx, "o", "r", 1, opts) + pull, _, err := client.PullRequests.UpdateBranch(ctx, "o", "r", 1, body) if err != nil { t.Errorf("PullRequests.UpdateBranch returned error: %v", err) } @@ -434,12 +435,12 @@ func TestPullRequestsService_UpdateBranch(t *testing.T) { const methodName = "UpdateBranch" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.PullRequests.UpdateBranch(ctx, "\n", "\n", -1, opts) + _, _, err = client.PullRequests.UpdateBranch(ctx, "\n", "\n", -1, body) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.PullRequests.UpdateBranch(ctx, "o", "r", 1, opts) + got, resp, err := client.PullRequests.UpdateBranch(ctx, "o", "r", 1, body) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } diff --git a/github/users_administration.go b/github/users_administration.go index 34e603ab61e..2853ba23503 100644 --- a/github/users_administration.go +++ b/github/users_administration.go @@ -42,8 +42,8 @@ func (s *UsersService) DemoteSiteAdmin(ctx context.Context, user string) (*Respo return s.client.Do(req, nil) } -// UserSuspendOptions represents the reason to suspend a user. -type UserSuspendOptions struct { +// SuspendUserRequest represents a request to suspend a user. +type SuspendUserRequest struct { Reason *string `json:"reason,omitempty"` } @@ -52,7 +52,7 @@ type UserSuspendOptions struct { // GitHub API docs: https://docs.github.com/enterprise-server@3.22/rest/enterprise-admin/users#suspend-a-user // //meta:operation PUT /users/{username}/suspended -func (s *UsersService) Suspend(ctx context.Context, user string, body *UserSuspendOptions) (*Response, error) { +func (s *UsersService) Suspend(ctx context.Context, user string, body SuspendUserRequest) (*Response, error) { u := fmt.Sprintf("users/%v/suspended", user) req, err := s.client.NewRequest(ctx, "PUT", u, body) diff --git a/github/users_administration_test.go b/github/users_administration_test.go index 563975823b8..21455b5034b 100644 --- a/github/users_administration_test.go +++ b/github/users_administration_test.go @@ -72,19 +72,19 @@ func TestUsersService_Suspend(t *testing.T) { }) ctx := t.Context() - _, err := client.Users.Suspend(ctx, "u", nil) + _, err := client.Users.Suspend(ctx, "u", SuspendUserRequest{}) if err != nil { t.Errorf("Users.Suspend returned error: %v", err) } const methodName = "Suspend" testBadOptions(t, methodName, func() (err error) { - _, err = client.Users.Suspend(ctx, "\n", nil) + _, err = client.Users.Suspend(ctx, "\n", SuspendUserRequest{}) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Users.Suspend(ctx, "u", nil) + return client.Users.Suspend(ctx, "u", SuspendUserRequest{}) }) } @@ -92,16 +92,16 @@ func TestUsersServiceReason_Suspend(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &UserSuspendOptions{Reason: new("test")} + body := SuspendUserRequest{Reason: new("test")} mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") - testJSONBody(t, r, input) + testJSONBody(t, r, body) w.WriteHeader(http.StatusNoContent) }) ctx := t.Context() - _, err := client.Users.Suspend(ctx, "u", input) + _, err := client.Users.Suspend(ctx, "u", body) if err != nil { t.Errorf("Users.Suspend returned error: %v", err) }