fix: address review findings (pagination, case-insensitive bool, docs)
- ListReviews: full pagination (loops until partial page returned) - envOrDefaultBool: case-insensitive, whitespace-trimmed - action.yml: document accepted boolean values - Tests: verify pagination across multiple pages
This commit is contained in:
+24
-13
@@ -297,21 +297,32 @@ func (c *Client) GetAuthenticatedUser(ctx context.Context) (string, error) {
|
||||
}
|
||||
|
||||
// ListReviews returns all reviews on a pull request.
|
||||
// Paginates through all pages to ensure no reviews are missed.
|
||||
func (c *Client) ListReviews(ctx context.Context, owner, repo string, number int) ([]Review, error) {
|
||||
reqURL := fmt.Sprintf("%s/api/v1/repos/%s/%s/pulls/%d/reviews",
|
||||
c.baseURL,
|
||||
url.PathEscape(owner),
|
||||
url.PathEscape(repo),
|
||||
number)
|
||||
body, err := c.doGet(ctx, reqURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list reviews: %w", err)
|
||||
const pageSize = 50
|
||||
var all []Review
|
||||
for page := 1; ; page++ {
|
||||
reqURL := fmt.Sprintf("%s/api/v1/repos/%s/%s/pulls/%d/reviews?limit=%d&page=%d",
|
||||
c.baseURL,
|
||||
url.PathEscape(owner),
|
||||
url.PathEscape(repo),
|
||||
number,
|
||||
pageSize,
|
||||
page)
|
||||
body, err := c.doGet(ctx, reqURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list reviews (page %d): %w", page, err)
|
||||
}
|
||||
var batch []Review
|
||||
if err := json.Unmarshal(body, &batch); err != nil {
|
||||
return nil, fmt.Errorf("parse reviews (page %d): %w", page, err)
|
||||
}
|
||||
all = append(all, batch...)
|
||||
if len(batch) < pageSize {
|
||||
break
|
||||
}
|
||||
}
|
||||
var reviews []Review
|
||||
if err := json.Unmarshal(body, &reviews); err != nil {
|
||||
return nil, fmt.Errorf("parse reviews: %w", err)
|
||||
}
|
||||
return reviews, nil
|
||||
return all, nil
|
||||
}
|
||||
|
||||
// DeleteReview deletes a review by ID. The token must belong to the review author.
|
||||
|
||||
Reference in New Issue
Block a user