Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pulls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MAJOR] 潜在问题:Line 字段类型为 int,零值为 0,且 JSON tag 中没有 omitempty。这意味着如果调用者未设置 Line,请求体中会发送 "line": 0,这在 GitHub API 中是无效的(行

[security] 潜在问题:Line 字段类型为 int,零值为 0,且 JSON tag 中没有 omitempty。这意味着如果调用者未设置 Line,请求体中会发送 "line": 0,这在 GitHub API 中是无效的(行号从 1 开始),可能导致 API 返回不明确的错误。

建议:可以考虑将 Line 改为指针类型 *int,这样可以区分"未设置"和"设置为 0"的情况,或者在 CreatePullRequestInlineComment 方法中添加对必填字段(BodyPathLineSide)的基本校验,提前返回有意义的错误信息。

[frontend] 潜在问题:Line 字段类型为 int,零值为 0。当调用者不设置 Line(例如使用 position 方式定位评论)时,JSON 序列化会发送 "line": 0,这可能导致 GitHub API 返回错误(因为行号 0 是无效的)。

建议添加 omitempty tag,或者考虑使用 *int 指针类型来区分"未设置"和"设置为 0"的情况。同理,Side 字段也建议添加 omitempty,以保持与项目中其他 Options 结构体的一致性(如 CreatePullRequestOptions 中可选字段使用 omitempty)。

[backend] 潜在问题:LineSide 字段缺少 omitempty 标签。当调用方未设置这些字段时,JSON 序列化会将 Line: 0Side: "" 发送到 API,可能导致 API 返回错误(GitHub API 中 line 从 1 开始,side 必须是 "LEFT" 或 "RIGHT")。

如果这些字段是创建 inline comment 的必填项,建议在方法中添加参数校验(例如检查 Line > 0Side 为合法值、BodyPath 非空),以便在客户端提前返回有意义的错误信息,而不是依赖 API 端的报错。

如果这些字段是可选的,则应添加 omitempty 标签。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MAJOR] 潜在问题:Line 字段类型为 int,零值为 0,且 JSON tag 中没有 omitempty。这意味着如果调用者未设置 Line,请求体中会发送 "line": 0,这在 GitHub API 中是无效的(行

[security] 潜在问题:Line 字段类型为 int,零值为 0,且 JSON tag 中没有 omitempty。这意味着如果调用者未设置 Line,请求体中会发送 "line": 0,这在 GitHub API 中是无效的(行号从 1 开始),可能导致 API 返回不明确的错误。

建议:可以考虑将 Line 改为指针类型 *int,这样可以区分"未设置"和"设置为 0"的情况,或者在 CreatePullRequestInlineComment 方法中添加对必填字段(BodyPathLineSide)的基本校验,提前返回有意义的错误信息。

[frontend] 潜在问题:Line 字段类型为 int,零值为 0。当调用者不设置 Line(例如使用 position 方式定位评论)时,JSON 序列化会发送 "line": 0,这可能导致 GitHub API 返回错误(因为行号 0 是无效的)。

建议添加 omitempty tag,或者考虑使用 *int 指针类型来区分"未设置"和"设置为 0"的情况。同理,Side 字段也建议添加 omitempty,以保持与项目中其他 Options 结构体的一致性(如 CreatePullRequestOptions 中可选字段使用 omitempty)。

[backend] 潜在问题:LineSide 字段缺少 omitempty 标签。当调用方未设置这些字段时,JSON 序列化会将 Line: 0Side: "" 发送到 API,可能导致 API 返回错误(GitHub API 中 line 从 1 开始,side 必须是 "LEFT" 或 "RIGHT")。

如果这些字段是创建 inline comment 的必填项,建议在方法中添加参数校验(例如检查 Line > 0Side 为合法值、BodyPath 非空),以便在客户端提前返回有意义的错误信息,而不是依赖 API 端的报错。

如果这些字段是可选的,则应添加 omitempty 标签。

Body string `json:"body"`
Path string `json:"path"`
Line int `json:"line"`
Side string `json:"side"`
CommitID string `json:"commit_id,omitempty"`
}
Comment on lines +79 to +85

type PullRequestReview struct {
ID int64 `json:"id"`
Body string `json:"body"`
Expand Down Expand Up @@ -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
Comment on lines +258 to +262
}
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)
Expand Down