Skip to content

Commit f6030da

Browse files
committed
API: add owner filter to repo.ListPullRequests
1 parent fa35ace commit f6030da

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

models/issues/pull_list.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type PullRequestsOptions struct {
2626
SortType string
2727
Labels []int64
2828
MilestoneID int64
29+
OwnerID int64
2930
}
3031

3132
func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullRequestsOptions) *xorm.Session {
@@ -46,6 +47,10 @@ func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullR
4647
sess.And("issue.milestone_id=?", opts.MilestoneID)
4748
}
4849

50+
if opts.OwnerID > 0 {
51+
sess.And("issue.owner_id=?", opts.OwnerID)
52+
}
53+
4954
return sess
5055
}
5156

routers/api/v1/repo/pull.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func ListPullRequests(ctx *context.APIContext) {
8383
// items:
8484
// type: integer
8585
// format: int64
86+
// - name: owner
87+
// in: query
88+
// description: filter by owner
89+
// type: string
8690
// - name: page
8791
// in: query
8892
// description: page number of results to return (1-based)
@@ -102,13 +106,27 @@ func ListPullRequests(ctx *context.APIContext) {
102106
ctx.Error(http.StatusInternalServerError, "PullRequests", err)
103107
return
104108
}
109+
var ownerID int64
110+
if ctx.FormString("owner") != "" {
111+
owner, err := user_model.GetUserByName(ctx, ctx.FormString("owner"))
112+
if err != nil {
113+
if user_model.IsErrUserNotExist(err) {
114+
ctx.Error(http.StatusBadRequest, "Owner not found", err)
115+
} else {
116+
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
117+
}
118+
return
119+
}
120+
ownerID = owner.ID
121+
}
105122
listOptions := utils.GetListOptions(ctx)
106123
prs, maxResults, err := issues_model.PullRequests(ctx, ctx.Repo.Repository.ID, &issues_model.PullRequestsOptions{
107124
ListOptions: listOptions,
108125
State: ctx.FormTrim("state"),
109126
SortType: ctx.FormTrim("sort"),
110127
Labels: labelIDs,
111128
MilestoneID: ctx.FormInt64("milestone"),
129+
OwnerID: ownerID,
112130
})
113131
if err != nil {
114132
ctx.Error(http.StatusInternalServerError, "PullRequests", err)

templates/swagger/v1_json.tmpl

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)