From 024871ade60c619302430a2852018dcbd1b35b79 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Mon, 4 Feb 2019 16:20:44 +0100 Subject: Add label names as filter in issue search api (#5946) --- routers/api/v1/repo/issue.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'routers/api/v1') diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index fe00715949..1cb9c2f819 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -43,6 +43,10 @@ func ListIssues(ctx *context.APIContext) { // in: query // description: whether issue is open or closed // type: string + // - name: labels + // in: query + // description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded + // type: string // - name: page // in: query // description: page number of requested issues @@ -71,20 +75,30 @@ func ListIssues(ctx *context.APIContext) { keyword = "" } var issueIDs []int64 + var labelIDs []int64 var err error if len(keyword) > 0 { issueIDs, err = indexer.SearchIssuesByKeyword(ctx.Repo.Repository.ID, keyword) } + if splitted := strings.Split(ctx.Query("labels"), ","); len(splitted) > 0 { + labelIDs, err = models.GetLabelIDsInRepoByNames(ctx.Repo.Repository.ID, splitted) + if err != nil { + ctx.Error(500, "GetLabelIDsInRepoByNames", err) + return + } + } + // Only fetch the issues if we either don't have a keyword or the search returned issues // This would otherwise return all issues if no issues were found by the search. - if len(keyword) == 0 || len(issueIDs) > 0 { + if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 { issues, err = models.Issues(&models.IssuesOptions{ RepoIDs: []int64{ctx.Repo.Repository.ID}, Page: ctx.QueryInt("page"), PageSize: setting.UI.IssuePagingNum, IsClosed: isClosed, IssueIDs: issueIDs, + LabelIDs: labelIDs, }) } -- cgit v1.2.3