fix(api)!: list only open pull requests when no state is given (#40078)

`GET /repos/{owner}/{repo}/pulls` is documented with `state` defaulting
to `open`, but without `state` it returned every pull request, closed
and merged ones included. Now it parses `state` with
`ParseIssueFilterStateIsClosed`, like the issues and milestones
endpoints, so no state means open, as documented. `closed` and `all`
work as before. GitHub's pulls endpoint also defaults to open.
This commit is contained in:
Jorge authored and GitHub committed 2026-10-30 08:42:49 +00:00
1 parent 467963f0dd
commit 2660b4d2c4
4 files changed
+31 -8

No files matched your search

+22
View File
@@ -144,6 +144,28 @@ func TestAPIViewPulls(t *testing.T) {
}))
}
t.Run("DefaultState", func(t *testing.T) {
writeToken := getTokenForLoggedInUser(t, ctx.Session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/3", owner.Name, repo.Name), &api.EditPullRequestOption{
State: new(string(api.StateClosed)),
}).AddTokenAuth(writeToken)
MakeRequest(t, req, http.StatusCreated)
for query, want := range map[string][]int64{
"": {2, 5},
"state=closed": {3},
"state=all": {2, 3, 5},
} {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls?%s", owner.Name, repo.Name, query).AddTokenAuth(ctx.Token)
listed := DecodeJSON(t, ctx.Session.MakeRequest(t, req, http.StatusOK), []*api.PullRequest{})
indexes := make([]int64, 0, len(listed))
for _, pr := range listed {
indexes = append(indexes, pr.Index)
}
assert.ElementsMatch(t, want, indexes, query)
}
})
t.Run("APIViewPullsByBaseHead", func(t *testing.T) {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls/master/branch2", owner.Name, repo.Name).
AddTokenAuth(ctx.Token)