Skip to content

Commit a82a39d

Browse files
committed
Try fixing your unit tests
1 parent 3a2ffcb commit a82a39d

File tree

11 files changed

+48
-36
lines changed

11 files changed

+48
-36
lines changed

models/issues/issue_project.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func LoadProjectIssueColumnMap(ctx context.Context, projectID, defaultColumnID i
6262
func LoadIssuesFromColumn(ctx context.Context, b *project_model.Column, opts *IssuesOptions) (IssueList, error) {
6363
issueList, err := Issues(ctx, opts.Copy(func(o *IssuesOptions) {
6464
o.ProjectColumnID = b.ID
65-
o.ProjectID = b.ProjectID
65+
o.ProjectIDs = []int64{b.ProjectID}
6666
o.SortType = "project-column-sorting"
6767
}))
6868
if err != nil {
@@ -72,7 +72,7 @@ func LoadIssuesFromColumn(ctx context.Context, b *project_model.Column, opts *Is
7272
if b.Default {
7373
issues, err := Issues(ctx, opts.Copy(func(o *IssuesOptions) {
7474
o.ProjectColumnID = db.NoConditionID
75-
o.ProjectID = b.ProjectID
75+
o.ProjectIDs = []int64{b.ProjectID}
7676
o.SortType = "project-column-sorting"
7777
}))
7878
if err != nil {

models/issues/issue_search.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type IssuesOptions struct { //nolint
3636
ReviewedID int64
3737
SubscriberID int64
3838
MilestoneIDs []int64
39-
ProjectID int64
39+
ProjectIDs []int64
4040
ProjectColumnID int64
4141
IsClosed optional.Option[bool]
4242
IsPull optional.Option[bool]
@@ -196,11 +196,17 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) {
196196
}
197197

198198
func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) {
199-
if opts.ProjectID > 0 { // specific project
200-
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
201-
And("project_issue.project_id=?", opts.ProjectID)
202-
} else if opts.ProjectID == db.NoConditionID { // show those that are in no project
203-
sess.And(builder.NotIn("issue.id", builder.Select("issue_id").From("project_issue").And(builder.Neq{"project_id": 0})))
199+
if len(opts.ProjectIDs) > 0 { // specific project
200+
var includedProjectIDs []int64
201+
for _, projectID := range opts.ProjectIDs {
202+
if projectID > 0 {
203+
includedProjectIDs = append(includedProjectIDs, projectID)
204+
}
205+
}
206+
if len(includedProjectIDs) > 0 {
207+
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
208+
In("project_issue.project_id", includedProjectIDs)
209+
}
204210
}
205211
// opts.ProjectID == 0 means all projects,
206212
// do not need to apply any condition

modules/indexer/issues/bleve/bleve.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,14 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
241241
queries = append(queries, bleve.NewDisjunctionQuery(milestoneQueries...))
242242
}
243243

244-
if options.ProjectID.Has() {
245-
queries = append(queries, inner_bleve.NumericEqualityQuery(options.ProjectID.Value(), "project_id"))
244+
if len(options.ProjectIDs) > 0 {
245+
var projectQueries []query.Query
246+
for _, projectID := range options.ProjectIDs {
247+
projectQueries = append(projectQueries, inner_bleve.NumericEqualityQuery(projectID, "project_id"))
248+
}
249+
queries = append(queries, bleve.NewDisjunctionQuery(projectQueries...))
246250
}
251+
247252
if options.ProjectColumnID.Has() {
248253
queries = append(queries, inner_bleve.NumericEqualityQuery(options.ProjectColumnID.Value(), "project_board_id"))
249254
}

modules/indexer/issues/db/options.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
6565
ReviewRequestedID: convertID(options.ReviewRequestedID),
6666
ReviewedID: convertID(options.ReviewedID),
6767
SubscriberID: convertID(options.SubscriberID),
68-
ProjectID: convertID(options.ProjectID),
6968
ProjectColumnID: convertID(options.ProjectColumnID),
7069
IsClosed: options.IsClosed,
7170
IsPull: options.IsPull,
@@ -88,6 +87,10 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
8887
opts.MilestoneIDs = options.MilestoneIDs
8988
}
9089

90+
if len(options.ProjectIDs) > 0 {
91+
opts.ProjectIDs = options.ProjectIDs
92+
}
93+
9194
if options.NoLabelOnly {
9295
opts.LabelIDs = []int64{0} // Be careful, it's zero, not db.NoConditionID
9396
} else {

modules/indexer/issues/dboptions.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp
4646
searchOpt.MilestoneIDs = opts.MilestoneIDs
4747
}
4848

49-
if opts.ProjectID > 0 {
50-
searchOpt.ProjectID = optional.Some(opts.ProjectID)
51-
} else if opts.ProjectID == db.NoConditionID { // FIXME: this is inconsistent from other places
52-
searchOpt.ProjectID = optional.Some[int64](0) // Those issues with no project(projectid==0)
49+
if len(opts.ProjectIDs) > 0 {
50+
searchOpt.ProjectIDs = opts.ProjectIDs
5351
}
5452

5553
searchOpt.AssigneeID = opts.AssigneeID

modules/indexer/issues/elasticsearch/elasticsearch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
204204
query.Must(elastic.NewTermsQuery("milestone_id", toAnySlice(options.MilestoneIDs)...))
205205
}
206206

207-
if options.ProjectID.Has() {
208-
query.Must(elastic.NewTermQuery("project_id", options.ProjectID.Value()))
207+
if len(options.ProjectIDs) > 0 {
208+
query.Must(elastic.NewTermsQuery("project_id", toAnySlice(options.ProjectIDs)...))
209209
}
210210
if options.ProjectColumnID.Has() {
211211
query.Must(elastic.NewTermQuery("project_board_id", options.ProjectColumnID.Value()))

modules/indexer/issues/internal/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type SearchOptions struct {
9494

9595
MilestoneIDs []int64 // milestones the issues have
9696

97-
ProjectID optional.Option[int64] // project the issues belong to
97+
ProjectIDs []int64 // project the issues belong to
9898
ProjectColumnID optional.Option[int64] // project column the issues belong to
9999

100100
PosterID string // poster of the issues, "(none)" or "(any)" or a user ID

modules/indexer/issues/internal/tests/tests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ var cases = []*testIndexerCase{
307307
Paginator: &db.ListOptions{
308308
PageSize: 5,
309309
},
310-
ProjectID: optional.Some(int64(1)),
310+
ProjectIDs: []int64{1},
311311
},
312312
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
313313
assert.Len(t, result.Hits, 5)
@@ -325,7 +325,7 @@ var cases = []*testIndexerCase{
325325
Paginator: &db.ListOptions{
326326
PageSize: 5,
327327
},
328-
ProjectID: optional.Some(int64(0)),
328+
ProjectIDs: []int64{0},
329329
},
330330
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
331331
assert.Len(t, result.Hits, 5)

modules/indexer/issues/meilisearch/meilisearch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
180180
query.And(inner_meilisearch.NewFilterIn("milestone_id", options.MilestoneIDs...))
181181
}
182182

183-
if options.ProjectID.Has() {
184-
query.And(inner_meilisearch.NewFilterEq("project_id", options.ProjectID.Value()))
183+
if len(options.ProjectIDs) > 0 {
184+
query.And(inner_meilisearch.NewFilterIn("project_id", options.ProjectIDs...))
185185
}
186186
if options.ProjectColumnID.Has() {
187187
query.And(inner_meilisearch.NewFilterEq("project_board_id", options.ProjectColumnID.Value()))

routers/web/repo/issue_list.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func SearchIssues(ctx *context.Context) {
189189
IsClosed: isClosed,
190190
IncludedAnyLabelIDs: includedAnyLabels,
191191
MilestoneIDs: includedMilestones,
192-
ProjectID: projectID,
192+
ProjectIDs: projectID,
193193
SortBy: issue_indexer.SortByCreatedDesc,
194194
}
195195

@@ -345,12 +345,12 @@ func SearchRepoIssuesJSON(ctx *context.Context) {
345345
Page: ctx.FormInt("page"),
346346
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
347347
},
348-
Keyword: keyword,
349-
RepoIDs: []int64{ctx.Repo.Repository.ID},
350-
IsPull: isPull,
351-
IsClosed: isClosed,
352-
ProjectID: projectID,
353-
SortBy: issue_indexer.SortByCreatedDesc,
348+
Keyword: keyword,
349+
RepoIDs: []int64{ctx.Repo.Repository.ID},
350+
IsPull: isPull,
351+
IsClosed: isClosed,
352+
ProjectIDs: projectID,
353+
SortBy: issue_indexer.SortByCreatedDesc,
354354
}
355355
if since != 0 {
356356
searchOpt.UpdatedAfterUnix = optional.Some(since)
@@ -542,7 +542,7 @@ func prepareIssueFilterAndList(ctx *context.Context, milestoneID, projectID int6
542542
RepoIDs: []int64{repo.ID},
543543
LabelIDs: preparedLabelFilter.SelectedLabelIDs,
544544
MilestoneIDs: mileIDs,
545-
ProjectID: projectID,
545+
ProjectIDs: []int64{projectID},
546546
AssigneeID: assigneeID,
547547
MentionedID: mentionedID,
548548
PosterID: posterUserID,
@@ -629,7 +629,7 @@ func prepareIssueFilterAndList(ctx *context.Context, milestoneID, projectID int6
629629
ReviewRequestedID: reviewRequestedID,
630630
ReviewedID: reviewedID,
631631
MilestoneIDs: mileIDs,
632-
ProjectID: projectID,
632+
ProjectIDs: []int64{projectID},
633633
IsClosed: isShowClosed,
634634
IsPull: isPullOption,
635635
LabelIDs: preparedLabelFilter.SelectedLabelIDs,

0 commit comments

Comments
 (0)