diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 41076fd99c..22324e1923 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -157,6 +157,10 @@ func SearchIssues(ctx *context.APIContext) { // in: query // description: Filter by repository owner // type: string + // - name: created_by + // in: query + // description: Only show items which were created by the given user + // type: string // - name: team // in: query // description: Filter by team (requires organization owner parameter) @@ -257,6 +261,14 @@ func SearchIssues(ctx *context.APIContext) { searchOpt.UpdatedBeforeUnix = optional.Some(before) } + createdByID := getUserIDForFilter(ctx, "created_by") + if ctx.Written() { + return + } + if createdByID > 0 { + searchOpt.PosterID = strconv.FormatInt(createdByID, 10) + } + if ctx.IsSigned { ctxUserID := ctx.Doer.ID if ctx.FormBool("created") { diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index a1ecc7fb4f..7b86cc3d45 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -4300,6 +4300,12 @@ "name": "owner", "in": "query" }, + { + "type": "string", + "description": "Only show items which were created by the given user", + "name": "created_by", + "in": "query" + }, { "type": "string", "description": "Filter by team (requires organization owner parameter)", diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index 56bed7db0d..8d85543dc8 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -361,6 +361,34 @@ func TestAPISearchIssues(t *testing.T) { resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) assert.Len(t, apiIssues, 2) + + query = url.Values{"created": {"1"}} // issues created by the auth user + link.RawQuery = query.Encode() + req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) + resp = MakeRequest(t, req, http.StatusOK) + DecodeJSON(t, resp, &apiIssues) + assert.Len(t, apiIssues, 5) + + query = url.Values{"created": {"1"}, "type": {"pulls"}} // prs created by the auth user + link.RawQuery = query.Encode() + req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) + resp = MakeRequest(t, req, http.StatusOK) + DecodeJSON(t, resp, &apiIssues) + assert.Len(t, apiIssues, 3) + + query = url.Values{"created_by": {"user2"}} // issues created by the user2 + link.RawQuery = query.Encode() + req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) + resp = MakeRequest(t, req, http.StatusOK) + DecodeJSON(t, resp, &apiIssues) + assert.Len(t, apiIssues, 9) + + query = url.Values{"created_by": {"user2"}, "type": {"pulls"}} // prs created by user2 + link.RawQuery = query.Encode() + req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) + resp = MakeRequest(t, req, http.StatusOK) + DecodeJSON(t, resp, &apiIssues) + assert.Len(t, apiIssues, 3) } func TestAPISearchIssuesWithLabels(t *testing.T) {