diff options
author | Jimmy Praet <jimmy.praet@telenet.be> | 2021-08-13 22:47:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-13 22:47:25 +0200 |
commit | a4962a944002c3d3949520949f964aae7ff478ed (patch) | |
tree | e9e82d3fd7e88092577610f067c4befbd1550162 /routers | |
parent | 3a6edd36851b266612f3d325bebc716fc60bfed5 (diff) | |
download | gitea-a4962a944002c3d3949520949f964aae7ff478ed.tar.gz gitea-a4962a944002c3d3949520949f964aae7ff478ed.zip |
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
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index ff003b840b..e8ef2f3d05 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -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 { |