From 0563e40a730b734fa9eb708d956a4381afc647de Mon Sep 17 00:00:00 2001 From: zy84338719 Date: Thu, 25 Jun 2026 02:07:07 +0800 Subject: [PATCH] feat: add CreatePullRequestInlineComment for line-level PR comments GitCode's PR comment API accepts and parameters for inline (line-level) comments, but the existing CreatePullRequestComment only sends (diff position), which doesn't produce inline comments on the GitCode web UI. Changes: - Add Line and Side fields to PullRequestComment struct - Add CreatePullRequestInlineCommentOptions with body/path/line/side/commit_id - Add CreatePullRequestInlineComment method that sends the correct parameters for GitCode inline comments --- pulls.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pulls.go b/pulls.go index c5a4cb9..762d5ee 100644 --- a/pulls.go +++ b/pulls.go @@ -69,11 +69,21 @@ type PullRequestComment struct { Author *User `json:"author"` Path string `json:"path"` Position int `json:"position"` + Line int `json:"line"` + Side string `json:"side"` CommitID string `json:"commit_id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } +type CreatePullRequestInlineCommentOptions struct { + Body string `json:"body"` + Path string `json:"path"` + Line int `json:"line"` + Side string `json:"side"` + CommitID string `json:"commit_id,omitempty"` +} + type PullRequestReview struct { ID int64 `json:"id"` Body string `json:"body"` @@ -245,6 +255,15 @@ func (c *Client) CreatePullRequestComment(ctx context.Context, owner, repo strin return &comment, nil } +func (c *Client) CreatePullRequestInlineComment(ctx context.Context, owner, repo string, number int, opts CreatePullRequestInlineCommentOptions) (*PullRequestComment, error) { + var comment PullRequestComment + err := c.doRequest(ctx, http.MethodPost, fmt.Sprintf("/repos/%s/%s/pulls/%d/comments", owner, repo, number), opts, &comment) + if err != nil { + return nil, err + } + return &comment, nil +} + func (c *Client) UpdatePullRequestComment(ctx context.Context, owner, repo string, commentID string, body string) (*PullRequestComment, error) { var comment PullRequestComment err := c.doRequest(ctx, http.MethodPatch, fmt.Sprintf("/repos/%s/%s/pulls/comments/%s", owner, repo, commentID), map[string]string{"body": body}, &comment)