diff --git a/.golangci.yml b/.golangci.yml index 238a7d3e59c..080b058918f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -233,7 +233,6 @@ linters: - ProtectionRequest - PublishCodespaceOptions - PullRequestBranchUpdateOptions - - PullRequestComment - PullRequestReviewRequest - PullRequestReviewsEnforcementUpdate - Repository diff --git a/github/github-accessors.go b/github/github-accessors.go index ab14c72673c..9c32d55d4ae 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -12414,6 +12414,86 @@ func (c *CreatePullRequest) GetTitle() string { return *c.Title } +// GetBody returns the Body field. +func (c *CreatePullRequestCommentRequest) GetBody() string { + if c == nil { + return "" + } + return c.Body +} + +// GetCommitID returns the CommitID field. +func (c *CreatePullRequestCommentRequest) GetCommitID() string { + if c == nil { + return "" + } + return c.CommitID +} + +// GetInReplyTo returns the InReplyTo field if it's non-nil, zero value otherwise. +func (c *CreatePullRequestCommentRequest) GetInReplyTo() int64 { + if c == nil || c.InReplyTo == nil { + return 0 + } + return *c.InReplyTo +} + +// GetLine returns the Line field if it's non-nil, zero value otherwise. +func (c *CreatePullRequestCommentRequest) GetLine() int { + if c == nil || c.Line == nil { + return 0 + } + return *c.Line +} + +// GetPath returns the Path field. +func (c *CreatePullRequestCommentRequest) GetPath() string { + if c == nil { + return "" + } + return c.Path +} + +// GetPosition returns the Position field if it's non-nil, zero value otherwise. +func (c *CreatePullRequestCommentRequest) GetPosition() int { + if c == nil || c.Position == nil { + return 0 + } + return *c.Position +} + +// GetSide returns the Side field if it's non-nil, zero value otherwise. +func (c *CreatePullRequestCommentRequest) GetSide() string { + if c == nil || c.Side == nil { + return "" + } + return *c.Side +} + +// GetStartLine returns the StartLine field if it's non-nil, zero value otherwise. +func (c *CreatePullRequestCommentRequest) GetStartLine() int { + if c == nil || c.StartLine == nil { + return 0 + } + return *c.StartLine +} + +// GetStartSide returns the StartSide field if it's non-nil, zero value otherwise. +func (c *CreatePullRequestCommentRequest) GetStartSide() string { + if c == nil || c.StartSide == nil { + return "" + } + return *c.StartSide +} + +// GetSubjectType returns the SubjectType field if it's non-nil, zero value otherwise. +func (c *CreatePullRequestCommentRequest) GetSubjectType() string { + if c == nil || c.SubjectType == nil { + return "" + } + return *c.SubjectType +} + // GetRef returns the Ref field. func (c *CreateRef) GetRef() string { if c == nil { @@ -31838,6 +31918,22 @@ func (p *PullRequestComment) GetBody() string { return *p.Body } +// GetBodyHTML returns the BodyHTML field if it's non-nil, zero value otherwise. +func (p *PullRequestComment) GetBodyHTML() string { + if p == nil || p.BodyHTML == nil { + return "" + } + return *p.BodyHTML +} + +// GetBodyText returns the BodyText field if it's non-nil, zero value otherwise. +func (p *PullRequestComment) GetBodyText() string { + if p == nil || p.BodyText == nil { + return "" + } + return *p.BodyText +} + // GetCommitID returns the CommitID field if it's non-nil, zero value otherwise. func (p *PullRequestComment) GetCommitID() string { if p == nil || p.CommitID == nil { @@ -31894,6 +31990,14 @@ func (p *PullRequestComment) GetLine() int { return *p.Line } +// GetLinks returns the Links field. +func (p *PullRequestComment) GetLinks() *PullRequestCommentLinks { + if p == nil { + return nil + } + return p.Links +} + // GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. func (p *PullRequestComment) GetNodeID() string { if p == nil || p.NodeID == nil { @@ -32030,6 +32134,30 @@ func (p *PullRequestComment) GetUser() *User { return p.User } +// GetHTML returns the HTML field. +func (p *PullRequestCommentLinks) GetHTML() *PRLink { + if p == nil { + return nil + } + return p.HTML +} + +// GetPullRequest returns the PullRequest field. +func (p *PullRequestCommentLinks) GetPullRequest() *PRLink { + if p == nil { + return nil + } + return p.PullRequest +} + +// GetSelf returns the Self field. +func (p *PullRequestCommentLinks) GetSelf() *PRLink { + if p == nil { + return nil + } + return p.Self +} + // GetEvent returns the Event field if it's non-nil, zero value otherwise. func (p *PullRequestDismissReviewRequest) GetEvent() string { if p == nil || p.Event == nil { @@ -44566,6 +44694,14 @@ func (u *UpdateProvisionedOrgMembershipRequest) GetUserName() string { return u.UserName } +// GetBody returns the Body field. +func (u *UpdatePullRequestCommentRequest) GetBody() string { + if u == nil { + return "" + } + return u.Body +} + // GetForce returns the Force field if it's non-nil, zero value otherwise. func (u *UpdateRef) GetForce() bool { if u == nil || u.Force == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index beb42687d75..5301467f9d5 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -15682,6 +15682,107 @@ func TestCreatePullRequest_GetTitle(tt *testing.T) { c.GetTitle() } +func TestCreatePullRequestCommentRequest_GetBody(tt *testing.T) { + tt.Parallel() + c := &CreatePullRequestCommentRequest{} + c.GetBody() + c = nil + c.GetBody() +} + +func TestCreatePullRequestCommentRequest_GetCommitID(tt *testing.T) { + tt.Parallel() + c := &CreatePullRequestCommentRequest{} + c.GetCommitID() + c = nil + c.GetCommitID() +} + +func TestCreatePullRequestCommentRequest_GetInReplyTo(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + c := &CreatePullRequestCommentRequest{InReplyTo: &zeroValue} + c.GetInReplyTo() + c = &CreatePullRequestCommentRequest{} + c.GetInReplyTo() + c = nil + c.GetInReplyTo() +} + +func TestCreatePullRequestCommentRequest_GetLine(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &CreatePullRequestCommentRequest{Line: &zeroValue} + c.GetLine() + c = &CreatePullRequestCommentRequest{} + c.GetLine() + c = nil + c.GetLine() +} + +func TestCreatePullRequestCommentRequest_GetPath(tt *testing.T) { + tt.Parallel() + c := &CreatePullRequestCommentRequest{} + c.GetPath() + c = nil + c.GetPath() +} + +func TestCreatePullRequestCommentRequest_GetPosition(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &CreatePullRequestCommentRequest{Position: &zeroValue} + c.GetPosition() + c = &CreatePullRequestCommentRequest{} + c.GetPosition() + c = nil + c.GetPosition() +} + +func TestCreatePullRequestCommentRequest_GetSide(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreatePullRequestCommentRequest{Side: &zeroValue} + c.GetSide() + c = &CreatePullRequestCommentRequest{} + c.GetSide() + c = nil + c.GetSide() +} + +func TestCreatePullRequestCommentRequest_GetStartLine(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &CreatePullRequestCommentRequest{StartLine: &zeroValue} + c.GetStartLine() + c = &CreatePullRequestCommentRequest{} + c.GetStartLine() + c = nil + c.GetStartLine() +} + +func TestCreatePullRequestCommentRequest_GetStartSide(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreatePullRequestCommentRequest{StartSide: &zeroValue} + c.GetStartSide() + c = &CreatePullRequestCommentRequest{} + c.GetStartSide() + c = nil + c.GetStartSide() +} + +func TestCreatePullRequestCommentRequest_GetSubjectType(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreatePullRequestCommentRequest{SubjectType: &zeroValue} + c.GetSubjectType() + c = &CreatePullRequestCommentRequest{} + c.GetSubjectType() + c = nil + c.GetSubjectType() +} + func TestCreateRef_GetRef(tt *testing.T) { tt.Parallel() c := &CreateRef{} @@ -39957,6 +40058,28 @@ func TestPullRequestComment_GetBody(tt *testing.T) { p.GetBody() } +func TestPullRequestComment_GetBodyHTML(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &PullRequestComment{BodyHTML: &zeroValue} + p.GetBodyHTML() + p = &PullRequestComment{} + p.GetBodyHTML() + p = nil + p.GetBodyHTML() +} + +func TestPullRequestComment_GetBodyText(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &PullRequestComment{BodyText: &zeroValue} + p.GetBodyText() + p = &PullRequestComment{} + p.GetBodyText() + p = nil + p.GetBodyText() +} + func TestPullRequestComment_GetCommitID(tt *testing.T) { tt.Parallel() var zeroValue string @@ -40034,6 +40157,14 @@ func TestPullRequestComment_GetLine(tt *testing.T) { p.GetLine() } +func TestPullRequestComment_GetLinks(tt *testing.T) { + tt.Parallel() + p := &PullRequestComment{} + p.GetLinks() + p = nil + p.GetLinks() +} + func TestPullRequestComment_GetNodeID(tt *testing.T) { tt.Parallel() var zeroValue string @@ -40215,6 +40346,30 @@ func TestPullRequestComment_GetUser(tt *testing.T) { p.GetUser() } +func TestPullRequestCommentLinks_GetHTML(tt *testing.T) { + tt.Parallel() + p := &PullRequestCommentLinks{} + p.GetHTML() + p = nil + p.GetHTML() +} + +func TestPullRequestCommentLinks_GetPullRequest(tt *testing.T) { + tt.Parallel() + p := &PullRequestCommentLinks{} + p.GetPullRequest() + p = nil + p.GetPullRequest() +} + +func TestPullRequestCommentLinks_GetSelf(tt *testing.T) { + tt.Parallel() + p := &PullRequestCommentLinks{} + p.GetSelf() + p = nil + p.GetSelf() +} + func TestPullRequestDismissReviewRequest_GetEvent(tt *testing.T) { tt.Parallel() var zeroValue string @@ -55784,6 +55939,14 @@ func TestUpdateProvisionedOrgMembershipRequest_GetUserName(tt *testing.T) { u.GetUserName() } +func TestUpdatePullRequestCommentRequest_GetBody(tt *testing.T) { + tt.Parallel() + u := &UpdatePullRequestCommentRequest{} + u.GetBody() + u = nil + u.GetBody() +} + func TestUpdateRef_GetForce(tt *testing.T) { tt.Parallel() var zeroValue bool diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 3bbdc8a9a61..2780d7b4c5e 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -1681,6 +1681,8 @@ func TestPullRequestComment_String(t *testing.T) { NodeID: Ptr(""), InReplyTo: Ptr(int64(0)), Body: Ptr(""), + BodyHTML: Ptr(""), + BodyText: Ptr(""), Path: Ptr(""), DiffHunk: Ptr(""), PullRequestReviewID: Ptr(int64(0)), @@ -1702,9 +1704,10 @@ func TestPullRequestComment_String(t *testing.T) { URL: Ptr(""), HTMLURL: Ptr(""), PullRequestURL: Ptr(""), + Links: &PullRequestCommentLinks{}, SubjectType: Ptr(""), } - want := `github.PullRequestComment{ID:0, NodeID:"", InReplyTo:0, Body:"", Path:"", DiffHunk:"", PullRequestReviewID:0, Position:0, OriginalPosition:0, StartLine:0, Line:0, OriginalLine:0, OriginalStartLine:0, Side:"", StartSide:"", CommitID:"", OriginalCommitID:"", 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}, AuthorAssociation:"", URL:"", HTMLURL:"", PullRequestURL:"", SubjectType:""}` + want := `github.PullRequestComment{ID:0, NodeID:"", InReplyTo:0, Body:"", BodyHTML:"", BodyText:"", Path:"", DiffHunk:"", PullRequestReviewID:0, Position:0, OriginalPosition:0, StartLine:0, Line:0, OriginalLine:0, OriginalStartLine:0, Side:"", StartSide:"", CommitID:"", OriginalCommitID:"", 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}, AuthorAssociation:"", URL:"", HTMLURL:"", PullRequestURL:"", Links:github.PullRequestCommentLinks{}, SubjectType:""}` if got := v.String(); got != want { t.Errorf("PullRequestComment.String = %v, want %v", got, want) } diff --git a/github/pulls_comments.go b/github/pulls_comments.go index 1a8016f7272..7bd2c970e96 100644 --- a/github/pulls_comments.go +++ b/github/pulls_comments.go @@ -18,6 +18,8 @@ type PullRequestComment struct { NodeID *string `json:"node_id,omitempty"` InReplyTo *int64 `json:"in_reply_to_id,omitempty"` Body *string `json:"body,omitempty"` + BodyHTML *string `json:"body_html,omitempty"` + BodyText *string `json:"body_text,omitempty"` Path *string `json:"path,omitempty"` DiffHunk *string `json:"diff_hunk,omitempty"` PullRequestReviewID *int64 `json:"pull_request_review_id,omitempty"` @@ -41,14 +43,23 @@ type PullRequestComment struct { // Deprecated: GitHub will remove this field from Events API payloads on October 7, 2025. // Use the Pull Request Comments REST API endpoint to retrieve this information. // See: https://docs.github.com/rest/pulls/comments?apiVersion=2022-11-28#get-a-review-comment-for-a-pull-request - AuthorAssociation *string `json:"author_association,omitempty"` - URL *string `json:"url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - PullRequestURL *string `json:"pull_request_url,omitempty"` + AuthorAssociation *string `json:"author_association,omitempty"` + URL *string `json:"url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + PullRequestURL *string `json:"pull_request_url,omitempty"` + Links *PullRequestCommentLinks `json:"_links,omitempty"` // Can be one of: LINE, FILE from https://docs.github.com/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment-for-a-pull-request SubjectType *string `json:"subject_type,omitempty"` } +// PullRequestCommentLinks represents the "_links" object in a pull request +// review comment. +type PullRequestCommentLinks struct { + Self *PRLink `json:"self,omitempty"` + HTML *PRLink `json:"html,omitempty"` + PullRequest *PRLink `json:"pull_request,omitempty"` +} + func (p PullRequestComment) String() string { return Stringify(p) } @@ -131,12 +142,34 @@ func (s *PullRequestsService) GetComment(ctx context.Context, owner, repo string return comment, resp, nil } +// CreatePullRequestCommentRequest represents a request to create a review +// comment on a pull request. +type CreatePullRequestCommentRequest struct { + Body string `json:"body"` + CommitID string `json:"commit_id"` + Path string `json:"path"` + // Deprecated: Use Line and Side instead. + Position *int `json:"position,omitempty"` + Line *int `json:"line,omitempty"` + Side *string `json:"side,omitempty"` + StartLine *int `json:"start_line,omitempty"` + StartSide *string `json:"start_side,omitempty"` + InReplyTo *int64 `json:"in_reply_to,omitempty"` + SubjectType *string `json:"subject_type,omitempty"` +} + +// UpdatePullRequestCommentRequest represents a request to update a review +// comment on a pull request. +type UpdatePullRequestCommentRequest struct { + Body string `json:"body"` +} + // CreateComment creates a new comment on the specified pull request. // // GitHub API docs: https://docs.github.com/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment-for-a-pull-request // //meta:operation POST /repos/{owner}/{repo}/pulls/{pull_number}/comments -func (s *PullRequestsService) CreateComment(ctx context.Context, owner, repo string, number int, body *PullRequestComment) (*PullRequestComment, *Response, error) { +func (s *PullRequestsService) CreateComment(ctx context.Context, owner, repo string, number int, body CreatePullRequestCommentRequest) (*PullRequestComment, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%v/comments", owner, repo, number) req, err := s.client.NewRequest(ctx, "POST", u, body) if err != nil { @@ -182,13 +215,12 @@ func (s *PullRequestsService) CreateCommentInReplyTo(ctx context.Context, owner, return c, resp, nil } -// EditComment updates a pull request comment. -// A non-nil comment.Body must be provided. Other comment fields should be left nil. +// UpdateComment updates a pull request comment. // // GitHub API docs: https://docs.github.com/rest/pulls/comments?apiVersion=2022-11-28#update-a-review-comment-for-a-pull-request // //meta:operation PATCH /repos/{owner}/{repo}/pulls/comments/{comment_id} -func (s *PullRequestsService) EditComment(ctx context.Context, owner, repo string, commentID int64, body *PullRequestComment) (*PullRequestComment, *Response, error) { +func (s *PullRequestsService) UpdateComment(ctx context.Context, owner, repo string, commentID int64, body UpdatePullRequestCommentRequest) (*PullRequestComment, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v", owner, repo, commentID) req, err := s.client.NewRequest(ctx, "PATCH", u, body) if err != nil { diff --git a/github/pulls_comments_test.go b/github/pulls_comments_test.go index 1171b6bf2d7..7322a501e91 100644 --- a/github/pulls_comments_test.go +++ b/github/pulls_comments_test.go @@ -145,7 +145,7 @@ func TestPullRequestsService_CreateComment(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &PullRequestComment{Body: Ptr("b")} + input := CreatePullRequestCommentRequest{Body: "b", CommitID: "c", Path: "p"} wantAcceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeMultiLineCommentsPreview} mux.HandleFunc("/repos/o/r/pulls/1/comments", func(w http.ResponseWriter, r *http.Request) { @@ -186,7 +186,7 @@ func TestPullRequestsService_CreateComment_invalidOwner(t *testing.T) { client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.PullRequests.CreateComment(ctx, "%", "r", 1, nil) + _, _, err := client.PullRequests.CreateComment(ctx, "%", "r", 1, CreatePullRequestCommentRequest{}) testURLParseError(t, err) } @@ -228,11 +228,11 @@ func TestPullRequestsService_CreateCommentInReplyTo(t *testing.T) { }) } -func TestPullRequestsService_EditComment(t *testing.T) { +func TestPullRequestsService_UpdateComment(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &PullRequestComment{Body: Ptr("b")} + input := UpdatePullRequestCommentRequest{Body: "b"} mux.HandleFunc("/repos/o/r/pulls/comments/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") @@ -241,24 +241,24 @@ func TestPullRequestsService_EditComment(t *testing.T) { }) ctx := t.Context() - comment, _, err := client.PullRequests.EditComment(ctx, "o", "r", 1, input) + comment, _, err := client.PullRequests.UpdateComment(ctx, "o", "r", 1, input) if err != nil { - t.Errorf("PullRequests.EditComment returned error: %v", err) + t.Errorf("PullRequests.UpdateComment returned error: %v", err) } want := &PullRequestComment{ID: Ptr(int64(1))} if !cmp.Equal(comment, want) { - t.Errorf("PullRequests.EditComment returned %+v, want %+v", comment, want) + t.Errorf("PullRequests.UpdateComment returned %+v, want %+v", comment, want) } - const methodName = "EditComment" + const methodName = "UpdateComment" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.PullRequests.EditComment(ctx, "\n", "\n", -1, input) + _, _, err = client.PullRequests.UpdateComment(ctx, "\n", "\n", -1, input) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.PullRequests.EditComment(ctx, "o", "r", 1, input) + got, resp, err := client.PullRequests.UpdateComment(ctx, "o", "r", 1, input) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -266,12 +266,12 @@ func TestPullRequestsService_EditComment(t *testing.T) { }) } -func TestPullRequestsService_EditComment_invalidOwner(t *testing.T) { +func TestPullRequestsService_UpdateComment_invalidOwner(t *testing.T) { t.Parallel() client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.PullRequests.EditComment(ctx, "%", "r", 1, nil) + _, _, err := client.PullRequests.UpdateComment(ctx, "%", "r", 1, UpdatePullRequestCommentRequest{}) testURLParseError(t, err) }