-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added issue search via api #3612
Changes from 12 commits
7a54205
5bc4f3f
f3870bf
bfd61f9
752d5b5
b01f5a7
c2542eb
a1211c0
3755d09
7818adc
1bfcb04
38cbfd9
7b08c92
533e1aa
b598149
be9ddba
c5d9b4c
5df8c13
5255550
5f2405d
1db0418
1f209aa
34918c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,15 @@ | |
package repo | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strings" | ||
|
||
api "code.gitea.io/sdk/gitea" | ||
|
||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/indexer" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/util" | ||
) | ||
|
@@ -42,6 +44,10 @@ func ListIssues(ctx *context.APIContext) { | |
// in: query | ||
// description: page number of requested issues | ||
// type: integer | ||
// - name: q | ||
// in: query | ||
// description: search string | ||
// type: string | ||
// responses: | ||
// "200": | ||
// "$ref": "#/responses/IssueList" | ||
|
@@ -55,12 +61,35 @@ func ListIssues(ctx *context.APIContext) { | |
isClosed = util.OptionalBoolFalse | ||
} | ||
|
||
issues, err := models.Issues(&models.IssuesOptions{ | ||
RepoIDs: []int64{ctx.Repo.Repository.ID}, | ||
Page: ctx.QueryInt("page"), | ||
PageSize: setting.UI.IssuePagingNum, | ||
IsClosed: isClosed, | ||
}) | ||
// Define issues var | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comment pls |
||
var issues []*models.Issue | ||
|
||
// Check for search | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comment pls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its obvious from code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah probably 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
keyword := strings.Trim(ctx.Query("q"), " ") | ||
if bytes.Contains([]byte(keyword), []byte{0x00}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
keyword = "" | ||
} | ||
var issueIDs []int64 | ||
var err error | ||
if len(keyword) > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can do something like this:
(simple search function call where you can immediately return empty array instead of doing "if" would be cleaner...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good, thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it |
||
issueIDs, err = indexer.SearchIssuesByKeyword(ctx.Repo.Repository.ID, keyword) | ||
|
||
// Didn't found anything | ||
if len(issueIDs) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But if I don't define it there, I cannot access it in line 83 and 89 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is defined on line 65 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am talking about variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ups, I though you were talking about defining the |
||
issues = []*models.Issue{} | ||
} | ||
} | ||
|
||
if len(keyword) == 0 || len(issueIDs) > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems this line is unnecessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's necessary, but a comment should be added to explain it. At this point, three outcomes are possible:
This condition guards against condition 2, because otherwise models.Issues would just be called and would return all the issues as if no keyword was passed. So, add comment: // We don't fetch any issue if we have keywords, but SearchIssuesByKeyword returned no issue IDs.
// (In other words, we don't fetch issues if no issue matches our keywords) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @thehowl you are right, but we should avoid using another function names (it can be changed and you can not track changes in comments) in comment, just explain "why" that code is needed. IMO your last part is enough:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Morlinest I've added a comment explaining it. |
||
issues, err = models.Issues(&models.IssuesOptions{ | ||
RepoIDs: []int64{ctx.Repo.Repository.ID}, | ||
Page: ctx.QueryInt("page"), | ||
PageSize: setting.UI.IssuePagingNum, | ||
IsClosed: isClosed, | ||
IssueIDs: issueIDs, | ||
}) | ||
} | ||
|
||
if err != nil { | ||
ctx.Error(500, "Issues", err) | ||
return | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.