Skip to content
Merged
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
7 changes: 0 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,11 @@ linters:
- InstallationTokenListRepoOptions
- InstallationTokenOptions
- IssueImportRequest
- LockIssueOptions
- MaintenanceOptions
- Organization
- PagesUpdate
- PagesUpdateWithoutCNAME
- ProtectionRequest
- PullRequestBranchUpdateOptions
- PullRequestReviewRequest
- PullRequestReviewsEnforcementUpdate
- Repository
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -404,7 +398,6 @@ linters:
- ListSCIMProvisionedIdentitiesOptions.Filter
- ListSCIMProvisionedIdentitiesOptions.StartIndex
- ListUserIssuesOptions.Since
- LockIssueOptions.LockReason # TODO: Issues
- MarketplacePlan.Bullets # TODO: Marketplaces
- NodeQueryOptions.ClusterRoles
- NodeQueryOptions.UUID
Expand Down
40 changes: 20 additions & 20 deletions github/github-accessors.go

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

51 changes: 27 additions & 24 deletions github/github-accessors_test.go

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

9 changes: 4 additions & 5 deletions github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,21 +543,20 @@ 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.
//
// 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 {
Expand Down
13 changes: 7 additions & 6 deletions github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,34 +483,35 @@ 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{})
})
}

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)
}
}
Expand Down
7 changes: 3 additions & 4 deletions github/pulls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions github/pulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,22 +403,23 @@ 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.",
"url": "https://github.com/repos/o/r/pulls/1"
}`)
})

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)
}
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions github/users_administration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -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)
Expand Down
Loading
Loading