diff options
author | 6543 <6543@obermui.de> | 2022-04-25 16:06:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-25 16:06:24 +0200 |
commit | ddbbe6e15ce411a286c2c9ea4e9fb4107fe3cde5 (patch) | |
tree | 9ec29e551b0a06a3cbc2027aa968d5fc06883a6b /models | |
parent | fe274c148bc516b63aa89ab1904d124e60903421 (diff) | |
download | gitea-ddbbe6e15ce411a286c2c9ea4e9fb4107fe3cde5.tar.gz gitea-ddbbe6e15ce411a286c2c9ea4e9fb4107fe3cde5.zip |
User specific repoID or xorm builder conditions for issue search (#19475)
* extend models.IssuesOptions to have more specific repo filter options
* use new options
* unrelated refactor
* rm RepoIDs
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 21 | ||||
-rw-r--r-- | models/issue_label.go | 7 | ||||
-rw-r--r-- | models/issue_test.go | 5 |
3 files changed, 14 insertions, 19 deletions
diff --git a/models/issue.go b/models/issue.go index 68582b2b14..8bb46bde7e 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1194,7 +1194,8 @@ func GetIssuesByIDs(issueIDs []int64) ([]*Issue, error) { // IssuesOptions represents options of an issue. type IssuesOptions struct { db.ListOptions - RepoIDs []int64 // include all repos if empty + RepoID int64 // overwrites RepoCond if not 0 + RepoCond builder.Cond AssigneeID int64 PosterID int64 MentionedID int64 @@ -1285,15 +1286,15 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) { sess.In("issue.id", opts.IssueIDs) } - if len(opts.RepoIDs) > 0 { - applyReposCondition(sess, opts.RepoIDs) + if opts.RepoID != 0 { + opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoID} + } + if opts.RepoCond != nil { + sess.And(opts.RepoCond) } - switch opts.IsClosed { - case util.OptionalBoolTrue: - sess.And("issue.is_closed=?", true) - case util.OptionalBoolFalse: - sess.And("issue.is_closed=?", false) + if !opts.IsClosed.IsNone() { + sess.And("issue.is_closed=?", opts.IsClosed.IsTrue()) } if opts.AssigneeID > 0 { @@ -1412,10 +1413,6 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati return cond } -func applyReposCondition(sess *xorm.Session, repoIDs []int64) *xorm.Session { - return sess.In("issue.repo_id", repoIDs) -} - func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) *xorm.Session { return sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id"). And("issue_assignees.assignee_id = ?", assigneeID) diff --git a/models/issue_label.go b/models/issue_label.go index 016109e80f..25e6350bc1 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -57,12 +57,9 @@ func (label *Label) CalOpenIssues() { // CalOpenOrgIssues calculates the open issues of a label for a specific repo func (label *Label) CalOpenOrgIssues(repoID, labelID int64) { - repoIDs := []int64{repoID} - labelIDs := []int64{labelID} - counts, _ := CountIssuesByRepo(&IssuesOptions{ - RepoIDs: repoIDs, - LabelIDs: labelIDs, + RepoID: repoID, + LabelIDs: []int64{labelID}, }) for _, count := range counts { diff --git a/models/issue_test.go b/models/issue_test.go index 7893df8a7f..19e1295264 100644 --- a/models/issue_test.go +++ b/models/issue_test.go @@ -21,6 +21,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "github.com/stretchr/testify/assert" + "xorm.io/builder" ) func TestIssue_ReplaceLabels(t *testing.T) { @@ -157,7 +158,7 @@ func TestIssues(t *testing.T) { }, { IssuesOptions{ - RepoIDs: []int64{1, 3}, + RepoCond: builder.In("repo_id", 1, 3), SortType: "oldest", ListOptions: db.ListOptions{ Page: 1, @@ -344,7 +345,7 @@ func TestGetRepoIDsForIssuesOptions(t *testing.T) { }, { IssuesOptions{ - RepoIDs: []int64{1, 2}, + RepoCond: builder.In("repo_id", 1, 2), }, []int64{1, 2}, }, |