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.
|
Would be good to add a test case into |
I've just added a new commit with the new test case |
834ca6f to
491f222
Compare
* main: (24 commits) Instance-wide (global) info banner and maintenance mode (go-gitea#36571) Add created_by filter to SearchIssues (go-gitea#36670) Inline and lazy-load EasyMDE CSS, fix border colors (go-gitea#36714) Fix release draft access check logic (go-gitea#36720) Change image transparency grid to CSS (go-gitea#36711) Avoid opening new tab when downloading actions logs (go-gitea#36740) Add validation constraints for repository creation fields (go-gitea#36671) Fix SVG height calculation in diff viewer (go-gitea#36748) Fix path resolving (go-gitea#36734) [skip ci] Updated translations via Crowdin Fix track time list permission check (go-gitea#36662) Fix incorrect setting loading order (go-gitea#36735) Use case-insensitive matching for Git error "Not a valid object name" (go-gitea#36728) feat: Add workflow dependencies visualization (go-gitea#36248) Add keyboard shortcuts for repository file and code search (go-gitea#36416) Refactor text utility classes to Tailwind CSS (go-gitea#36703) Prevent redirect bypasses via backslash-encoded paths (go-gitea#36660) Fix force push time-line commit comments of pull request (go-gitea#36653) Fix get release draft permission check (go-gitea#36659) Move `X_FRAME_OPTIONS` setting from `cors` to `security` section (go-gitea#30256) ... # Conflicts: # web_src/css/base.css # web_src/css/index.css
* giteaofficial/main: Filter out untracked files from spellchecking (go-gitea#36756) Fix CSS stacking context issue in actions log (go-gitea#36749) Fix milestone/project text overflow in issue sidebar (go-gitea#36741) Update tool dependencies and fix new lint issues (go-gitea#36702) Instance-wide (global) info banner and maintenance mode (go-gitea#36571) Add created_by filter to SearchIssues (go-gitea#36670) Inline and lazy-load EasyMDE CSS, fix border colors (go-gitea#36714)
* origin/main: Move Fomantic dropdown CSS to custom module (go-gitea#36530) Use "Enable Gravatar" but not "Disable" (go-gitea#36771) feat: add branch_count to repository API (go-gitea#35351) (go-gitea#36743) Deprecate RenderWithErr (go-gitea#36769) Lazy-load some Vue components, fix heatmap chunk loading on every page (go-gitea#36719) Filter out untracked files from spellchecking (go-gitea#36756) Fix CSS stacking context issue in actions log (go-gitea#36749) Fix milestone/project text overflow in issue sidebar (go-gitea#36741) Update tool dependencies and fix new lint issues (go-gitea#36702) Instance-wide (global) info banner and maintenance mode (go-gitea#36571) Add created_by filter to SearchIssues (go-gitea#36670) Inline and lazy-load EasyMDE CSS, fix border colors (go-gitea#36714) # Conflicts: # templates/repo/issue/view_content/pull_merge_box.tmpl # web_src/js/features/repo-issue-pull.ts
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.