Skip to content

Commit ddbbe6e

Browse files
authored
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
1 parent fe274c1 commit ddbbe6e

File tree

8 files changed

+25
-34
lines changed

8 files changed

+25
-34
lines changed

models/issue.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,8 @@ func GetIssuesByIDs(issueIDs []int64) ([]*Issue, error) {
11941194
// IssuesOptions represents options of an issue.
11951195
type IssuesOptions struct {
11961196
db.ListOptions
1197-
RepoIDs []int64 // include all repos if empty
1197+
RepoID int64 // overwrites RepoCond if not 0
1198+
RepoCond builder.Cond
11981199
AssigneeID int64
11991200
PosterID int64
12001201
MentionedID int64
@@ -1285,15 +1286,15 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
12851286
sess.In("issue.id", opts.IssueIDs)
12861287
}
12871288

1288-
if len(opts.RepoIDs) > 0 {
1289-
applyReposCondition(sess, opts.RepoIDs)
1289+
if opts.RepoID != 0 {
1290+
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoID}
1291+
}
1292+
if opts.RepoCond != nil {
1293+
sess.And(opts.RepoCond)
12901294
}
12911295

1292-
switch opts.IsClosed {
1293-
case util.OptionalBoolTrue:
1294-
sess.And("issue.is_closed=?", true)
1295-
case util.OptionalBoolFalse:
1296-
sess.And("issue.is_closed=?", false)
1296+
if !opts.IsClosed.IsNone() {
1297+
sess.And("issue.is_closed=?", opts.IsClosed.IsTrue())
12971298
}
12981299

12991300
if opts.AssigneeID > 0 {
@@ -1412,10 +1413,6 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
14121413
return cond
14131414
}
14141415

1415-
func applyReposCondition(sess *xorm.Session, repoIDs []int64) *xorm.Session {
1416-
return sess.In("issue.repo_id", repoIDs)
1417-
}
1418-
14191416
func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) *xorm.Session {
14201417
return sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
14211418
And("issue_assignees.assignee_id = ?", assigneeID)

models/issue_label.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ func (label *Label) CalOpenIssues() {
5757

5858
// CalOpenOrgIssues calculates the open issues of a label for a specific repo
5959
func (label *Label) CalOpenOrgIssues(repoID, labelID int64) {
60-
repoIDs := []int64{repoID}
61-
labelIDs := []int64{labelID}
62-
6360
counts, _ := CountIssuesByRepo(&IssuesOptions{
64-
RepoIDs: repoIDs,
65-
LabelIDs: labelIDs,
61+
RepoID: repoID,
62+
LabelIDs: []int64{labelID},
6663
})
6764

6865
for _, count := range counts {

models/issue_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
user_model "code.gitea.io/gitea/models/user"
2222

2323
"github.com/stretchr/testify/assert"
24+
"xorm.io/builder"
2425
)
2526

2627
func TestIssue_ReplaceLabels(t *testing.T) {
@@ -157,7 +158,7 @@ func TestIssues(t *testing.T) {
157158
},
158159
{
159160
IssuesOptions{
160-
RepoIDs: []int64{1, 3},
161+
RepoCond: builder.In("repo_id", 1, 3),
161162
SortType: "oldest",
162163
ListOptions: db.ListOptions{
163164
Page: 1,
@@ -344,7 +345,7 @@ func TestGetRepoIDsForIssuesOptions(t *testing.T) {
344345
},
345346
{
346347
IssuesOptions{
347-
RepoIDs: []int64{1, 2},
348+
RepoCond: builder.In("repo_id", 1, 2),
348349
},
349350
[]int64{1, 2},
350351
},

modules/indexer/issues/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func populateIssueIndexer(ctx context.Context) {
321321
// UpdateRepoIndexer add/update all issues of the repositories
322322
func UpdateRepoIndexer(repo *repo_model.Repository) {
323323
is, err := models.Issues(&models.IssuesOptions{
324-
RepoIDs: []int64{repo.ID},
324+
RepoID: repo.ID,
325325
IsClosed: util.OptionalBoolNone,
326326
IsPull: util.OptionalBoolNone,
327327
})

routers/api/v1/repo/issue.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func SearchIssues(ctx *context.APIContext) {
175175
opts.TeamID = team.ID
176176
}
177177

178+
repoCond := models.SearchRepositoryCondition(opts)
178179
repoIDs, _, err := models.SearchRepositoryIDs(opts)
179180
if err != nil {
180181
ctx.Error(http.StatusInternalServerError, "SearchRepositoryByName", err)
@@ -235,7 +236,7 @@ func SearchIssues(ctx *context.APIContext) {
235236
Page: ctx.FormInt("page"),
236237
PageSize: limit,
237238
},
238-
RepoIDs: repoIDs,
239+
RepoCond: repoCond,
239240
IsClosed: isClosed,
240241
IssueIDs: issueIDs,
241242
IncludedLabelNames: includedLabelNames,
@@ -462,7 +463,7 @@ func ListIssues(ctx *context.APIContext) {
462463
if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
463464
issuesOpt := &models.IssuesOptions{
464465
ListOptions: listOptions,
465-
RepoIDs: []int64{ctx.Repo.Repository.ID},
466+
RepoID: ctx.Repo.Repository.ID,
466467
IsClosed: isClosed,
467468
IssueIDs: issueIDs,
468469
LabelIDs: labelIDs,

routers/web/repo/issue.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
232232
Page: pager.Paginater.Current(),
233233
PageSize: setting.UI.IssuePagingNum,
234234
},
235-
RepoIDs: []int64{repo.ID},
235+
RepoID: repo.ID,
236236
AssigneeID: assigneeID,
237237
PosterID: posterID,
238238
MentionedID: mentionedID,
@@ -2167,6 +2167,7 @@ func SearchIssues(ctx *context.Context) {
21672167
opts.TeamID = team.ID
21682168
}
21692169

2170+
repoCond := models.SearchRepositoryCondition(opts)
21702171
repoIDs, _, err := models.SearchRepositoryIDs(opts)
21712172
if err != nil {
21722173
ctx.Error(http.StatusInternalServerError, "SearchRepositoryByName", err.Error())
@@ -2227,7 +2228,7 @@ func SearchIssues(ctx *context.Context) {
22272228
Page: ctx.FormInt("page"),
22282229
PageSize: limit,
22292230
},
2230-
RepoIDs: repoIDs,
2231+
RepoCond: repoCond,
22312232
IsClosed: isClosed,
22322233
IssueIDs: issueIDs,
22332234
IncludedLabelNames: includedLabelNames,
@@ -2403,7 +2404,7 @@ func ListIssues(ctx *context.Context) {
24032404
if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
24042405
issuesOpt := &models.IssuesOptions{
24052406
ListOptions: listOptions,
2406-
RepoIDs: []int64{ctx.Repo.Repository.ID},
2407+
RepoID: ctx.Repo.Repository.ID,
24072408
IsClosed: isClosed,
24082409
IssueIDs: issueIDs,
24092410
LabelIDs: labelIDs,

routers/web/user/home.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
463463
// to check if it's in the team(which possible isn't the case).
464464
opts.User = nil
465465
}
466-
userRepoIDs, _, err := models.SearchRepositoryIDs(repoOpts)
467-
if err != nil {
468-
ctx.ServerError("models.SearchRepositoryIDs: %v", err)
469-
return
470-
}
471-
472-
opts.RepoIDs = userRepoIDs
466+
opts.RepoCond = models.SearchRepositoryCondition(repoOpts)
473467
}
474468

475469
// keyword holds the search term entered into the search field.
@@ -533,7 +527,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
533527
// Gets set when clicking filters on the issues overview page.
534528
repoIDs := getRepoIDs(ctx.FormString("repos"))
535529
if len(repoIDs) > 0 {
536-
opts.RepoIDs = repoIDs
530+
opts.RepoCond = builder.In("issue.repo_id", repoIDs)
537531
}
538532

539533
// ------------------------------

services/migrations/gitea_uploader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestGiteaUploadRepo(t *testing.T) {
105105
assert.Len(t, releases, 1)
106106

107107
issues, err := models.Issues(&models.IssuesOptions{
108-
RepoIDs: []int64{repo.ID},
108+
RepoID: repo.ID,
109109
IsPull: util.OptionalBoolFalse,
110110
SortType: "oldest",
111111
})

0 commit comments

Comments
 (0)