Skip to content

Commit e754d2c

Browse files
refactor!: Pass the Projects v2 item body types by value and rename them to ...Request (#4609)
BREAKING CHANGE: `AddProjectItemOptions` and `UpdateProjectItemOptions` are renamed to `AddProjectItemRequest` and `UpdateProjectItemRequest` and passed by value; `AddProjectItemRequest.Type` is no longer a pointer; `UpdateProjectItemOptions.Archived` is removed.
1 parent 40091e2 commit e754d2c

5 files changed

Lines changed: 136 additions & 80 deletions

File tree

‎.golangci.yml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ linters:
202202
# Body type names exempt from the "pass by value, not by pointer" rule.
203203
# TODO: fix and remove these exceptions.
204204
body-allowed-pointer-types:
205-
- AddProjectItemOptions
206205
- AuthorizationRequest
207206
- CodeScanningAlertState
208207
- ConfigApplyOptions
@@ -236,13 +235,11 @@ linters:
236235
- SourceImportAuthor
237236
- Subscription
238237
- UpdateDefaultSetupConfigurationOptions
239-
- UpdateProjectItemOptions
240238
- UserSuspendOptions
241239
- WorkflowsPermissionsOpt
242240
# Body type names exempt from the "Options" suffix rule.
243241
# TODO: fix and remove these exceptions.
244242
body-allowed-wrong-names:
245-
- AddProjectItemOptions
246243
- CheckSuitePreferenceOptions
247244
- ConfigApplyOptions
248245
- CreateCheckRunOptions
@@ -256,7 +253,6 @@ linters:
256253
- RepositoryContentFileOptions
257254
- UpdateCheckRunOptions
258255
- UpdateDefaultSetupConfigurationOptions
259-
- UpdateProjectItemOptions
260256
- UserSuspendOptions
261257
sliceofpointers:
262258
type: module

‎github/github-accessors.go‎

Lines changed: 28 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎github/github-accessors_test.go‎

Lines changed: 41 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎github/projects.go‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,16 @@ type GetProjectItemOptions struct {
477477
Fields []int64 `url:"fields,omitempty,comma"`
478478
}
479479

480-
// AddProjectItemOptions represents the payload to add an item (issue or pull request)
481-
// to a project. The Type must be either "Issue" or "PullRequest" (as per API docs) and
482-
// ID is the numerical ID of that issue or pull request.
483-
type AddProjectItemOptions struct {
484-
Type *ProjectV2ItemContentType `json:"type,omitempty"`
485-
ID *int64 `json:"id,omitempty"`
480+
// AddProjectItemRequest represents the payload to add an item (issue or pull request)
481+
// to a project. The Type must be either "Issue" or "PullRequest" (as per API docs).
482+
// The item is identified either by ID, the numerical ID of that issue or pull request,
483+
// or by Owner, Repo, and Number.
484+
type AddProjectItemRequest struct {
485+
Type ProjectV2ItemContentType `json:"type"`
486+
ID *int64 `json:"id,omitempty"`
487+
Owner *string `json:"owner,omitempty"`
488+
Repo *string `json:"repo,omitempty"`
489+
Number *int `json:"number,omitempty"`
486490
}
487491

488492
// UpdateProjectV2Field represents a field update for a project item.
@@ -501,15 +505,11 @@ type UpdateProjectV2Field struct {
501505
Value any `json:"value"`
502506
}
503507

504-
// UpdateProjectItemOptions represents fields that can be modified for a project item.
505-
// The GitHub API expects either archived status updates or field value updates.
506-
type UpdateProjectItemOptions struct {
507-
// Archived indicates whether the item should be archived (true) or unarchived (false).
508-
// This is used for archive/unarchive operations.
509-
Archived *bool `json:"archived,omitempty"`
508+
// UpdateProjectItemRequest represents fields that can be modified for a project item.
509+
type UpdateProjectItemRequest struct {
510510
// Fields contains field updates to apply to the project item.
511511
// Each entry specifies a field ID and its new value.
512-
Fields []*UpdateProjectV2Field `json:"fields,omitempty"`
512+
Fields []*UpdateProjectV2Field `json:"fields"`
513513
}
514514

515515
// ListOrganizationProjectItems lists items for an organization owned project.
@@ -543,7 +543,7 @@ func (s *ProjectsService) ListOrganizationProjectItems(ctx context.Context, org
543543
// GitHub API docs: https://docs.github.com/rest/projects/items?apiVersion=2022-11-28#add-item-to-organization-owned-project
544544
//
545545
//meta:operation POST /orgs/{org}/projectsV2/{project_number}/items
546-
func (s *ProjectsService) AddOrganizationProjectItem(ctx context.Context, org string, projectNumber int, body *AddProjectItemOptions) (*ProjectV2Item, *Response, error) {
546+
func (s *ProjectsService) AddOrganizationProjectItem(ctx context.Context, org string, projectNumber int, body AddProjectItemRequest) (*ProjectV2Item, *Response, error) {
547547
u := fmt.Sprintf("orgs/%v/projectsV2/%v/items", org, projectNumber)
548548
req, err := s.client.NewRequest(ctx, "POST", u, body)
549549
if err != nil {
@@ -590,7 +590,7 @@ func (s *ProjectsService) GetOrganizationProjectItem(ctx context.Context, org st
590590
// GitHub API docs: https://docs.github.com/rest/projects/items?apiVersion=2022-11-28#update-project-item-for-organization
591591
//
592592
//meta:operation PATCH /orgs/{org}/projectsV2/{project_number}/items/{item_id}
593-
func (s *ProjectsService) UpdateOrganizationProjectItem(ctx context.Context, org string, projectNumber int, itemID int64, body *UpdateProjectItemOptions) (*ProjectV2Item, *Response, error) {
593+
func (s *ProjectsService) UpdateOrganizationProjectItem(ctx context.Context, org string, projectNumber int, itemID int64, body UpdateProjectItemRequest) (*ProjectV2Item, *Response, error) {
594594
u := fmt.Sprintf("orgs/%v/projectsV2/%v/items/%v", org, projectNumber, itemID)
595595
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
596596
if err != nil {
@@ -652,7 +652,7 @@ func (s *ProjectsService) ListUserProjectItems(ctx context.Context, username str
652652
// GitHub API docs: https://docs.github.com/rest/projects/items?apiVersion=2022-11-28#add-item-to-user-owned-project
653653
//
654654
//meta:operation POST /users/{username}/projectsV2/{project_number}/items
655-
func (s *ProjectsService) AddUserProjectItem(ctx context.Context, username string, projectNumber int, body *AddProjectItemOptions) (*ProjectV2Item, *Response, error) {
655+
func (s *ProjectsService) AddUserProjectItem(ctx context.Context, username string, projectNumber int, body AddProjectItemRequest) (*ProjectV2Item, *Response, error) {
656656
u := fmt.Sprintf("users/%v/projectsV2/%v/items", username, projectNumber)
657657
req, err := s.client.NewRequest(ctx, "POST", u, body)
658658
if err != nil {
@@ -699,7 +699,7 @@ func (s *ProjectsService) GetUserProjectItem(ctx context.Context, username strin
699699
// GitHub API docs: https://docs.github.com/rest/projects/items?apiVersion=2022-11-28#update-project-item-for-user
700700
//
701701
//meta:operation PATCH /users/{username}/projectsV2/{project_number}/items/{item_id}
702-
func (s *ProjectsService) UpdateUserProjectItem(ctx context.Context, username string, projectNumber int, itemID int64, body *UpdateProjectItemOptions) (*ProjectV2Item, *Response, error) {
702+
func (s *ProjectsService) UpdateUserProjectItem(ctx context.Context, username string, projectNumber int, itemID int64, body UpdateProjectItemRequest) (*ProjectV2Item, *Response, error) {
703703
u := fmt.Sprintf("users/%v/projectsV2/%v/items/%v", username, projectNumber, itemID)
704704
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
705705
if err != nil {

0 commit comments

Comments
 (0)