Skip to content

Commit d0f92cb

Browse files
danigmwxiaoguangsilverwind
authored
Add created_by filter to SearchIssues (#36670)
This patch adds the created_by filter to the SearchIssues method. tea cli has an option to filter by author when listing issues, but it's not working. The tea command line creates this request for the API when using the author filter: ``` $ tea issue list -l local --kind pull -A danigm -vvv http://localhost:3000/api/v1/repos/issues/search?created_by=danigm&labels=&limit=30&milestones=&page=1&state=open&type=pulls ``` This patch fixes the API to allow this kind of queries from go-sdk and tea cli. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
1 parent 0d00629 commit d0f92cb

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

routers/api/v1/repo/issue.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func SearchIssues(ctx *context.APIContext) {
157157
// in: query
158158
// description: Filter by repository owner
159159
// type: string
160+
// - name: created_by
161+
// in: query
162+
// description: Only show items which were created by the given user
163+
// type: string
160164
// - name: team
161165
// in: query
162166
// description: Filter by team (requires organization owner parameter)
@@ -257,6 +261,14 @@ func SearchIssues(ctx *context.APIContext) {
257261
searchOpt.UpdatedBeforeUnix = optional.Some(before)
258262
}
259263

264+
createdByID := getUserIDForFilter(ctx, "created_by")
265+
if ctx.Written() {
266+
return
267+
}
268+
if createdByID > 0 {
269+
searchOpt.PosterID = strconv.FormatInt(createdByID, 10)
270+
}
271+
260272
if ctx.IsSigned {
261273
ctxUserID := ctx.Doer.ID
262274
if ctx.FormBool("created") {

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.

tests/integration/api_issue_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,34 @@ func TestAPISearchIssues(t *testing.T) {
361361
resp = MakeRequest(t, req, http.StatusOK)
362362
DecodeJSON(t, resp, &apiIssues)
363363
assert.Len(t, apiIssues, 2)
364+
365+
query = url.Values{"created": {"1"}} // issues created by the auth user
366+
link.RawQuery = query.Encode()
367+
req = NewRequest(t, "GET", link.String()).AddTokenAuth(token)
368+
resp = MakeRequest(t, req, http.StatusOK)
369+
DecodeJSON(t, resp, &apiIssues)
370+
assert.Len(t, apiIssues, 5)
371+
372+
query = url.Values{"created": {"1"}, "type": {"pulls"}} // prs created by the auth user
373+
link.RawQuery = query.Encode()
374+
req = NewRequest(t, "GET", link.String()).AddTokenAuth(token)
375+
resp = MakeRequest(t, req, http.StatusOK)
376+
DecodeJSON(t, resp, &apiIssues)
377+
assert.Len(t, apiIssues, 3)
378+
379+
query = url.Values{"created_by": {"user2"}} // issues created by the user2
380+
link.RawQuery = query.Encode()
381+
req = NewRequest(t, "GET", link.String()).AddTokenAuth(token)
382+
resp = MakeRequest(t, req, http.StatusOK)
383+
DecodeJSON(t, resp, &apiIssues)
384+
assert.Len(t, apiIssues, 9)
385+
386+
query = url.Values{"created_by": {"user2"}, "type": {"pulls"}} // prs created by user2
387+
link.RawQuery = query.Encode()
388+
req = NewRequest(t, "GET", link.String()).AddTokenAuth(token)
389+
resp = MakeRequest(t, req, http.StatusOK)
390+
DecodeJSON(t, resp, &apiIssues)
391+
assert.Len(t, apiIssues, 3)
364392
}
365393

366394
func TestAPISearchIssuesWithLabels(t *testing.T) {

0 commit comments

Comments
 (0)