Skip to content

Commit 8d7f1e4

Browse files
authored
User specific repoID or xorm builder conditions for issue search (#19475) (#19476)
1 parent a6b32ad commit 8d7f1e4

File tree

8 files changed

+22
-32
lines changed

8 files changed

+22
-32
lines changed

models/issue.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,8 @@ func GetIssuesByIDs(issueIDs []int64) ([]*Issue, error) {
11651165
// IssuesOptions represents options of an issue.
11661166
type IssuesOptions struct {
11671167
db.ListOptions
1168-
RepoIDs []int64 // include all repos if empty
1168+
RepoID int64 // overwrites RepoCond if not 0
1169+
RepoCond builder.Cond
11691170
AssigneeID int64
11701171
PosterID int64
11711172
MentionedID int64
@@ -1256,15 +1257,15 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
12561257
sess.In("issue.id", opts.IssueIDs)
12571258
}
12581259

1259-
if len(opts.RepoIDs) > 0 {
1260-
applyReposCondition(sess, opts.RepoIDs)
1260+
if opts.RepoID != 0 {
1261+
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoID}
1262+
}
1263+
if opts.RepoCond != nil {
1264+
sess.And(opts.RepoCond)
12611265
}
12621266

1263-
switch opts.IsClosed {
1264-
case util.OptionalBoolTrue:
1265-
sess.And("issue.is_closed=?", true)
1266-
case util.OptionalBoolFalse:
1267-
sess.And("issue.is_closed=?", false)
1267+
if !opts.IsClosed.IsNone() {
1268+
sess.And("issue.is_closed=?", opts.IsClosed.IsTrue())
12681269
}
12691270

12701271
if opts.AssigneeID > 0 {
@@ -1383,10 +1384,6 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *Organizati
13831384
return cond
13841385
}
13851386

1386-
func applyReposCondition(sess *xorm.Session, repoIDs []int64) *xorm.Session {
1387-
return sess.In("issue.repo_id", repoIDs)
1388-
}
1389-
13901387
func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) *xorm.Session {
13911388
return sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
13921389
And("issue_assignees.assignee_id = ?", assigneeID)

models/issue_label.go

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

102102
// CalOpenOrgIssues calculates the open issues of a label for a specific repo
103103
func (label *Label) CalOpenOrgIssues(repoID, labelID int64) {
104-
repoIDs := []int64{repoID}
105-
labelIDs := []int64{labelID}
106-
107104
counts, _ := CountIssuesByRepo(&IssuesOptions{
108-
RepoIDs: repoIDs,
109-
LabelIDs: labelIDs,
105+
RepoID: repoID,
106+
LabelIDs: []int64{labelID},
110107
})
111108

112109
for _, count := range counts {

models/issue_test.go

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

1919
"github.com/stretchr/testify/assert"
20+
"xorm.io/builder"
2021
)
2122

2223
func TestIssue_ReplaceLabels(t *testing.T) {
@@ -153,7 +154,7 @@ func TestIssues(t *testing.T) {
153154
},
154155
{
155156
IssuesOptions{
156-
RepoIDs: []int64{1, 3},
157+
RepoCond: builder.In("repo_id", 1, 3),
157158
SortType: "oldest",
158159
ListOptions: db.ListOptions{
159160
Page: 1,
@@ -340,7 +341,7 @@ func TestGetRepoIDsForIssuesOptions(t *testing.T) {
340341
},
341342
{
342343
IssuesOptions{
343-
RepoIDs: []int64{1, 2},
344+
RepoCond: builder.In("repo_id", 1, 2),
344345
},
345346
[]int64{1, 2},
346347
},

modules/indexer/issues/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func populateIssueIndexer(ctx context.Context) {
272272
// UpdateRepoIndexer add/update all issues of the repositories
273273
func UpdateRepoIndexer(repo *repo_model.Repository) {
274274
is, err := models.Issues(&models.IssuesOptions{
275-
RepoIDs: []int64{repo.ID},
275+
RepoID: repo.ID,
276276
IsClosed: util.OptionalBoolNone,
277277
IsPull: util.OptionalBoolNone,
278278
})

routers/api/v1/repo/issue.go

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

176+
repoCond := models.SearchRepositoryCondition(opts)
176177
repoIDs, _, err := models.SearchRepositoryIDs(opts)
177178
if err != nil {
178179
ctx.Error(http.StatusInternalServerError, "SearchRepositoryByName", err)
@@ -233,7 +234,7 @@ func SearchIssues(ctx *context.APIContext) {
233234
Page: ctx.FormInt("page"),
234235
PageSize: limit,
235236
},
236-
RepoIDs: repoIDs,
237+
RepoCond: repoCond,
237238
IsClosed: isClosed,
238239
IssueIDs: issueIDs,
239240
IncludedLabelNames: includedLabelNames,
@@ -460,7 +461,7 @@ func ListIssues(ctx *context.APIContext) {
460461
if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
461462
issuesOpt := &models.IssuesOptions{
462463
ListOptions: listOptions,
463-
RepoIDs: []int64{ctx.Repo.Repository.ID},
464+
RepoID: ctx.Repo.Repository.ID,
464465
IsClosed: isClosed,
465466
IssueIDs: issueIDs,
466467
LabelIDs: labelIDs,

routers/web/repo/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
226226
Page: pager.Paginater.Current(),
227227
PageSize: setting.UI.IssuePagingNum,
228228
},
229-
RepoIDs: []int64{repo.ID},
229+
RepoID: repo.ID,
230230
AssigneeID: assigneeID,
231231
PosterID: posterID,
232232
MentionedID: mentionedID,

routers/web/user/home.go

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

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

538532
// ------------------------------

services/migrations/gitea_uploader_test.go

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

9999
issues, err := models.Issues(&models.IssuesOptions{
100-
RepoIDs: []int64{repo.ID},
100+
RepoID: repo.ID,
101101
IsPull: util.OptionalBoolFalse,
102102
SortType: "oldest",
103103
})

0 commit comments

Comments
 (0)