feat(tools): pr_list

This commit is contained in:
Mathias Bergqvist
2026-05-06 22:46:11 +02:00
parent ddfcc32afd
commit 388131c8cd
4 changed files with 187 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/url"
)
type PullRequest struct {
@@ -101,3 +102,29 @@ func (c *Client) GetPullRequestDiff(ctx context.Context, owner, repo string, ind
}
return resp.Body, nil
}
func (c *Client) ListPullRequests(ctx context.Context, owner, repo, state, head string, page, limit int) ([]PullRequest, error) {
if page < 1 {
page = 1
}
if limit < 1 {
limit = 30
}
p := fmt.Sprintf("/api/v1/repos/%s/%s/pulls?state=%s&page=%d&limit=%d",
owner, repo, url.QueryEscape(state), page, limit)
if head != "" {
p += "&head=" + url.QueryEscape(head)
}
body, status, err := c.GetJSON(ctx, p)
if err != nil {
return nil, err
}
if err := MapStatus(status, body); err != nil {
return nil, err
}
var prs []PullRequest
if err := json.Unmarshal(body, &prs); err != nil {
return nil, err
}
return prs, nil
}