Skip to content

Commit 4c5baeb

Browse files
authored
fix: loop over all pages to find matching pull request (#333)
1 parent 5e0a308 commit 4c5baeb

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

repository/pull_request.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,34 @@ func (r Repository) findMatchingPullRequest(ctx context.Context, options GitHubO
2323
if err != nil {
2424
return nil, fmt.Errorf("failed to create github client: %w", err)
2525
}
26-
prs, _, err := client.PullRequests.List(ctx, r.Owner, r.Name, &github.PullRequestListOptions{
27-
Base: options.PullRequest.BaseBranch,
28-
})
29-
if err != nil {
30-
return nil, fmt.Errorf("failed to list opened Pull Requests for repository %s: %w", r.FullName(), err)
31-
}
3226

33-
for _, pr := range prs {
34-
if prHasLabels(pr, options.PullRequest.Labels) {
35-
logrus.WithFields(logrus.Fields{
36-
"repository": r.FullName(),
37-
"labels": options.PullRequest.Labels,
38-
"pull-request": pr.GetHTMLURL(),
39-
}).Info("Found existing Pull Request")
40-
return pr, nil
27+
page := 1
28+
for {
29+
prs, resp, err := client.PullRequests.List(ctx, r.Owner, r.Name, &github.PullRequestListOptions{
30+
Base: options.PullRequest.BaseBranch,
31+
ListOptions: github.ListOptions{
32+
Page: page,
33+
PerPage: 100,
34+
},
35+
})
36+
if err != nil {
37+
return nil, fmt.Errorf("failed to list opened Pull Requests for repository %s: %w", r.FullName(), err)
38+
}
39+
40+
for _, pr := range prs {
41+
if prHasLabels(pr, options.PullRequest.Labels) {
42+
logrus.WithFields(logrus.Fields{
43+
"repository": r.FullName(),
44+
"labels": options.PullRequest.Labels,
45+
"pull-request": pr.GetHTMLURL(),
46+
}).Info("Found existing Pull Request")
47+
return pr, nil
48+
}
49+
}
50+
51+
page = resp.NextPage
52+
if resp.NextPage == 0 {
53+
break
4154
}
4255
}
4356

0 commit comments

Comments
 (0)