diff options
author | Brad Albright <32200834+bhalbright@users.noreply.github.com> | 2019-10-31 00:06:10 -0500 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-10-31 13:06:10 +0800 |
commit | 887a8fe2422ed783ae0968fccc269bdfb6a39595 (patch) | |
tree | c5ebb25091122d5b8cb956311e0f6ce2d9fa60d7 /modules/indexer/issues | |
parent | 086a46994a9f59ba06bfacdf2041817ef2f6671c (diff) | |
download | gitea-887a8fe2422ed783ae0968fccc269bdfb6a39595.tar.gz gitea-887a8fe2422ed783ae0968fccc269bdfb6a39595.zip |
Allow cross-repository dependencies on issues (#7901)
* in progress changes for #7405, added ability to add cross-repo dependencies
* removed unused repolink var
* fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes
* reverted removal of string in local files becasue these are done via crowdin, not updated manually
* removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review
* changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result
* simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository
* made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line)
* replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard
* some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies
* added Name to the RepositoryMeta struct
* updated swagger doc
* fixed total count for link header on SearchIssues
* fixed indentation
* fixed aligment of remove icon on dependencies in issue sidebar
* removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block)
* reverting .css change, somehow missed or forgot that less is used
* updated less file and generated css; updated sidebar template with styles to line up delete and issue index
* added ordering to the blocked by/depends on queries
* fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository)
* re-applied my swagger changes after merge
* fixed split string condition in issue search
* changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter
* when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled
* updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here
* fixed incorrect setting of user id parameter in search repos call
Diffstat (limited to 'modules/indexer/issues')
-rw-r--r-- | modules/indexer/issues/bleve.go | 16 | ||||
-rw-r--r-- | modules/indexer/issues/bleve_test.go | 2 | ||||
-rw-r--r-- | modules/indexer/issues/db.go | 7 | ||||
-rw-r--r-- | modules/indexer/issues/indexer.go | 11 | ||||
-rw-r--r-- | modules/indexer/issues/indexer_test.go | 16 |
5 files changed, 29 insertions, 23 deletions
diff --git a/modules/indexer/issues/bleve.go b/modules/indexer/issues/bleve.go index 36279198b8..24443e54a3 100644 --- a/modules/indexer/issues/bleve.go +++ b/modules/indexer/issues/bleve.go @@ -218,9 +218,18 @@ func (b *BleveIndexer) Delete(ids ...int64) error { // Search searches for issues by given conditions. // Returns the matching issue IDs -func (b *BleveIndexer) Search(keyword string, repoID int64, limit, start int) (*SearchResult, error) { +func (b *BleveIndexer) Search(keyword string, repoIDs []int64, limit, start int) (*SearchResult, error) { + var repoQueriesP []*query.NumericRangeQuery + for _, repoID := range repoIDs { + repoQueriesP = append(repoQueriesP, numericEqualityQuery(repoID, "RepoID")) + } + repoQueries := make([]query.Query, len(repoQueriesP)) + for i, v := range repoQueriesP { + repoQueries[i] = query.Query(v) + } + indexerQuery := bleve.NewConjunctionQuery( - numericEqualityQuery(repoID, "RepoID"), + bleve.NewDisjunctionQuery(repoQueries...), bleve.NewDisjunctionQuery( newMatchPhraseQuery(keyword, "Title", issueIndexerAnalyzer), newMatchPhraseQuery(keyword, "Content", issueIndexerAnalyzer), @@ -242,8 +251,7 @@ func (b *BleveIndexer) Search(keyword string, repoID int64, limit, start int) (* return nil, err } ret.Hits = append(ret.Hits, Match{ - ID: id, - RepoID: repoID, + ID: id, }) } return &ret, nil diff --git a/modules/indexer/issues/bleve_test.go b/modules/indexer/issues/bleve_test.go index 8ec274566f..94d935d89d 100644 --- a/modules/indexer/issues/bleve_test.go +++ b/modules/indexer/issues/bleve_test.go @@ -76,7 +76,7 @@ func TestBleveIndexAndSearch(t *testing.T) { ) for _, kw := range keywords { - res, err := indexer.Search(kw.Keyword, 2, 10, 0) + res, err := indexer.Search(kw.Keyword, []int64{2}, 10, 0) assert.NoError(t, err) var ids = make([]int64, 0, len(res.Hits)) diff --git a/modules/indexer/issues/db.go b/modules/indexer/issues/db.go index 6e7f0c1a6e..7d4e389471 100644 --- a/modules/indexer/issues/db.go +++ b/modules/indexer/issues/db.go @@ -26,8 +26,8 @@ func (db *DBIndexer) Delete(ids ...int64) error { } // Search dummy function -func (db *DBIndexer) Search(kw string, repoID int64, limit, start int) (*SearchResult, error) { - total, ids, err := models.SearchIssueIDsByKeyword(kw, repoID, limit, start) +func (db *DBIndexer) Search(kw string, repoIDs []int64, limit, start int) (*SearchResult, error) { + total, ids, err := models.SearchIssueIDsByKeyword(kw, repoIDs, limit, start) if err != nil { return nil, err } @@ -37,8 +37,7 @@ func (db *DBIndexer) Search(kw string, repoID int64, limit, start int) (*SearchR } for _, id := range ids { result.Hits = append(result.Hits, Match{ - ID: id, - RepoID: repoID, + ID: id, }) } return &result, nil diff --git a/modules/indexer/issues/indexer.go b/modules/indexer/issues/indexer.go index 4f410daf4c..76da46d759 100644 --- a/modules/indexer/issues/indexer.go +++ b/modules/indexer/issues/indexer.go @@ -28,9 +28,8 @@ type IndexerData struct { // Match represents on search result type Match struct { - ID int64 `json:"id"` - RepoID int64 `json:"repo_id"` - Score float64 `json:"score"` + ID int64 `json:"id"` + Score float64 `json:"score"` } // SearchResult represents search results @@ -44,7 +43,7 @@ type Indexer interface { Init() (bool, error) Index(issue []*IndexerData) error Delete(ids ...int64) error - Search(kw string, repoID int64, limit, start int) (*SearchResult, error) + Search(kw string, repoIDs []int64, limit, start int) (*SearchResult, error) } type indexerHolder struct { @@ -262,9 +261,9 @@ func DeleteRepoIssueIndexer(repo *models.Repository) { } // SearchIssuesByKeyword search issue ids by keywords and repo id -func SearchIssuesByKeyword(repoID int64, keyword string) ([]int64, error) { +func SearchIssuesByKeyword(repoIDs []int64, keyword string) ([]int64, error) { var issueIDs []int64 - res, err := holder.get().Search(keyword, repoID, 1000, 0) + res, err := holder.get().Search(keyword, repoIDs, 1000, 0) if err != nil { return nil, err } diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index 212c2edfbe..a45fede9ac 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -30,19 +30,19 @@ func TestBleveSearchIssues(t *testing.T) { time.Sleep(5 * time.Second) - ids, err := SearchIssuesByKeyword(1, "issue2") + ids, err := SearchIssuesByKeyword([]int64{1}, "issue2") assert.NoError(t, err) assert.EqualValues(t, []int64{2}, ids) - ids, err = SearchIssuesByKeyword(1, "first") + ids, err = SearchIssuesByKeyword([]int64{1}, "first") assert.NoError(t, err) assert.EqualValues(t, []int64{1}, ids) - ids, err = SearchIssuesByKeyword(1, "for") + ids, err = SearchIssuesByKeyword([]int64{1}, "for") assert.NoError(t, err) assert.EqualValues(t, []int64{1, 2, 3, 5}, ids) - ids, err = SearchIssuesByKeyword(1, "good") + ids, err = SearchIssuesByKeyword([]int64{1}, "good") assert.NoError(t, err) assert.EqualValues(t, []int64{1}, ids) } @@ -53,19 +53,19 @@ func TestDBSearchIssues(t *testing.T) { setting.Indexer.IssueType = "db" InitIssueIndexer(true) - ids, err := SearchIssuesByKeyword(1, "issue2") + ids, err := SearchIssuesByKeyword([]int64{1}, "issue2") assert.NoError(t, err) assert.EqualValues(t, []int64{2}, ids) - ids, err = SearchIssuesByKeyword(1, "first") + ids, err = SearchIssuesByKeyword([]int64{1}, "first") assert.NoError(t, err) assert.EqualValues(t, []int64{1}, ids) - ids, err = SearchIssuesByKeyword(1, "for") + ids, err = SearchIssuesByKeyword([]int64{1}, "for") assert.NoError(t, err) assert.EqualValues(t, []int64{1, 2, 3, 5}, ids) - ids, err = SearchIssuesByKeyword(1, "good") + ids, err = SearchIssuesByKeyword([]int64{1}, "good") assert.NoError(t, err) assert.EqualValues(t, []int64{1}, ids) } |