feat(tools): pr_files_diff with caps
Returns per-file unified diff for a PR, capped at 20KB/file and 200KB total response. Files exceeding per-file cap report truncated+omitted_lines; files that would push the response over 200KB go to omitted_files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -64,3 +64,40 @@ func (c *Client) GetPullRequest(ctx context.Context, owner, repo string, index i
|
||||
}
|
||||
return &pr, nil
|
||||
}
|
||||
|
||||
type PullRequestFile struct {
|
||||
Filename string `json:"filename"`
|
||||
Status string `json:"status"` // added | modified | deleted | renamed
|
||||
Additions int `json:"additions"`
|
||||
Deletions int `json:"deletions"`
|
||||
}
|
||||
|
||||
func (c *Client) GetPullRequestFiles(ctx context.Context, owner, repo string, index int) ([]PullRequestFile, error) {
|
||||
p := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/files", owner, repo, index)
|
||||
body, status, err := c.GetJSON(ctx, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := MapStatus(status, body); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var files []PullRequestFile
|
||||
if err := json.Unmarshal(body, &files); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
// GetPullRequestDiff returns the raw unified diff. The endpoint serves text/plain, not JSON,
|
||||
// so we use doRaw to bypass the json Accept header expectation.
|
||||
func (c *Client) GetPullRequestDiff(ctx context.Context, owner, repo string, index int) ([]byte, error) {
|
||||
p := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d.diff", owner, repo, index)
|
||||
resp, err := c.doRaw(ctx, "GET", p, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := MapStatus(resp.Status, resp.Body); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user