From 2a65d2f2a5d8734d3062b798b4ac7936d990d1eb Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Tue, 23 Jun 2026 00:30:31 +0000 Subject: [PATCH 1/4] refactor!: Pass GistsService required params by value BREAKING CHANGE: GistsService.Create / Update / CreateComment / UpdateComment now take dedicated request structs by value (CreateGistRequest, UpdateGistRequest, CreateGistCommentRequest, UpdateGistCommentRequest) instead of *Gist / *GistComment. Edit is renamed to Update and EditComment is renamed to UpdateComment. This completes the stalled PR #3680, applying the maintainer-agreed review feedback that was never addressed: drop the deprecated wrappers entirely and rename Edit/EditComment to Update/UpdateComment for API consistency. The now-obsolete Gist and GistComment entries are removed from the paramcheck body-allowed-pointer-types allow-list in .golangci.yml. Relates to #3644. --- .golangci.yml | 2 - github/gists.go | 19 ++++++-- github/gists_comments.go | 16 +++++-- github/gists_comments_test.go | 24 +++++----- github/gists_test.go | 22 +++++----- github/github-accessors.go | 56 ++++++++++++++++++++++++ github/github-accessors_test.go | 77 +++++++++++++++++++++++++++++++++ 7 files changed, 185 insertions(+), 31 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9a7fd32877b..2224d1c1ab6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -230,8 +230,6 @@ linters: - ExternalGroup - GenerateJITConfigRequest - GenerateNotesOptions - - Gist - - GistComment - Hook - HookConfig - ImpersonateUserOptions diff --git a/github/gists.go b/github/gists.go index bd8553f9745..7b08ab9c09d 100644 --- a/github/gists.go +++ b/github/gists.go @@ -37,6 +37,19 @@ func (g Gist) String() string { return Stringify(g) } +// CreateGistRequest represents the input for creating a gist. +type CreateGistRequest struct { + Description *string `json:"description,omitempty"` + Public *bool `json:"public,omitempty"` + Files map[GistFilename]GistFile `json:"files,omitempty"` +} + +// UpdateGistRequest represents the input for updating a gist. +type UpdateGistRequest struct { + Description *string `json:"description,omitempty"` + Files map[GistFilename]GistFile `json:"files,omitempty"` +} + // GistFilename represents filename on a gist. type GistFilename string @@ -225,7 +238,7 @@ func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist, // GitHub API docs: https://docs.github.com/rest/gists/gists?apiVersion=2022-11-28#create-a-gist // //meta:operation POST /gists -func (s *GistsService) Create(ctx context.Context, body *Gist) (*Gist, *Response, error) { +func (s *GistsService) Create(ctx context.Context, body CreateGistRequest) (*Gist, *Response, error) { u := "gists" req, err := s.client.NewRequest(ctx, "POST", u, body) if err != nil { @@ -241,12 +254,12 @@ func (s *GistsService) Create(ctx context.Context, body *Gist) (*Gist, *Response return g, resp, nil } -// Edit a gist. +// Update a gist. // // GitHub API docs: https://docs.github.com/rest/gists/gists?apiVersion=2022-11-28#update-a-gist // //meta:operation PATCH /gists/{gist_id} -func (s *GistsService) Edit(ctx context.Context, id string, body *Gist) (*Gist, *Response, error) { +func (s *GistsService) Update(ctx context.Context, id string, body UpdateGistRequest) (*Gist, *Response, error) { u := fmt.Sprintf("gists/%v", id) req, err := s.client.NewRequest(ctx, "PATCH", u, body) if err != nil { diff --git a/github/gists_comments.go b/github/gists_comments.go index 27f0fa1d7a3..b53e5dedd91 100644 --- a/github/gists_comments.go +++ b/github/gists_comments.go @@ -23,6 +23,16 @@ func (g GistComment) String() string { return Stringify(g) } +// CreateGistCommentRequest represents the input for creating a gist comment. +type CreateGistCommentRequest struct { + Body *string `json:"body,omitempty"` +} + +// UpdateGistCommentRequest represents the input for updating a gist comment. +type UpdateGistCommentRequest struct { + Body *string `json:"body,omitempty"` +} + // ListComments lists all comments for a gist. // // GitHub API docs: https://docs.github.com/rest/gists/comments?apiVersion=2022-11-28#list-gist-comments @@ -75,7 +85,7 @@ func (s *GistsService) GetComment(ctx context.Context, gistID string, commentID // GitHub API docs: https://docs.github.com/rest/gists/comments?apiVersion=2022-11-28#create-a-gist-comment // //meta:operation POST /gists/{gist_id}/comments -func (s *GistsService) CreateComment(ctx context.Context, gistID string, body *GistComment) (*GistComment, *Response, error) { +func (s *GistsService) CreateComment(ctx context.Context, gistID string, body CreateGistCommentRequest) (*GistComment, *Response, error) { u := fmt.Sprintf("gists/%v/comments", gistID) req, err := s.client.NewRequest(ctx, "POST", u, body) if err != nil { @@ -91,12 +101,12 @@ func (s *GistsService) CreateComment(ctx context.Context, gistID string, body *G return c, resp, nil } -// EditComment edits an existing gist comment. +// UpdateComment updates an existing gist comment. // // GitHub API docs: https://docs.github.com/rest/gists/comments?apiVersion=2022-11-28#update-a-gist-comment // //meta:operation PATCH /gists/{gist_id}/comments/{comment_id} -func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID int64, body *GistComment) (*GistComment, *Response, error) { +func (s *GistsService) UpdateComment(ctx context.Context, gistID string, commentID int64, body UpdateGistCommentRequest) (*GistComment, *Response, error) { u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID) req, err := s.client.NewRequest(ctx, "PATCH", u, body) if err != nil { diff --git a/github/gists_comments_test.go b/github/gists_comments_test.go index 9db219e64fb..82cea996331 100644 --- a/github/gists_comments_test.go +++ b/github/gists_comments_test.go @@ -107,7 +107,7 @@ func TestGistsService_CreateComment(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &GistComment{ID: Ptr(int64(1)), Body: Ptr("b")} + input := CreateGistCommentRequest{Body: Ptr("b")} mux.HandleFunc("/gists/1/comments", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") @@ -146,15 +146,15 @@ func TestGistsService_CreateComment_invalidID(t *testing.T) { client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.Gists.CreateComment(ctx, "%", nil) + _, _, err := client.Gists.CreateComment(ctx, "%", CreateGistCommentRequest{}) testURLParseError(t, err) } -func TestGistsService_EditComment(t *testing.T) { +func TestGistsService_UpdateComment(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &GistComment{ID: Ptr(int64(1)), Body: Ptr("b")} + input := UpdateGistCommentRequest{Body: Ptr("b")} mux.HandleFunc("/gists/1/comments/2", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") @@ -163,24 +163,24 @@ func TestGistsService_EditComment(t *testing.T) { }) ctx := t.Context() - comment, _, err := client.Gists.EditComment(ctx, "1", 2, input) + comment, _, err := client.Gists.UpdateComment(ctx, "1", 2, input) if err != nil { - t.Errorf("Gists.EditComment returned error: %v", err) + t.Errorf("Gists.UpdateComment returned error: %v", err) } want := &GistComment{ID: Ptr(int64(1))} if !cmp.Equal(comment, want) { - t.Errorf("Gists.EditComment returned %+v, want %+v", comment, want) + t.Errorf("Gists.UpdateComment returned %+v, want %+v", comment, want) } - const methodName = "EditComment" + const methodName = "UpdateComment" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Gists.EditComment(ctx, "\n", -2, input) + _, _, err = client.Gists.UpdateComment(ctx, "\n", -2, input) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Gists.EditComment(ctx, "1", 2, input) + got, resp, err := client.Gists.UpdateComment(ctx, "1", 2, input) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -188,12 +188,12 @@ func TestGistsService_EditComment(t *testing.T) { }) } -func TestGistsService_EditComment_invalidID(t *testing.T) { +func TestGistsService_UpdateComment_invalidID(t *testing.T) { t.Parallel() client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.Gists.EditComment(ctx, "%", 1, nil) + _, _, err := client.Gists.UpdateComment(ctx, "%", 1, UpdateGistCommentRequest{}) testURLParseError(t, err) } diff --git a/github/gists_test.go b/github/gists_test.go index 39928c0d2bc..e59bc72e854 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -263,7 +263,7 @@ func TestGistsService_Create(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &Gist{ + input := CreateGistRequest{ Description: Ptr("Gist description"), Public: Ptr(false), Files: map[GistFilename]GistFile{ @@ -317,11 +317,11 @@ func TestGistsService_Create(t *testing.T) { }) } -func TestGistsService_Edit(t *testing.T) { +func TestGistsService_Update(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &Gist{ + input := UpdateGistRequest{ Description: Ptr("New description"), Files: map[GistFilename]GistFile{ "new.txt": {Content: Ptr("new file content")}, @@ -350,9 +350,9 @@ func TestGistsService_Edit(t *testing.T) { }) ctx := t.Context() - gist, _, err := client.Gists.Edit(ctx, "1", input) + gist, _, err := client.Gists.Update(ctx, "1", input) if err != nil { - t.Errorf("Gists.Edit returned error: %v", err) + t.Errorf("Gists.Update returned error: %v", err) } want := &Gist{ @@ -365,17 +365,17 @@ func TestGistsService_Edit(t *testing.T) { }, } if !cmp.Equal(gist, want) { - t.Errorf("Gists.Edit returned %+v, want %+v", gist, want) + t.Errorf("Gists.Update returned %+v, want %+v", gist, want) } - const methodName = "Edit" + const methodName = "Update" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Gists.Edit(ctx, "\n", input) + _, _, err = client.Gists.Update(ctx, "\n", input) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Gists.Edit(ctx, "1", input) + got, resp, err := client.Gists.Update(ctx, "1", input) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -383,12 +383,12 @@ func TestGistsService_Edit(t *testing.T) { }) } -func TestGistsService_Edit_invalidID(t *testing.T) { +func TestGistsService_Update_invalidID(t *testing.T) { t.Parallel() client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.Gists.Edit(ctx, "%", nil) + _, _, err := client.Gists.Update(ctx, "%", UpdateGistRequest{}) testURLParseError(t, err) } diff --git a/github/github-accessors.go b/github/github-accessors.go index 0a6cc1e6b53..ef4e9fb0429 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10766,6 +10766,38 @@ func (c *CreateEvent) GetSender() *User { return c.Sender } +// GetBody returns the Body field if it's non-nil, zero value otherwise. +func (c *CreateGistCommentRequest) GetBody() string { + if c == nil || c.Body == nil { + return "" + } + return *c.Body +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (c *CreateGistRequest) GetDescription() string { + if c == nil || c.Description == nil { + return "" + } + return *c.Description +} + +// GetFiles returns the Files map if it's non-nil, an empty map otherwise. +func (c *CreateGistRequest) GetFiles() map[GistFilename]GistFile { + if c == nil || c.Files == nil { + return map[GistFilename]GistFile{} + } + return c.Files +} + +// GetPublic returns the Public field if it's non-nil, zero value otherwise. +func (c *CreateGistRequest) GetPublic() bool { + if c == nil || c.Public == nil { + return false + } + return *c.Public +} + // GetEnableStaticIP returns the EnableStaticIP field if it's non-nil, zero value otherwise. func (c *CreateHostedRunnerRequest) GetEnableStaticIP() bool { if c == nil || c.EnableStaticIP == nil { @@ -41870,6 +41902,30 @@ func (u *UpdateEnterpriseRunnerGroupRequest) GetVisibility() string { return *u.Visibility } +// GetBody returns the Body field if it's non-nil, zero value otherwise. +func (u *UpdateGistCommentRequest) GetBody() string { + if u == nil || u.Body == nil { + return "" + } + return *u.Body +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (u *UpdateGistRequest) GetDescription() string { + if u == nil || u.Description == nil { + return "" + } + return *u.Description +} + +// GetFiles returns the Files map if it's non-nil, an empty map otherwise. +func (u *UpdateGistRequest) GetFiles() map[GistFilename]GistFile { + if u == nil || u.Files == nil { + return map[GistFilename]GistFile{} + } + return u.Files +} + // GetEnableStaticIP returns the EnableStaticIP field if it's non-nil, zero value otherwise. func (u *UpdateHostedRunnerRequest) GetEnableStaticIP() bool { if u == nil || u.EnableStaticIP == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 7433e4499e8..9a2e759308e 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -13689,6 +13689,50 @@ func TestCreateEvent_GetSender(tt *testing.T) { c.GetSender() } +func TestCreateGistCommentRequest_GetBody(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateGistCommentRequest{Body: &zeroValue} + c.GetBody() + c = &CreateGistCommentRequest{} + c.GetBody() + c = nil + c.GetBody() +} + +func TestCreateGistRequest_GetDescription(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateGistRequest{Description: &zeroValue} + c.GetDescription() + c = &CreateGistRequest{} + c.GetDescription() + c = nil + c.GetDescription() +} + +func TestCreateGistRequest_GetFiles(tt *testing.T) { + tt.Parallel() + zeroValue := map[GistFilename]GistFile{} + c := &CreateGistRequest{Files: zeroValue} + c.GetFiles() + c = &CreateGistRequest{} + c.GetFiles() + c = nil + c.GetFiles() +} + +func TestCreateGistRequest_GetPublic(tt *testing.T) { + tt.Parallel() + var zeroValue bool + c := &CreateGistRequest{Public: &zeroValue} + c.GetPublic() + c = &CreateGistRequest{} + c.GetPublic() + c = nil + c.GetPublic() +} + func TestCreateHostedRunnerRequest_GetEnableStaticIP(tt *testing.T) { tt.Parallel() var zeroValue bool @@ -52563,6 +52607,39 @@ func TestUpdateEnterpriseRunnerGroupRequest_GetVisibility(tt *testing.T) { u.GetVisibility() } +func TestUpdateGistCommentRequest_GetBody(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateGistCommentRequest{Body: &zeroValue} + u.GetBody() + u = &UpdateGistCommentRequest{} + u.GetBody() + u = nil + u.GetBody() +} + +func TestUpdateGistRequest_GetDescription(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateGistRequest{Description: &zeroValue} + u.GetDescription() + u = &UpdateGistRequest{} + u.GetDescription() + u = nil + u.GetDescription() +} + +func TestUpdateGistRequest_GetFiles(tt *testing.T) { + tt.Parallel() + zeroValue := map[GistFilename]GistFile{} + u := &UpdateGistRequest{Files: zeroValue} + u.GetFiles() + u = &UpdateGistRequest{} + u.GetFiles() + u = nil + u.GetFiles() +} + func TestUpdateHostedRunnerRequest_GetEnableStaticIP(tt *testing.T) { tt.Parallel() var zeroValue bool From b85f702179db49eb859221dd4f9f273962bb6240 Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Tue, 23 Jun 2026 20:04:52 +0900 Subject: [PATCH 2/4] refactor: Use GistFileRequest for gist file inputs Per review, the gist create/update request files map should not reuse the GistFile response type (which carries read-only fields like size, raw_url, type and language). Introduce GistFileRequest{Content, Filename} for the request file value, mark CreateGistRequest.Files required (drop omitempty), and add field doc comments. The OpenAPI schema confirms the create file value is {content} (content required) and the update file value is {content, filename}. --- github/gists.go | 21 ++++++++++++++++----- github/gists_test.go | 4 ++-- github/github-accessors.go | 24 ++++++++++++++++++++---- github/github-accessors_test.go | 26 ++++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 13 deletions(-) diff --git a/github/gists.go b/github/gists.go index 7b08ab9c09d..8a1dd6f603e 100644 --- a/github/gists.go +++ b/github/gists.go @@ -39,15 +39,17 @@ func (g Gist) String() string { // CreateGistRequest represents the input for creating a gist. type CreateGistRequest struct { - Description *string `json:"description,omitempty"` - Public *bool `json:"public,omitempty"` - Files map[GistFilename]GistFile `json:"files,omitempty"` + Description *string `json:"description,omitempty"` + Public *bool `json:"public,omitempty"` + // Files is the set of files that make up the gist, keyed by filename. (Required.) + Files map[GistFilename]GistFileRequest `json:"files"` } // UpdateGistRequest represents the input for updating a gist. type UpdateGistRequest struct { - Description *string `json:"description,omitempty"` - Files map[GistFilename]GistFile `json:"files,omitempty"` + Description *string `json:"description,omitempty"` + // Files is the set of files to add, change or rename, keyed by filename. + Files map[GistFilename]GistFileRequest `json:"files,omitempty"` } // GistFilename represents filename on a gist. @@ -67,6 +69,15 @@ func (g GistFile) String() string { return Stringify(g) } +// GistFileRequest represents a file's content within a CreateGistRequest or +// UpdateGistRequest. The gist's files are keyed by filename. +type GistFileRequest struct { + // Content is the contents of the file. (Required when creating a gist.) + Content *string `json:"content,omitempty"` + // Filename, if set, renames the file. (Used when updating a gist.) + Filename *string `json:"filename,omitempty"` +} + // GistCommit represents a commit on a gist. type GistCommit struct { URL *string `json:"url,omitempty"` diff --git a/github/gists_test.go b/github/gists_test.go index e59bc72e854..de384f5c9ac 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -266,7 +266,7 @@ func TestGistsService_Create(t *testing.T) { input := CreateGistRequest{ Description: Ptr("Gist description"), Public: Ptr(false), - Files: map[GistFilename]GistFile{ + Files: map[GistFilename]GistFileRequest{ "test.txt": {Content: Ptr("Gist file content")}, }, } @@ -323,7 +323,7 @@ func TestGistsService_Update(t *testing.T) { input := UpdateGistRequest{ Description: Ptr("New description"), - Files: map[GistFilename]GistFile{ + Files: map[GistFilename]GistFileRequest{ "new.txt": {Content: Ptr("new file content")}, }, } diff --git a/github/github-accessors.go b/github/github-accessors.go index ef4e9fb0429..81a0f6c0bac 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10783,9 +10783,9 @@ func (c *CreateGistRequest) GetDescription() string { } // GetFiles returns the Files map if it's non-nil, an empty map otherwise. -func (c *CreateGistRequest) GetFiles() map[GistFilename]GistFile { +func (c *CreateGistRequest) GetFiles() map[GistFilename]GistFileRequest { if c == nil || c.Files == nil { - return map[GistFilename]GistFile{} + return map[GistFilename]GistFileRequest{} } return c.Files } @@ -16782,6 +16782,22 @@ func (g *GistFile) GetType() string { return *g.Type } +// GetContent returns the Content field if it's non-nil, zero value otherwise. +func (g *GistFileRequest) GetContent() string { + if g == nil || g.Content == nil { + return "" + } + return *g.Content +} + +// GetFilename returns the Filename field if it's non-nil, zero value otherwise. +func (g *GistFileRequest) GetFilename() string { + if g == nil || g.Filename == nil { + return "" + } + return *g.Filename +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (g *GistFork) GetCreatedAt() Timestamp { if g == nil || g.CreatedAt == nil { @@ -41919,9 +41935,9 @@ func (u *UpdateGistRequest) GetDescription() string { } // GetFiles returns the Files map if it's non-nil, an empty map otherwise. -func (u *UpdateGistRequest) GetFiles() map[GistFilename]GistFile { +func (u *UpdateGistRequest) GetFiles() map[GistFilename]GistFileRequest { if u == nil || u.Files == nil { - return map[GistFilename]GistFile{} + return map[GistFilename]GistFileRequest{} } return u.Files } diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 9a2e759308e..03eecc0818b 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -13713,7 +13713,7 @@ func TestCreateGistRequest_GetDescription(tt *testing.T) { func TestCreateGistRequest_GetFiles(tt *testing.T) { tt.Parallel() - zeroValue := map[GistFilename]GistFile{} + zeroValue := map[GistFilename]GistFileRequest{} c := &CreateGistRequest{Files: zeroValue} c.GetFiles() c = &CreateGistRequest{} @@ -21136,6 +21136,28 @@ func TestGistFile_GetType(tt *testing.T) { g.GetType() } +func TestGistFileRequest_GetContent(tt *testing.T) { + tt.Parallel() + var zeroValue string + g := &GistFileRequest{Content: &zeroValue} + g.GetContent() + g = &GistFileRequest{} + g.GetContent() + g = nil + g.GetContent() +} + +func TestGistFileRequest_GetFilename(tt *testing.T) { + tt.Parallel() + var zeroValue string + g := &GistFileRequest{Filename: &zeroValue} + g.GetFilename() + g = &GistFileRequest{} + g.GetFilename() + g = nil + g.GetFilename() +} + func TestGistFork_GetCreatedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp @@ -52631,7 +52653,7 @@ func TestUpdateGistRequest_GetDescription(tt *testing.T) { func TestUpdateGistRequest_GetFiles(tt *testing.T) { tt.Parallel() - zeroValue := map[GistFilename]GistFile{} + zeroValue := map[GistFilename]GistFileRequest{} u := &UpdateGistRequest{Files: zeroValue} u.GetFiles() u = &UpdateGistRequest{} From a332585a8c6075ef33bacc7badd5189e48ce1b7a Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Tue, 23 Jun 2026 20:52:16 +0900 Subject: [PATCH 3/4] refactor: Split create/update gist file structs Per review, use separate CreateGistFile and UpdateGistFile structs for the request files (matching the distinct create/update schemas), and key the Files maps to pointers (map[GistFilename]*...), matching the repo's preference for pointers to structs. A nil value in an UpdateGistRequest's Files map deletes that file from the gist, which is now documented and covered by a test. --- github/gists.go | 23 +++++++--- github/gists_test.go | 6 ++- github/github-accessors.go | 56 ++++++++++-------------- github/github-accessors_test.go | 77 ++++++++++++++------------------- 4 files changed, 77 insertions(+), 85 deletions(-) diff --git a/github/gists.go b/github/gists.go index 8a1dd6f603e..e154f810a91 100644 --- a/github/gists.go +++ b/github/gists.go @@ -42,14 +42,15 @@ type CreateGistRequest struct { Description *string `json:"description,omitempty"` Public *bool `json:"public,omitempty"` // Files is the set of files that make up the gist, keyed by filename. (Required.) - Files map[GistFilename]GistFileRequest `json:"files"` + Files map[GistFilename]*CreateGistFile `json:"files"` } // UpdateGistRequest represents the input for updating a gist. type UpdateGistRequest struct { Description *string `json:"description,omitempty"` // Files is the set of files to add, change or rename, keyed by filename. - Files map[GistFilename]GistFileRequest `json:"files,omitempty"` + // Mapping a filename to a nil value deletes that file from the gist. + Files map[GistFilename]*UpdateGistFile `json:"files,omitempty"` } // GistFilename represents filename on a gist. @@ -69,12 +70,20 @@ func (g GistFile) String() string { return Stringify(g) } -// GistFileRequest represents a file's content within a CreateGistRequest or -// UpdateGistRequest. The gist's files are keyed by filename. -type GistFileRequest struct { - // Content is the contents of the file. (Required when creating a gist.) +// CreateGistFile represents a file within a CreateGistRequest, keyed by filename +// in the request's Files map. +type CreateGistFile struct { + // Content is the contents of the file. (Required.) Content *string `json:"content,omitempty"` - // Filename, if set, renames the file. (Used when updating a gist.) +} + +// UpdateGistFile represents a file within an UpdateGistRequest, keyed by filename +// in the request's Files map. Mapping a filename to a nil *UpdateGistFile deletes +// that file from the gist. +type UpdateGistFile struct { + // Content is the new contents of the file. + Content *string `json:"content,omitempty"` + // Filename, if set, renames the file. Filename *string `json:"filename,omitempty"` } diff --git a/github/gists_test.go b/github/gists_test.go index de384f5c9ac..1426c652f8d 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -266,7 +266,7 @@ func TestGistsService_Create(t *testing.T) { input := CreateGistRequest{ Description: Ptr("Gist description"), Public: Ptr(false), - Files: map[GistFilename]GistFileRequest{ + Files: map[GistFilename]*CreateGistFile{ "test.txt": {Content: Ptr("Gist file content")}, }, } @@ -323,8 +323,10 @@ func TestGistsService_Update(t *testing.T) { input := UpdateGistRequest{ Description: Ptr("New description"), - Files: map[GistFilename]GistFileRequest{ + Files: map[GistFilename]*UpdateGistFile{ "new.txt": {Content: Ptr("new file content")}, + // A nil value deletes the file from the gist. + "old.txt": nil, }, } diff --git a/github/github-accessors.go b/github/github-accessors.go index 81a0f6c0bac..3f27ac51662 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10774,6 +10774,14 @@ func (c *CreateGistCommentRequest) GetBody() string { return *c.Body } +// GetContent returns the Content field if it's non-nil, zero value otherwise. +func (c *CreateGistFile) GetContent() string { + if c == nil || c.Content == nil { + return "" + } + return *c.Content +} + // GetDescription returns the Description field if it's non-nil, zero value otherwise. func (c *CreateGistRequest) GetDescription() string { if c == nil || c.Description == nil { @@ -10782,14 +10790,6 @@ func (c *CreateGistRequest) GetDescription() string { return *c.Description } -// GetFiles returns the Files map if it's non-nil, an empty map otherwise. -func (c *CreateGistRequest) GetFiles() map[GistFilename]GistFileRequest { - if c == nil || c.Files == nil { - return map[GistFilename]GistFileRequest{} - } - return c.Files -} - // GetPublic returns the Public field if it's non-nil, zero value otherwise. func (c *CreateGistRequest) GetPublic() bool { if c == nil || c.Public == nil { @@ -16782,22 +16782,6 @@ func (g *GistFile) GetType() string { return *g.Type } -// GetContent returns the Content field if it's non-nil, zero value otherwise. -func (g *GistFileRequest) GetContent() string { - if g == nil || g.Content == nil { - return "" - } - return *g.Content -} - -// GetFilename returns the Filename field if it's non-nil, zero value otherwise. -func (g *GistFileRequest) GetFilename() string { - if g == nil || g.Filename == nil { - return "" - } - return *g.Filename -} - // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (g *GistFork) GetCreatedAt() Timestamp { if g == nil || g.CreatedAt == nil { @@ -41926,6 +41910,22 @@ func (u *UpdateGistCommentRequest) GetBody() string { return *u.Body } +// GetContent returns the Content field if it's non-nil, zero value otherwise. +func (u *UpdateGistFile) GetContent() string { + if u == nil || u.Content == nil { + return "" + } + return *u.Content +} + +// GetFilename returns the Filename field if it's non-nil, zero value otherwise. +func (u *UpdateGistFile) GetFilename() string { + if u == nil || u.Filename == nil { + return "" + } + return *u.Filename +} + // GetDescription returns the Description field if it's non-nil, zero value otherwise. func (u *UpdateGistRequest) GetDescription() string { if u == nil || u.Description == nil { @@ -41934,14 +41934,6 @@ func (u *UpdateGistRequest) GetDescription() string { return *u.Description } -// GetFiles returns the Files map if it's non-nil, an empty map otherwise. -func (u *UpdateGistRequest) GetFiles() map[GistFilename]GistFileRequest { - if u == nil || u.Files == nil { - return map[GistFilename]GistFileRequest{} - } - return u.Files -} - // GetEnableStaticIP returns the EnableStaticIP field if it's non-nil, zero value otherwise. func (u *UpdateHostedRunnerRequest) GetEnableStaticIP() bool { if u == nil || u.EnableStaticIP == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 03eecc0818b..1d077f8b1bf 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -13700,6 +13700,17 @@ func TestCreateGistCommentRequest_GetBody(tt *testing.T) { c.GetBody() } +func TestCreateGistFile_GetContent(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateGistFile{Content: &zeroValue} + c.GetContent() + c = &CreateGistFile{} + c.GetContent() + c = nil + c.GetContent() +} + func TestCreateGistRequest_GetDescription(tt *testing.T) { tt.Parallel() var zeroValue string @@ -13711,17 +13722,6 @@ func TestCreateGistRequest_GetDescription(tt *testing.T) { c.GetDescription() } -func TestCreateGistRequest_GetFiles(tt *testing.T) { - tt.Parallel() - zeroValue := map[GistFilename]GistFileRequest{} - c := &CreateGistRequest{Files: zeroValue} - c.GetFiles() - c = &CreateGistRequest{} - c.GetFiles() - c = nil - c.GetFiles() -} - func TestCreateGistRequest_GetPublic(tt *testing.T) { tt.Parallel() var zeroValue bool @@ -21136,28 +21136,6 @@ func TestGistFile_GetType(tt *testing.T) { g.GetType() } -func TestGistFileRequest_GetContent(tt *testing.T) { - tt.Parallel() - var zeroValue string - g := &GistFileRequest{Content: &zeroValue} - g.GetContent() - g = &GistFileRequest{} - g.GetContent() - g = nil - g.GetContent() -} - -func TestGistFileRequest_GetFilename(tt *testing.T) { - tt.Parallel() - var zeroValue string - g := &GistFileRequest{Filename: &zeroValue} - g.GetFilename() - g = &GistFileRequest{} - g.GetFilename() - g = nil - g.GetFilename() -} - func TestGistFork_GetCreatedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp @@ -52640,6 +52618,28 @@ func TestUpdateGistCommentRequest_GetBody(tt *testing.T) { u.GetBody() } +func TestUpdateGistFile_GetContent(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateGistFile{Content: &zeroValue} + u.GetContent() + u = &UpdateGistFile{} + u.GetContent() + u = nil + u.GetContent() +} + +func TestUpdateGistFile_GetFilename(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateGistFile{Filename: &zeroValue} + u.GetFilename() + u = &UpdateGistFile{} + u.GetFilename() + u = nil + u.GetFilename() +} + func TestUpdateGistRequest_GetDescription(tt *testing.T) { tt.Parallel() var zeroValue string @@ -52651,17 +52651,6 @@ func TestUpdateGistRequest_GetDescription(tt *testing.T) { u.GetDescription() } -func TestUpdateGistRequest_GetFiles(tt *testing.T) { - tt.Parallel() - zeroValue := map[GistFilename]GistFileRequest{} - u := &UpdateGistRequest{Files: zeroValue} - u.GetFiles() - u = &UpdateGistRequest{} - u.GetFiles() - u = nil - u.GetFiles() -} - func TestUpdateHostedRunnerRequest_GetEnableStaticIP(tt *testing.T) { tt.Parallel() var zeroValue bool From f632d4b29a824b99202e94a6426dfbb4f577d266 Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Wed, 24 Jun 2026 00:19:19 +0000 Subject: [PATCH 4/4] refactor: Use value types for required gist request fields Per review, the required scalar fields on the gist request structs should be passed by value rather than by pointer: CreateGistFile.Content and the Body fields on CreateGistCommentRequest / UpdateGistCommentRequest are now string with json:"..." (no omitempty). Drop the redundant "(Required.)" doc notes now that the types convey it, and regenerate the accessors. --- github/gists.go | 6 +++--- github/gists_comments.go | 6 ++++-- github/gists_comments_test.go | 4 ++-- github/gists_test.go | 2 +- github/github-accessors.go | 18 +++++++++--------- github/github-accessors_test.go | 15 +++------------ 6 files changed, 22 insertions(+), 29 deletions(-) diff --git a/github/gists.go b/github/gists.go index e154f810a91..a339286c062 100644 --- a/github/gists.go +++ b/github/gists.go @@ -41,7 +41,7 @@ func (g Gist) String() string { type CreateGistRequest struct { Description *string `json:"description,omitempty"` Public *bool `json:"public,omitempty"` - // Files is the set of files that make up the gist, keyed by filename. (Required.) + // Files is the set of files that make up the gist, keyed by filename. Files map[GistFilename]*CreateGistFile `json:"files"` } @@ -73,8 +73,8 @@ func (g GistFile) String() string { // CreateGistFile represents a file within a CreateGistRequest, keyed by filename // in the request's Files map. type CreateGistFile struct { - // Content is the contents of the file. (Required.) - Content *string `json:"content,omitempty"` + // Content is the contents of the file. + Content string `json:"content"` } // UpdateGistFile represents a file within an UpdateGistRequest, keyed by filename diff --git a/github/gists_comments.go b/github/gists_comments.go index b53e5dedd91..d2e769604fa 100644 --- a/github/gists_comments.go +++ b/github/gists_comments.go @@ -25,12 +25,14 @@ func (g GistComment) String() string { // CreateGistCommentRequest represents the input for creating a gist comment. type CreateGistCommentRequest struct { - Body *string `json:"body,omitempty"` + // Body is the comment text. + Body string `json:"body"` } // UpdateGistCommentRequest represents the input for updating a gist comment. type UpdateGistCommentRequest struct { - Body *string `json:"body,omitempty"` + // Body is the comment text. + Body string `json:"body"` } // ListComments lists all comments for a gist. diff --git a/github/gists_comments_test.go b/github/gists_comments_test.go index 82cea996331..a18022cbb93 100644 --- a/github/gists_comments_test.go +++ b/github/gists_comments_test.go @@ -107,7 +107,7 @@ func TestGistsService_CreateComment(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := CreateGistCommentRequest{Body: Ptr("b")} + input := CreateGistCommentRequest{Body: "b"} mux.HandleFunc("/gists/1/comments", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") @@ -154,7 +154,7 @@ func TestGistsService_UpdateComment(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := UpdateGistCommentRequest{Body: Ptr("b")} + input := UpdateGistCommentRequest{Body: "b"} mux.HandleFunc("/gists/1/comments/2", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") diff --git a/github/gists_test.go b/github/gists_test.go index 1426c652f8d..3a3f08668bb 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -267,7 +267,7 @@ func TestGistsService_Create(t *testing.T) { Description: Ptr("Gist description"), Public: Ptr(false), Files: map[GistFilename]*CreateGistFile{ - "test.txt": {Content: Ptr("Gist file content")}, + "test.txt": {Content: "Gist file content"}, }, } diff --git a/github/github-accessors.go b/github/github-accessors.go index 3f27ac51662..b5c01e9989b 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10766,20 +10766,20 @@ func (c *CreateEvent) GetSender() *User { return c.Sender } -// GetBody returns the Body field if it's non-nil, zero value otherwise. +// GetBody returns the Body field. func (c *CreateGistCommentRequest) GetBody() string { - if c == nil || c.Body == nil { + if c == nil { return "" } - return *c.Body + return c.Body } -// GetContent returns the Content field if it's non-nil, zero value otherwise. +// GetContent returns the Content field. func (c *CreateGistFile) GetContent() string { - if c == nil || c.Content == nil { + if c == nil { return "" } - return *c.Content + return c.Content } // GetDescription returns the Description field if it's non-nil, zero value otherwise. @@ -41902,12 +41902,12 @@ func (u *UpdateEnterpriseRunnerGroupRequest) GetVisibility() string { return *u.Visibility } -// GetBody returns the Body field if it's non-nil, zero value otherwise. +// GetBody returns the Body field. func (u *UpdateGistCommentRequest) GetBody() string { - if u == nil || u.Body == nil { + if u == nil { return "" } - return *u.Body + return u.Body } // GetContent returns the Content field if it's non-nil, zero value otherwise. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 1d077f8b1bf..fe11f19855f 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -13691,10 +13691,7 @@ func TestCreateEvent_GetSender(tt *testing.T) { func TestCreateGistCommentRequest_GetBody(tt *testing.T) { tt.Parallel() - var zeroValue string - c := &CreateGistCommentRequest{Body: &zeroValue} - c.GetBody() - c = &CreateGistCommentRequest{} + c := &CreateGistCommentRequest{} c.GetBody() c = nil c.GetBody() @@ -13702,10 +13699,7 @@ func TestCreateGistCommentRequest_GetBody(tt *testing.T) { func TestCreateGistFile_GetContent(tt *testing.T) { tt.Parallel() - var zeroValue string - c := &CreateGistFile{Content: &zeroValue} - c.GetContent() - c = &CreateGistFile{} + c := &CreateGistFile{} c.GetContent() c = nil c.GetContent() @@ -52609,10 +52603,7 @@ func TestUpdateEnterpriseRunnerGroupRequest_GetVisibility(tt *testing.T) { func TestUpdateGistCommentRequest_GetBody(tt *testing.T) { tt.Parallel() - var zeroValue string - u := &UpdateGistCommentRequest{Body: &zeroValue} - u.GetBody() - u = &UpdateGistCommentRequest{} + u := &UpdateGistCommentRequest{} u.GetBody() u = nil u.GetBody()