Add created_by filter to SearchIssues#36670
Conversation
|
Please run |
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.
ef21795 to
829bbd1
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a created_by query parameter to the SearchIssues API endpoint (GET /repos/issues/search) to enable filtering issues and pull requests by their creator's username. This feature is needed for the tea CLI tool which has an author filter option that was previously not working due to the missing API support.
Changes:
- Added
created_byparameter documentation to SearchIssues swagger comments - Implemented
created_byparameter handling using the existinggetUserIDForFilterhelper - Manually updated swagger JSON template with the new parameter definition
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| routers/api/v1/repo/issue.go | Added swagger documentation and implementation for the created_by query parameter in SearchIssues function |
| templates/swagger/v1_json.tmpl | Manually added created_by parameter definition to the swagger specification (should be auto-generated instead) |
Comments suppressed due to low confidence (1)
routers/api/v1/repo/issue.go:276
- The interaction between
created_byparameter and thecreatedboolean parameter has a logic error. When both parameters are provided, thecreatedboolean (line 274-276) will unconditionally overwrite thesearchOpt.PosterIDvalue set bycreated_by(line 268-270). This means that if a user requests issues created by a specific user viacreated_by=someuserand also setscreated=true, thecreated_byfilter will be ignored and only issues created by the authenticated user will be returned.
The intended behavior should likely be: if created=true is set, it takes precedence (filter by authenticated user). However, if created is not set or false, then created_by should be respected. The fix would be to only set PosterID from the authenticated user if created_by was not already specified, or to document that created=true takes precedence over created_by.
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") {
searchOpt.PosterID = strconv.FormatInt(ctxUserID, 10)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| createdByID := getUserIDForFilter(ctx, "created_by") | ||
| if ctx.Written() { | ||
| return | ||
| } | ||
| if createdByID > 0 { | ||
| searchOpt.PosterID = strconv.FormatInt(createdByID, 10) | ||
| } |
There was a problem hiding this comment.
The new created_by parameter lacks test coverage. The existing test file tests/integration/api_issue_test.go has a TestAPISearchIssues function that tests various filters (assigned, milestones, owner, team), but does not include tests for the new created_by parameter. Consider adding test cases that verify:
- Filtering by a specific user with
created_by=username - The interaction between
created=trueandcreated_by=username - Error handling when the specified user doesn't exist
|
Would be good to add a test case into |
I've just added a new commit with the new test case |
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:
This patch fixes the API to allow this kind of queries from go-sdk and tea cli.