Add filter by owner and team to issue/pulls search endpoint (#16662)

* Filter by owner and team in API issue/pulls search

* Add integration test
This commit is contained in:
Jimmy Praet 2021-08-13 22:47:25 +02:00 committed by GitHub
parent 3a6edd3685
commit a4962a9440
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 87 additions and 3 deletions

View file

@ -87,6 +87,14 @@ func SearchIssues(ctx *context.APIContext) {
// in: query
// description: filter pulls requesting your review, default is false
// type: boolean
// - name: owner
// in: query
// description: filter by owner
// type: string
// - name: team
// in: query
// description: filter by team (requires organization owner parameter to be provided)
// type: string
// - name: page
// in: query
// description: page number of results to return (1-based)
@ -130,6 +138,37 @@ func SearchIssues(ctx *context.APIContext) {
opts.Private = true
opts.AllLimited = true
}
if ctx.FormString("owner") != "" {
owner, err := models.GetUserByName(ctx.FormString("owner"))
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.Error(http.StatusBadRequest, "Owner not found", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
}
return
}
opts.OwnerID = owner.ID
opts.AllLimited = false
opts.AllPublic = false
opts.Collaborate = util.OptionalBoolFalse
}
if ctx.FormString("team") != "" {
if ctx.FormString("owner") == "" {
ctx.Error(http.StatusBadRequest, "", "Owner organisation is required for filtering on team")
return
}
team, err := models.GetTeam(opts.OwnerID, ctx.FormString("team"))
if err != nil {
if models.IsErrTeamNotExist(err) {
ctx.Error(http.StatusBadRequest, "Team not found", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
}
return
}
opts.TeamID = team.ID
}
repoIDs, _, err := models.SearchRepositoryIDs(opts)
if err != nil {