From 2409c57229363b9da0430dc44f6f0f37913c123f Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Sat, 29 Aug 2026 08:36:01 +0900 Subject: [PATCH 1/2] refactor!: Split commit comment request bodies and pass by value RepositoriesService.CreateComment and UpdateComment reused the 12-field RepositoryComment response type as their request bodies. The two endpoints accept different fields (create: body, path, position, line; update: body only), so introduce dedicated CreateCommitCommentRequest and UpdateCommitCommentRequest types, pass them by value, and drop RepositoryComment from the paramcheck allowlist. Also align the {comment_id} parameter name to commentID across GetComment, UpdateComment, and DeleteComment. BREAKING CHANGE: `RepositoriesService.CreateComment` now takes `CreateCommitCommentRequest` and `RepositoriesService.UpdateComment` takes `UpdateCommitCommentRequest`, both passed by value instead of `*RepositoryComment`. Updates #3644. --- .golangci.yml | 1 - github/github-accessors.go | 40 +++++++++++++++++++++++++++ github/github-accessors_test.go | 49 +++++++++++++++++++++++++++++++++ github/repos_comments.go | 35 +++++++++++++++-------- github/repos_comments_test.go | 8 +++--- 5 files changed, 116 insertions(+), 17 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ec01b793baa..7b1ea8aaea0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -236,7 +236,6 @@ linters: - PullRequestReviewsEnforcementUpdate - Repository - RepositoryAddCollaboratorOptions - - RepositoryComment - RepositoryContentFileOptions - RepositoryCreateForkOptions - RequiredStatusChecksRequest diff --git a/github/github-accessors.go b/github/github-accessors.go index 94f10a4031e..580c35e37f9 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -11582,6 +11582,38 @@ func (c *CreateCodespaceOptions) GetWorkingDirectory() string { return *c.WorkingDirectory } +// GetBody returns the Body field. +func (c *CreateCommitCommentRequest) GetBody() string { + if c == nil { + return "" + } + return c.Body +} + +// GetLine returns the Line field if it's non-nil, zero value otherwise. +func (c *CreateCommitCommentRequest) GetLine() int { + if c == nil || c.Line == nil { + return 0 + } + return *c.Line +} + +// GetPath returns the Path field if it's non-nil, zero value otherwise. +func (c *CreateCommitCommentRequest) GetPath() string { + if c == nil || c.Path == nil { + return "" + } + return *c.Path +} + +// GetPosition returns the Position field if it's non-nil, zero value otherwise. +func (c *CreateCommitCommentRequest) GetPosition() int { + if c == nil || c.Position == nil { + return 0 + } + return *c.Position +} + // GetSigner returns the Signer field. func (c *CreateCommitOptions) GetSigner() MessageSigner { if c == nil { @@ -44046,6 +44078,14 @@ func (u *UpdateCodespaceOptions) GetRecentFolders() []string { return u.RecentFolders } +// GetBody returns the Body field. +func (u *UpdateCommitCommentRequest) GetBody() string { + if u == nil { + return "" + } + return u.Body +} + // GetGroupID returns the GroupID field. func (u *UpdateConnectedExternalGroupRequest) GetGroupID() int64 { if u == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 99430a9e357..14f419bd2f1 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -14631,6 +14631,47 @@ func TestCreateCodespaceOptions_GetWorkingDirectory(tt *testing.T) { c.GetWorkingDirectory() } +func TestCreateCommitCommentRequest_GetBody(tt *testing.T) { + tt.Parallel() + c := &CreateCommitCommentRequest{} + c.GetBody() + c = nil + c.GetBody() +} + +func TestCreateCommitCommentRequest_GetLine(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &CreateCommitCommentRequest{Line: &zeroValue} + c.GetLine() + c = &CreateCommitCommentRequest{} + c.GetLine() + c = nil + c.GetLine() +} + +func TestCreateCommitCommentRequest_GetPath(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateCommitCommentRequest{Path: &zeroValue} + c.GetPath() + c = &CreateCommitCommentRequest{} + c.GetPath() + c = nil + c.GetPath() +} + +func TestCreateCommitCommentRequest_GetPosition(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &CreateCommitCommentRequest{Position: &zeroValue} + c.GetPosition() + c = &CreateCommitCommentRequest{} + c.GetPosition() + c = nil + c.GetPosition() +} + func TestCreateCommitOptions_GetSigner(tt *testing.T) { tt.Parallel() c := &CreateCommitOptions{} @@ -55075,6 +55116,14 @@ func TestUpdateCodespaceOptions_GetRecentFolders(tt *testing.T) { u.GetRecentFolders() } +func TestUpdateCommitCommentRequest_GetBody(tt *testing.T) { + tt.Parallel() + u := &UpdateCommitCommentRequest{} + u.GetBody() + u = nil + u.GetBody() +} + func TestUpdateConnectedExternalGroupRequest_GetGroupID(tt *testing.T) { tt.Parallel() u := &UpdateConnectedExternalGroupRequest{} diff --git a/github/repos_comments.go b/github/repos_comments.go index e5da15f02a4..69f2f2b2c40 100644 --- a/github/repos_comments.go +++ b/github/repos_comments.go @@ -21,16 +21,27 @@ type RepositoryComment struct { Reactions *Reactions `json:"reactions,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` UpdatedAt *Timestamp `json:"updated_at,omitempty"` + Body *string `json:"body,omitempty"` + Path *string `json:"path,omitempty"` + Position *int `json:"position,omitempty"` +} - // User-mutable fields - Body *string `json:"body"` - // User-initialized fields +func (r RepositoryComment) String() string { + return Stringify(r) +} + +// CreateCommitCommentRequest represents a request to create a commit comment. +type CreateCommitCommentRequest struct { + Body string `json:"body"` Path *string `json:"path,omitempty"` Position *int `json:"position,omitempty"` + // Deprecated: Use Position instead. + Line *int `json:"line,omitempty"` } -func (r RepositoryComment) String() string { - return Stringify(r) +// UpdateCommitCommentRequest represents a request to update a commit comment. +type UpdateCommitCommentRequest struct { + Body string `json:"body"` } // ListComments lists all the comments for the repository. @@ -95,7 +106,7 @@ func (s *RepositoriesService) ListCommitComments(ctx context.Context, owner, rep // GitHub API docs: https://docs.github.com/rest/commits/comments?apiVersion=2022-11-28#create-a-commit-comment // //meta:operation POST /repos/{owner}/{repo}/commits/{commit_sha}/comments -func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sha string, body *RepositoryComment) (*RepositoryComment, *Response, error) { +func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sha string, body CreateCommitCommentRequest) (*RepositoryComment, *Response, error) { u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha) req, err := s.client.NewRequest(ctx, "POST", u, body) if err != nil { @@ -116,8 +127,8 @@ func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sh // GitHub API docs: https://docs.github.com/rest/commits/comments?apiVersion=2022-11-28#get-a-commit-comment // //meta:operation GET /repos/{owner}/{repo}/comments/{comment_id} -func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string, id int64) (*RepositoryComment, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id) +func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string, commentID int64) (*RepositoryComment, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, commentID) req, err := s.client.NewRequest(ctx, "GET", u, nil) if err != nil { return nil, nil, err @@ -139,8 +150,8 @@ func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string // GitHub API docs: https://docs.github.com/rest/commits/comments?apiVersion=2022-11-28#update-a-commit-comment // //meta:operation PATCH /repos/{owner}/{repo}/comments/{comment_id} -func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo string, id int64, body *RepositoryComment) (*RepositoryComment, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id) +func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo string, commentID int64, body UpdateCommitCommentRequest) (*RepositoryComment, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, commentID) req, err := s.client.NewRequest(ctx, "PATCH", u, body) if err != nil { return nil, nil, err @@ -160,8 +171,8 @@ func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo str // GitHub API docs: https://docs.github.com/rest/commits/comments?apiVersion=2022-11-28#delete-a-commit-comment // //meta:operation DELETE /repos/{owner}/{repo}/comments/{comment_id} -func (s *RepositoriesService) DeleteComment(ctx context.Context, owner, repo string, id int64) (*Response, error) { - u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id) +func (s *RepositoriesService) DeleteComment(ctx context.Context, owner, repo string, commentID int64) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, commentID) req, err := s.client.NewRequest(ctx, "DELETE", u, nil) if err != nil { return nil, err diff --git a/github/repos_comments_test.go b/github/repos_comments_test.go index aaf63a9279a..874a841fc08 100644 --- a/github/repos_comments_test.go +++ b/github/repos_comments_test.go @@ -111,7 +111,7 @@ func TestRepositoriesService_CreateComment(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &RepositoryComment{Body: new("b")} + input := CreateCommitCommentRequest{Body: "b"} mux.HandleFunc("/repos/o/r/commits/s/comments", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") @@ -150,7 +150,7 @@ func TestRepositoriesService_CreateComment_invalidOwner(t *testing.T) { client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.Repositories.CreateComment(ctx, "%", "%", "%", nil) + _, _, err := client.Repositories.CreateComment(ctx, "%", "%", "%", CreateCommitCommentRequest{}) testURLParseError(t, err) } @@ -203,7 +203,7 @@ func TestRepositoriesService_UpdateComment(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &RepositoryComment{Body: new("b")} + input := UpdateCommitCommentRequest{Body: "b"} mux.HandleFunc("/repos/o/r/comments/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") @@ -243,7 +243,7 @@ func TestRepositoriesService_UpdateComment_invalidOwner(t *testing.T) { client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.Repositories.UpdateComment(ctx, "%", "%", 1, nil) + _, _, err := client.Repositories.UpdateComment(ctx, "%", "%", 1, UpdateCommitCommentRequest{}) testURLParseError(t, err) } From b85f7afdf1eb24ddafe325f1868402524ff57c39 Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Sat, 29 Aug 2026 08:38:00 +0900 Subject: [PATCH 2/2] feat: Add `AuthorAssociation` and `Line` to `RepositoryComment` The commit-comment response schema includes author_association and line, which were missing from the struct. --- github/github-accessors.go | 16 ++++++++++++++++ github/github-accessors_test.go | 22 ++++++++++++++++++++++ github/github-stringify_test.go | 28 +++++++++++++++------------- github/repos_comments.go | 26 ++++++++++++++------------ 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 580c35e37f9..164c18a390f 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -35870,6 +35870,14 @@ func (r *RepositoryCodeSecurityConfiguration) GetState() string { return *r.State } +// GetAuthorAssociation returns the AuthorAssociation field if it's non-nil, zero value otherwise. +func (r *RepositoryComment) GetAuthorAssociation() string { + if r == nil || r.AuthorAssociation == nil { + return "" + } + return *r.AuthorAssociation +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (r *RepositoryComment) GetBody() string { if r == nil || r.Body == nil { @@ -35910,6 +35918,14 @@ func (r *RepositoryComment) GetID() int64 { return *r.ID } +// GetLine returns the Line field if it's non-nil, zero value otherwise. +func (r *RepositoryComment) GetLine() int { + if r == nil || r.Line == nil { + return 0 + } + return *r.Line +} + // GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. func (r *RepositoryComment) GetNodeID() string { if r == nil || r.NodeID == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 14f419bd2f1..ea2d806138d 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -45012,6 +45012,17 @@ func TestRepositoryCodeSecurityConfiguration_GetState(tt *testing.T) { r.GetState() } +func TestRepositoryComment_GetAuthorAssociation(tt *testing.T) { + tt.Parallel() + var zeroValue string + r := &RepositoryComment{AuthorAssociation: &zeroValue} + r.GetAuthorAssociation() + r = &RepositoryComment{} + r.GetAuthorAssociation() + r = nil + r.GetAuthorAssociation() +} + func TestRepositoryComment_GetBody(tt *testing.T) { tt.Parallel() var zeroValue string @@ -45067,6 +45078,17 @@ func TestRepositoryComment_GetID(tt *testing.T) { r.GetID() } +func TestRepositoryComment_GetLine(tt *testing.T) { + tt.Parallel() + var zeroValue int + r := &RepositoryComment{Line: &zeroValue} + r.GetLine() + r = &RepositoryComment{} + r.GetLine() + r = nil + r.GetLine() +} + func TestRepositoryComment_GetNodeID(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 76ab5cf06d9..60409b9f2a1 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -2050,20 +2050,22 @@ func TestRepository_String(t *testing.T) { func TestRepositoryComment_String(t *testing.T) { t.Parallel() v := RepositoryComment{ - HTMLURL: new(""), - URL: new(""), - ID: new(int64(0)), - NodeID: new(""), - CommitID: new(""), - User: &User{}, - Reactions: &Reactions{}, - CreatedAt: &Timestamp{}, - UpdatedAt: &Timestamp{}, - Body: new(""), - Path: new(""), - Position: new(0), + HTMLURL: new(""), + URL: new(""), + ID: new(int64(0)), + NodeID: new(""), + CommitID: new(""), + User: &User{}, + AuthorAssociation: new(""), + Reactions: &Reactions{}, + CreatedAt: &Timestamp{}, + UpdatedAt: &Timestamp{}, + Body: new(""), + Path: new(""), + Position: new(0), + Line: new(0), } - want := `github.RepositoryComment{HTMLURL:"", URL:"", ID:0, NodeID:"", CommitID:"", User:github.User{}, Reactions:github.Reactions{}, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Body:"", Path:"", Position:0}` + want := `github.RepositoryComment{HTMLURL:"", URL:"", ID:0, NodeID:"", CommitID:"", User:github.User{}, AuthorAssociation:"", Reactions:github.Reactions{}, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Body:"", Path:"", Position:0, Line:0}` if got := v.String(); got != want { t.Errorf("RepositoryComment.String = %v, want %v", got, want) } diff --git a/github/repos_comments.go b/github/repos_comments.go index 69f2f2b2c40..ccbda059461 100644 --- a/github/repos_comments.go +++ b/github/repos_comments.go @@ -12,18 +12,20 @@ import ( // RepositoryComment represents a comment for a commit, file, or line in a repository. type RepositoryComment struct { - HTMLURL *string `json:"html_url,omitempty"` - URL *string `json:"url,omitempty"` - ID *int64 `json:"id,omitempty"` - NodeID *string `json:"node_id,omitempty"` - CommitID *string `json:"commit_id,omitempty"` - User *User `json:"user,omitempty"` - Reactions *Reactions `json:"reactions,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - UpdatedAt *Timestamp `json:"updated_at,omitempty"` - Body *string `json:"body,omitempty"` - Path *string `json:"path,omitempty"` - Position *int `json:"position,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + URL *string `json:"url,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + CommitID *string `json:"commit_id,omitempty"` + User *User `json:"user,omitempty"` + AuthorAssociation *string `json:"author_association,omitempty"` + Reactions *Reactions `json:"reactions,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + Body *string `json:"body,omitempty"` + Path *string `json:"path,omitempty"` + Position *int `json:"position,omitempty"` + Line *int `json:"line,omitempty"` } func (r RepositoryComment) String() string {