mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 08:04:54 +02:00
Try fixing your unit tests
This commit is contained in:
parent
3a2ffcbc97
commit
a82a39d322
@ -62,7 +62,7 @@ func LoadProjectIssueColumnMap(ctx context.Context, projectID, defaultColumnID i
|
|||||||
func LoadIssuesFromColumn(ctx context.Context, b *project_model.Column, opts *IssuesOptions) (IssueList, error) {
|
func LoadIssuesFromColumn(ctx context.Context, b *project_model.Column, opts *IssuesOptions) (IssueList, error) {
|
||||||
issueList, err := Issues(ctx, opts.Copy(func(o *IssuesOptions) {
|
issueList, err := Issues(ctx, opts.Copy(func(o *IssuesOptions) {
|
||||||
o.ProjectColumnID = b.ID
|
o.ProjectColumnID = b.ID
|
||||||
o.ProjectID = b.ProjectID
|
o.ProjectIDs = []int64{b.ProjectID}
|
||||||
o.SortType = "project-column-sorting"
|
o.SortType = "project-column-sorting"
|
||||||
}))
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -72,7 +72,7 @@ func LoadIssuesFromColumn(ctx context.Context, b *project_model.Column, opts *Is
|
|||||||
if b.Default {
|
if b.Default {
|
||||||
issues, err := Issues(ctx, opts.Copy(func(o *IssuesOptions) {
|
issues, err := Issues(ctx, opts.Copy(func(o *IssuesOptions) {
|
||||||
o.ProjectColumnID = db.NoConditionID
|
o.ProjectColumnID = db.NoConditionID
|
||||||
o.ProjectID = b.ProjectID
|
o.ProjectIDs = []int64{b.ProjectID}
|
||||||
o.SortType = "project-column-sorting"
|
o.SortType = "project-column-sorting"
|
||||||
}))
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -36,7 +36,7 @@ type IssuesOptions struct { //nolint
|
|||||||
ReviewedID int64
|
ReviewedID int64
|
||||||
SubscriberID int64
|
SubscriberID int64
|
||||||
MilestoneIDs []int64
|
MilestoneIDs []int64
|
||||||
ProjectID int64
|
ProjectIDs []int64
|
||||||
ProjectColumnID int64
|
ProjectColumnID int64
|
||||||
IsClosed optional.Option[bool]
|
IsClosed optional.Option[bool]
|
||||||
IsPull optional.Option[bool]
|
IsPull optional.Option[bool]
|
||||||
@ -196,11 +196,17 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) {
|
func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) {
|
||||||
if opts.ProjectID > 0 { // specific project
|
if len(opts.ProjectIDs) > 0 { // specific project
|
||||||
|
var includedProjectIDs []int64
|
||||||
|
for _, projectID := range opts.ProjectIDs {
|
||||||
|
if projectID > 0 {
|
||||||
|
includedProjectIDs = append(includedProjectIDs, projectID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(includedProjectIDs) > 0 {
|
||||||
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
|
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
|
||||||
And("project_issue.project_id=?", opts.ProjectID)
|
In("project_issue.project_id", includedProjectIDs)
|
||||||
} else if opts.ProjectID == db.NoConditionID { // show those that are in no project
|
}
|
||||||
sess.And(builder.NotIn("issue.id", builder.Select("issue_id").From("project_issue").And(builder.Neq{"project_id": 0})))
|
|
||||||
}
|
}
|
||||||
// opts.ProjectID == 0 means all projects,
|
// opts.ProjectID == 0 means all projects,
|
||||||
// do not need to apply any condition
|
// do not need to apply any condition
|
||||||
|
@ -241,9 +241,14 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
|
|||||||
queries = append(queries, bleve.NewDisjunctionQuery(milestoneQueries...))
|
queries = append(queries, bleve.NewDisjunctionQuery(milestoneQueries...))
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.ProjectID.Has() {
|
if len(options.ProjectIDs) > 0 {
|
||||||
queries = append(queries, inner_bleve.NumericEqualityQuery(options.ProjectID.Value(), "project_id"))
|
var projectQueries []query.Query
|
||||||
|
for _, projectID := range options.ProjectIDs {
|
||||||
|
projectQueries = append(projectQueries, inner_bleve.NumericEqualityQuery(projectID, "project_id"))
|
||||||
}
|
}
|
||||||
|
queries = append(queries, bleve.NewDisjunctionQuery(projectQueries...))
|
||||||
|
}
|
||||||
|
|
||||||
if options.ProjectColumnID.Has() {
|
if options.ProjectColumnID.Has() {
|
||||||
queries = append(queries, inner_bleve.NumericEqualityQuery(options.ProjectColumnID.Value(), "project_board_id"))
|
queries = append(queries, inner_bleve.NumericEqualityQuery(options.ProjectColumnID.Value(), "project_board_id"))
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,6 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
|
|||||||
ReviewRequestedID: convertID(options.ReviewRequestedID),
|
ReviewRequestedID: convertID(options.ReviewRequestedID),
|
||||||
ReviewedID: convertID(options.ReviewedID),
|
ReviewedID: convertID(options.ReviewedID),
|
||||||
SubscriberID: convertID(options.SubscriberID),
|
SubscriberID: convertID(options.SubscriberID),
|
||||||
ProjectID: convertID(options.ProjectID),
|
|
||||||
ProjectColumnID: convertID(options.ProjectColumnID),
|
ProjectColumnID: convertID(options.ProjectColumnID),
|
||||||
IsClosed: options.IsClosed,
|
IsClosed: options.IsClosed,
|
||||||
IsPull: options.IsPull,
|
IsPull: options.IsPull,
|
||||||
@ -88,6 +87,10 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
|
|||||||
opts.MilestoneIDs = options.MilestoneIDs
|
opts.MilestoneIDs = options.MilestoneIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(options.ProjectIDs) > 0 {
|
||||||
|
opts.ProjectIDs = options.ProjectIDs
|
||||||
|
}
|
||||||
|
|
||||||
if options.NoLabelOnly {
|
if options.NoLabelOnly {
|
||||||
opts.LabelIDs = []int64{0} // Be careful, it's zero, not db.NoConditionID
|
opts.LabelIDs = []int64{0} // Be careful, it's zero, not db.NoConditionID
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,10 +46,8 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp
|
|||||||
searchOpt.MilestoneIDs = opts.MilestoneIDs
|
searchOpt.MilestoneIDs = opts.MilestoneIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.ProjectID > 0 {
|
if len(opts.ProjectIDs) > 0 {
|
||||||
searchOpt.ProjectID = optional.Some(opts.ProjectID)
|
searchOpt.ProjectIDs = opts.ProjectIDs
|
||||||
} else if opts.ProjectID == db.NoConditionID { // FIXME: this is inconsistent from other places
|
|
||||||
searchOpt.ProjectID = optional.Some[int64](0) // Those issues with no project(projectid==0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
searchOpt.AssigneeID = opts.AssigneeID
|
searchOpt.AssigneeID = opts.AssigneeID
|
||||||
|
@ -204,8 +204,8 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
|
|||||||
query.Must(elastic.NewTermsQuery("milestone_id", toAnySlice(options.MilestoneIDs)...))
|
query.Must(elastic.NewTermsQuery("milestone_id", toAnySlice(options.MilestoneIDs)...))
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.ProjectID.Has() {
|
if len(options.ProjectIDs) > 0 {
|
||||||
query.Must(elastic.NewTermQuery("project_id", options.ProjectID.Value()))
|
query.Must(elastic.NewTermsQuery("project_id", toAnySlice(options.ProjectIDs)...))
|
||||||
}
|
}
|
||||||
if options.ProjectColumnID.Has() {
|
if options.ProjectColumnID.Has() {
|
||||||
query.Must(elastic.NewTermQuery("project_board_id", options.ProjectColumnID.Value()))
|
query.Must(elastic.NewTermQuery("project_board_id", options.ProjectColumnID.Value()))
|
||||||
|
@ -94,7 +94,7 @@ type SearchOptions struct {
|
|||||||
|
|
||||||
MilestoneIDs []int64 // milestones the issues have
|
MilestoneIDs []int64 // milestones the issues have
|
||||||
|
|
||||||
ProjectID optional.Option[int64] // project the issues belong to
|
ProjectIDs []int64 // project the issues belong to
|
||||||
ProjectColumnID optional.Option[int64] // project column the issues belong to
|
ProjectColumnID optional.Option[int64] // project column the issues belong to
|
||||||
|
|
||||||
PosterID string // poster of the issues, "(none)" or "(any)" or a user ID
|
PosterID string // poster of the issues, "(none)" or "(any)" or a user ID
|
||||||
|
@ -307,7 +307,7 @@ var cases = []*testIndexerCase{
|
|||||||
Paginator: &db.ListOptions{
|
Paginator: &db.ListOptions{
|
||||||
PageSize: 5,
|
PageSize: 5,
|
||||||
},
|
},
|
||||||
ProjectID: optional.Some(int64(1)),
|
ProjectIDs: []int64{1},
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Len(t, result.Hits, 5)
|
assert.Len(t, result.Hits, 5)
|
||||||
@ -325,7 +325,7 @@ var cases = []*testIndexerCase{
|
|||||||
Paginator: &db.ListOptions{
|
Paginator: &db.ListOptions{
|
||||||
PageSize: 5,
|
PageSize: 5,
|
||||||
},
|
},
|
||||||
ProjectID: optional.Some(int64(0)),
|
ProjectIDs: []int64{0},
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Len(t, result.Hits, 5)
|
assert.Len(t, result.Hits, 5)
|
||||||
|
@ -180,8 +180,8 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
|
|||||||
query.And(inner_meilisearch.NewFilterIn("milestone_id", options.MilestoneIDs...))
|
query.And(inner_meilisearch.NewFilterIn("milestone_id", options.MilestoneIDs...))
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.ProjectID.Has() {
|
if len(options.ProjectIDs) > 0 {
|
||||||
query.And(inner_meilisearch.NewFilterEq("project_id", options.ProjectID.Value()))
|
query.And(inner_meilisearch.NewFilterIn("project_id", options.ProjectIDs...))
|
||||||
}
|
}
|
||||||
if options.ProjectColumnID.Has() {
|
if options.ProjectColumnID.Has() {
|
||||||
query.And(inner_meilisearch.NewFilterEq("project_board_id", options.ProjectColumnID.Value()))
|
query.And(inner_meilisearch.NewFilterEq("project_board_id", options.ProjectColumnID.Value()))
|
||||||
|
@ -189,7 +189,7 @@ func SearchIssues(ctx *context.Context) {
|
|||||||
IsClosed: isClosed,
|
IsClosed: isClosed,
|
||||||
IncludedAnyLabelIDs: includedAnyLabels,
|
IncludedAnyLabelIDs: includedAnyLabels,
|
||||||
MilestoneIDs: includedMilestones,
|
MilestoneIDs: includedMilestones,
|
||||||
ProjectID: projectID,
|
ProjectIDs: projectID,
|
||||||
SortBy: issue_indexer.SortByCreatedDesc,
|
SortBy: issue_indexer.SortByCreatedDesc,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +349,7 @@ func SearchRepoIssuesJSON(ctx *context.Context) {
|
|||||||
RepoIDs: []int64{ctx.Repo.Repository.ID},
|
RepoIDs: []int64{ctx.Repo.Repository.ID},
|
||||||
IsPull: isPull,
|
IsPull: isPull,
|
||||||
IsClosed: isClosed,
|
IsClosed: isClosed,
|
||||||
ProjectID: projectID,
|
ProjectIDs: projectID,
|
||||||
SortBy: issue_indexer.SortByCreatedDesc,
|
SortBy: issue_indexer.SortByCreatedDesc,
|
||||||
}
|
}
|
||||||
if since != 0 {
|
if since != 0 {
|
||||||
@ -542,7 +542,7 @@ func prepareIssueFilterAndList(ctx *context.Context, milestoneID, projectID int6
|
|||||||
RepoIDs: []int64{repo.ID},
|
RepoIDs: []int64{repo.ID},
|
||||||
LabelIDs: preparedLabelFilter.SelectedLabelIDs,
|
LabelIDs: preparedLabelFilter.SelectedLabelIDs,
|
||||||
MilestoneIDs: mileIDs,
|
MilestoneIDs: mileIDs,
|
||||||
ProjectID: projectID,
|
ProjectIDs: []int64{projectID},
|
||||||
AssigneeID: assigneeID,
|
AssigneeID: assigneeID,
|
||||||
MentionedID: mentionedID,
|
MentionedID: mentionedID,
|
||||||
PosterID: posterUserID,
|
PosterID: posterUserID,
|
||||||
@ -629,7 +629,7 @@ func prepareIssueFilterAndList(ctx *context.Context, milestoneID, projectID int6
|
|||||||
ReviewRequestedID: reviewRequestedID,
|
ReviewRequestedID: reviewRequestedID,
|
||||||
ReviewedID: reviewedID,
|
ReviewedID: reviewedID,
|
||||||
MilestoneIDs: mileIDs,
|
MilestoneIDs: mileIDs,
|
||||||
ProjectID: projectID,
|
ProjectIDs: []int64{projectID},
|
||||||
IsClosed: isShowClosed,
|
IsClosed: isShowClosed,
|
||||||
IsPull: isPullOption,
|
IsPull: isPullOption,
|
||||||
LabelIDs: preparedLabelFilter.SelectedLabelIDs,
|
LabelIDs: preparedLabelFilter.SelectedLabelIDs,
|
||||||
|
@ -89,7 +89,7 @@ func MoveIssuesOnProjectColumn(ctx context.Context, doer *user_model.User, colum
|
|||||||
// LoadIssuesFromProject load issues assigned to each project column inside the given project
|
// LoadIssuesFromProject load issues assigned to each project column inside the given project
|
||||||
func LoadIssuesFromProject(ctx context.Context, project *project_model.Project, opts *issues_model.IssuesOptions) (map[int64]issues_model.IssueList, error) {
|
func LoadIssuesFromProject(ctx context.Context, project *project_model.Project, opts *issues_model.IssuesOptions) (map[int64]issues_model.IssueList, error) {
|
||||||
issueList, err := issues_model.Issues(ctx, opts.Copy(func(o *issues_model.IssuesOptions) {
|
issueList, err := issues_model.Issues(ctx, opts.Copy(func(o *issues_model.IssuesOptions) {
|
||||||
o.ProjectID = project.ID
|
o.ProjectIDs = []int64{project.ID}
|
||||||
o.SortType = "project-column-sorting"
|
o.SortType = "project-column-sorting"
|
||||||
}))
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -180,7 +180,7 @@ func LoadIssueNumbersForProject(ctx context.Context, project *project_model.Proj
|
|||||||
|
|
||||||
// for user or org projects, we need to check access permissions
|
// for user or org projects, we need to check access permissions
|
||||||
opts := issues_model.IssuesOptions{
|
opts := issues_model.IssuesOptions{
|
||||||
ProjectID: project.ID,
|
ProjectIDs: []int64{project.ID},
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
AllPublic: doer == nil,
|
AllPublic: doer == nil,
|
||||||
Owner: project.Owner,
|
Owner: project.Owner,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user