Skip to content

Commit f04f7c9

Browse files
authored
Merge branch 'master' into add-api-issues-subscriptions
2 parents 89c5ba9 + cb1048d commit f04f7c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+6128
-3795
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ DEFAULT_ORG_MEMBER_VISIBLE = false
479479
; Default value for EnableDependencies
480480
; Repositories will use dependencies by default depending on this setting
481481
DEFAULT_ENABLE_DEPENDENCIES = true
482+
; Dependencies can be added from any repository where the user is granted access or only from the current repository depending on this setting.
483+
ALLOW_CROSS_REPOSITORY_DEPENDENCIES = true
482484
; Enable heatmap on users profiles.
483485
ENABLE_USER_HEATMAP = true
484486
; Enable Timetracking

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ relation to port exhaustion.
297297
- `RECAPTCHA_SITEKEY`: **""**: Go to https://www.google.com/recaptcha/admin to get a sitekey for recaptcha.
298298
- `RECAPTCHA_URL`: **https://www.google.com/recaptcha/**: Set the recaptcha url - allows the use of recaptcha net.
299299
- `DEFAULT_ENABLE_DEPENDENCIES`: **true**: Enable this to have dependencies enabled by default.
300+
- `ALLOW_CROSS_REPOSITORY_DEPENDENCIES` : **true** Enable this to allow dependencies on issues from any repository where the user is granted access.
300301
- `ENABLE_USER_HEATMAP`: **true**: Enable this to display the heatmap on users profiles.
301302
- `EMAIL_DOMAIN_WHITELIST`: **\<empty\>**: If non-empty, list of domain names that can only be used to register
302303
on this instance.

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ require (
2222
github.com/blevesearch/go-porterstemmer v0.0.0-20141230013033-23a2c8e5cf1f // indirect
2323
github.com/blevesearch/segment v0.0.0-20160105220820-db70c57796cc // indirect
2424
github.com/boombuler/barcode v0.0.0-20161226211916-fe0f26ff6d26 // indirect
25-
github.com/chaseadamsio/goorgeous v0.0.0-20170901132237-098da33fde5f
2625
github.com/couchbase/vellum v0.0.0-20190111184608-e91b68ff3efe // indirect
2726
github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d // indirect
2827
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect
@@ -73,19 +72,21 @@ require (
7372
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae // indirect
7473
github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc
7574
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5
75+
github.com/niklasfasching/go-org v0.1.7
7676
github.com/oliamb/cutter v0.2.2
7777
github.com/philhofer/fwd v1.0.0 // indirect
7878
github.com/pkg/errors v0.8.1
7979
github.com/pquerna/otp v0.0.0-20160912161815-54653902c20e
8080
github.com/prometheus/client_golang v1.1.0
8181
github.com/prometheus/procfs v0.0.4 // indirect
8282
github.com/remyoudompheng/bigfft v0.0.0-20190321074620-2f0d2b0e0001 // indirect
83-
github.com/russross/blackfriday v0.0.0-20180428102519-11635eb403ff
83+
github.com/russross/blackfriday v2.0.0+incompatible // indirect
84+
github.com/russross/blackfriday/v2 v2.0.1
8485
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
8586
github.com/satori/go.uuid v1.2.0
8687
github.com/sergi/go-diff v1.0.0
8788
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b // indirect
88-
github.com/shurcooL/sanitized_anchor_name v0.0.0-20160918041101-1dba4b3954bc // indirect
89+
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
8990
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
9091
github.com/steveyen/gtreap v0.0.0-20150807155958-0abe01ef9be2 // indirect
9192
github.com/stretchr/testify v1.4.0
@@ -100,7 +101,7 @@ require (
100101
github.com/willf/bitset v0.0.0-20180426185212-8ce1146b8621 // indirect
101102
github.com/yohcop/openid-go v0.0.0-20160914080427-2c050d2dae53
102103
golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad
103-
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b
104+
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271
104105
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
105106
golang.org/x/sys v0.0.0-20190910064555-bbd175535a8b
106107
golang.org/x/text v0.3.2

go.sum

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ github.com/boombuler/barcode v0.0.0-20161226211916-fe0f26ff6d26/go.mod h1:paBWMc
8686
github.com/bradfitz/gomemcache v0.0.0-20190329173943-551aad21a668 h1:U/lr3Dgy4WK+hNk4tyD+nuGjpVLPEHuJSFXMw11/HPA=
8787
github.com/bradfitz/gomemcache v0.0.0-20190329173943-551aad21a668/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
8888
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
89-
github.com/chaseadamsio/goorgeous v0.0.0-20170901132237-098da33fde5f h1:REH9VH5ubNR0skLaOxK7TRJeRbE2dDfvaouQo8FsRcA=
90-
github.com/chaseadamsio/goorgeous v0.0.0-20170901132237-098da33fde5f/go.mod h1:6QaC0vFoKWYDth94dHFNgRT2YkT5FHdQp/Yx15aAAi0=
9189
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
9290
github.com/corbym/gocrest v1.0.3 h1:gwEdq6RkTmq+09CTuM29DfKOCtZ7G7bcyxs3IZ6EVdU=
9391
github.com/corbym/gocrest v1.0.3/go.mod h1:maVFL5lbdS2PgfOQgGRWDYTeunSWQeiEgoNdTABShCs=
@@ -425,6 +423,10 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
425423
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
426424
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY=
427425
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
426+
github.com/niklasfasching/go-org v0.1.6 h1:F521WcqRNl8OJumlgAnekZgERaTA2HpfOYYfVEKOeI8=
427+
github.com/niklasfasching/go-org v0.1.6/go.mod h1:AsLD6X7djzRIz4/RFZu8vwRL0VGjUvGZCCH1Nz0VdrU=
428+
github.com/niklasfasching/go-org v0.1.7 h1:t3V+3XnS/7BhKv/7SlMUa8FvAiq577/a1T3D7mLIRXE=
429+
github.com/niklasfasching/go-org v0.1.7/go.mod h1:AsLD6X7djzRIz4/RFZu8vwRL0VGjUvGZCCH1Nz0VdrU=
428430
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
429431
github.com/oliamb/cutter v0.2.2 h1:Lfwkya0HHNU1YLnGv2hTkzHfasrSMkgv4Dn+5rmlk3k=
430432
github.com/oliamb/cutter v0.2.2/go.mod h1:4BenG2/4GuRBDbVm/OPahDVqbrOemzpPiG5mi1iryBU=
@@ -487,8 +489,10 @@ github.com/remyoudompheng/bigfft v0.0.0-20190321074620-2f0d2b0e0001/go.mod h1:qq
487489
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
488490
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
489491
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
490-
github.com/russross/blackfriday v0.0.0-20180428102519-11635eb403ff h1:g9ZlAHmkc/h5So+OjNCkZWh+FjuKEOOOoyRkqlGA8+c=
491-
github.com/russross/blackfriday v0.0.0-20180428102519-11635eb403ff/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
492+
github.com/russross/blackfriday v2.0.0+incompatible h1:cBXrhZNUf9C+La9/YpS+UHpUT8YD6Td9ZMSU9APFcsk=
493+
github.com/russross/blackfriday v2.0.0+incompatible/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
494+
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
495+
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
492496
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca h1:NugYot0LIVPxTvN8n+Kvkn6TrbMyxQiuvKdEwFdR9vI=
493497
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
494498
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
@@ -499,6 +503,8 @@ github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b h1:4kg1wyftSKxLtnP
499503
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
500504
github.com/shurcooL/sanitized_anchor_name v0.0.0-20160918041101-1dba4b3954bc h1:3wIrJvFb3Pf6B/2mDBnN1G5IfUVev4X5apadQlWOczE=
501505
github.com/shurcooL/sanitized_anchor_name v0.0.0-20160918041101-1dba4b3954bc/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
506+
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
507+
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
502508
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
503509
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
504510
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
@@ -650,6 +656,8 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k
650656
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
651657
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b h1:XfVGCX+0T4WOStkaOsJRllbsiImhB2jgVBGc9L0lPGc=
652658
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
659+
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271 h1:N66aaryRB3Ax92gH0v3hp1QYZ3zWWCCUR/j8Ifh45Ss=
660+
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
653661
golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
654662
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
655663
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI=

models/issue.go

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path"
1010
"regexp"
1111
"sort"
12+
"strconv"
1213
"strings"
1314

1415
"code.gitea.io/gitea/modules/base"
@@ -378,6 +379,12 @@ func (issue *Issue) apiFormat(e Engine) *api.Issue {
378379
Updated: issue.UpdatedUnix.AsTime(),
379380
}
380381

382+
apiIssue.Repo = &api.RepositoryMeta{
383+
ID: issue.Repo.ID,
384+
Name: issue.Repo.Name,
385+
FullName: issue.Repo.FullName(),
386+
}
387+
381388
if issue.ClosedUnix != 0 {
382389
apiIssue.Closed = issue.ClosedUnix.AsTimePtr()
383390
}
@@ -1047,11 +1054,13 @@ type IssuesOptions struct {
10471054
LabelIDs []int64
10481055
SortType string
10491056
IssueIDs []int64
1057+
// prioritize issues from this repo
1058+
PriorityRepoID int64
10501059
}
10511060

10521061
// sortIssuesSession sort an issues-related session based on the provided
10531062
// sortType string
1054-
func sortIssuesSession(sess *xorm.Session, sortType string) {
1063+
func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64) {
10551064
switch sortType {
10561065
case "oldest":
10571066
sess.Asc("issue.created_unix")
@@ -1069,6 +1078,8 @@ func sortIssuesSession(sess *xorm.Session, sortType string) {
10691078
sess.Asc("issue.deadline_unix")
10701079
case "farduedate":
10711080
sess.Desc("issue.deadline_unix")
1081+
case "priorityrepo":
1082+
sess.OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(priorityRepoID, 10) + " THEN 1 ELSE 2 END, issue.created_unix DESC")
10721083
default:
10731084
sess.Desc("issue.created_unix")
10741085
}
@@ -1170,7 +1181,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
11701181
defer sess.Close()
11711182

11721183
opts.setupSession(sess)
1173-
sortIssuesSession(sess, opts.SortType)
1184+
sortIssuesSession(sess, opts.SortType, opts.PriorityRepoID)
11741185

11751186
issues := make([]*Issue, 0, setting.UI.IssuePagingNum)
11761187
if err := sess.Find(&issues); err != nil {
@@ -1476,8 +1487,8 @@ func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen
14761487
}
14771488

14781489
// SearchIssueIDsByKeyword search issues on database
1479-
func SearchIssueIDsByKeyword(kw string, repoID int64, limit, start int) (int64, []int64, error) {
1480-
var repoCond = builder.Eq{"repo_id": repoID}
1490+
func SearchIssueIDsByKeyword(kw string, repoIDs []int64, limit, start int) (int64, []int64, error) {
1491+
var repoCond = builder.In("repo_id", repoIDs)
14811492
var subQuery = builder.Select("id").From("issue").Where(repoCond)
14821493
var cond = builder.And(
14831494
repoCond,
@@ -1566,33 +1577,43 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *Us
15661577
return sess.Commit()
15671578
}
15681579

1580+
// DependencyInfo represents high level information about an issue which is a dependency of another issue.
1581+
type DependencyInfo struct {
1582+
Issue `xorm:"extends"`
1583+
Repository `xorm:"extends"`
1584+
}
1585+
15691586
// Get Blocked By Dependencies, aka all issues this issue is blocked by.
1570-
func (issue *Issue) getBlockedByDependencies(e Engine) (issueDeps []*Issue, err error) {
1587+
func (issue *Issue) getBlockedByDependencies(e Engine) (issueDeps []*DependencyInfo, err error) {
15711588
return issueDeps, e.
1572-
Table("issue_dependency").
1573-
Select("issue.*").
1574-
Join("INNER", "issue", "issue.id = issue_dependency.dependency_id").
1589+
Table("issue").
1590+
Join("INNER", "repository", "repository.id = issue.repo_id").
1591+
Join("INNER", "issue_dependency", "issue_dependency.dependency_id = issue.id").
15751592
Where("issue_id = ?", issue.ID).
1593+
//sort by repo id then created date, with the issues of the same repo at the beginning of the list
1594+
OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(issue.RepoID, 10) + " THEN 0 ELSE issue.repo_id END, issue.created_unix DESC").
15761595
Find(&issueDeps)
15771596
}
15781597

15791598
// Get Blocking Dependencies, aka all issues this issue blocks.
1580-
func (issue *Issue) getBlockingDependencies(e Engine) (issueDeps []*Issue, err error) {
1599+
func (issue *Issue) getBlockingDependencies(e Engine) (issueDeps []*DependencyInfo, err error) {
15811600
return issueDeps, e.
1582-
Table("issue_dependency").
1583-
Select("issue.*").
1584-
Join("INNER", "issue", "issue.id = issue_dependency.issue_id").
1601+
Table("issue").
1602+
Join("INNER", "repository", "repository.id = issue.repo_id").
1603+
Join("INNER", "issue_dependency", "issue_dependency.issue_id = issue.id").
15851604
Where("dependency_id = ?", issue.ID).
1605+
//sort by repo id then created date, with the issues of the same repo at the beginning of the list
1606+
OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(issue.RepoID, 10) + " THEN 0 ELSE issue.repo_id END, issue.created_unix DESC").
15861607
Find(&issueDeps)
15871608
}
15881609

15891610
// BlockedByDependencies finds all Dependencies an issue is blocked by
1590-
func (issue *Issue) BlockedByDependencies() ([]*Issue, error) {
1611+
func (issue *Issue) BlockedByDependencies() ([]*DependencyInfo, error) {
15911612
return issue.getBlockedByDependencies(x)
15921613
}
15931614

15941615
// BlockingDependencies returns all blocking dependencies, aka all other issues a given issue blocks
1595-
func (issue *Issue) BlockingDependencies() ([]*Issue, error) {
1616+
func (issue *Issue) BlockingDependencies() ([]*DependencyInfo, error) {
15961617
return issue.getBlockingDependencies(x)
15971618
}
15981619

models/issue_label.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,19 @@ func GetLabelIDsInRepoByNames(repoID int64, labelNames []string) ([]int64, error
250250
Find(&labelIDs)
251251
}
252252

253+
// GetLabelIDsInReposByNames returns a list of labelIDs by names in one of the given
254+
// repositories.
255+
// it silently ignores label names that do not belong to the repository.
256+
func GetLabelIDsInReposByNames(repoIDs []int64, labelNames []string) ([]int64, error) {
257+
labelIDs := make([]int64, 0, len(labelNames))
258+
return labelIDs, x.Table("label").
259+
In("repo_id", repoIDs).
260+
In("name", labelNames).
261+
Asc("name").
262+
Cols("id").
263+
Find(&labelIDs)
264+
}
265+
253266
// GetLabelInRepoByID returns a label by ID in given repository.
254267
func GetLabelInRepoByID(repoID, labelID int64) (*Label, error) {
255268
return getLabelInRepoByID(x, repoID, labelID)

models/issue_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,24 +264,23 @@ func TestIssue_loadTotalTimes(t *testing.T) {
264264

265265
func TestIssue_SearchIssueIDsByKeyword(t *testing.T) {
266266
assert.NoError(t, PrepareTestDatabase())
267-
268-
total, ids, err := SearchIssueIDsByKeyword("issue2", 1, 10, 0)
267+
total, ids, err := SearchIssueIDsByKeyword("issue2", []int64{1}, 10, 0)
269268
assert.NoError(t, err)
270269
assert.EqualValues(t, 1, total)
271270
assert.EqualValues(t, []int64{2}, ids)
272271

273-
total, ids, err = SearchIssueIDsByKeyword("first", 1, 10, 0)
272+
total, ids, err = SearchIssueIDsByKeyword("first", []int64{1}, 10, 0)
274273
assert.NoError(t, err)
275274
assert.EqualValues(t, 1, total)
276275
assert.EqualValues(t, []int64{1}, ids)
277276

278-
total, ids, err = SearchIssueIDsByKeyword("for", 1, 10, 0)
277+
total, ids, err = SearchIssueIDsByKeyword("for", []int64{1}, 10, 0)
279278
assert.NoError(t, err)
280279
assert.EqualValues(t, 4, total)
281280
assert.EqualValues(t, []int64{1, 2, 3, 5}, ids)
282281

283282
// issue1's comment id 2
284-
total, ids, err = SearchIssueIDsByKeyword("good", 1, 10, 0)
283+
total, ids, err = SearchIssueIDsByKeyword("good", []int64{1}, 10, 0)
285284
assert.NoError(t, err)
286285
assert.EqualValues(t, 1, total)
287286
assert.EqualValues(t, []int64{1}, ids)

models/pull_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func PullRequests(baseRepoID int64, opts *PullRequestsOptions) ([]*PullRequest,
8787

8888
prs := make([]*PullRequest, 0, ItemsPerPage)
8989
findSession, err := listPullRequestStatement(baseRepoID, opts)
90-
sortIssuesSession(findSession, opts.SortType)
90+
sortIssuesSession(findSession, opts.SortType, 0)
9191
if err != nil {
9292
log.Error("listPullRequestStatement: %v", err)
9393
return nil, maxResults, err

modules/indexer/issues/bleve.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,18 @@ func (b *BleveIndexer) Delete(ids ...int64) error {
218218

219219
// Search searches for issues by given conditions.
220220
// Returns the matching issue IDs
221-
func (b *BleveIndexer) Search(keyword string, repoID int64, limit, start int) (*SearchResult, error) {
221+
func (b *BleveIndexer) Search(keyword string, repoIDs []int64, limit, start int) (*SearchResult, error) {
222+
var repoQueriesP []*query.NumericRangeQuery
223+
for _, repoID := range repoIDs {
224+
repoQueriesP = append(repoQueriesP, numericEqualityQuery(repoID, "RepoID"))
225+
}
226+
repoQueries := make([]query.Query, len(repoQueriesP))
227+
for i, v := range repoQueriesP {
228+
repoQueries[i] = query.Query(v)
229+
}
230+
222231
indexerQuery := bleve.NewConjunctionQuery(
223-
numericEqualityQuery(repoID, "RepoID"),
232+
bleve.NewDisjunctionQuery(repoQueries...),
224233
bleve.NewDisjunctionQuery(
225234
newMatchPhraseQuery(keyword, "Title", issueIndexerAnalyzer),
226235
newMatchPhraseQuery(keyword, "Content", issueIndexerAnalyzer),
@@ -242,8 +251,7 @@ func (b *BleveIndexer) Search(keyword string, repoID int64, limit, start int) (*
242251
return nil, err
243252
}
244253
ret.Hits = append(ret.Hits, Match{
245-
ID: id,
246-
RepoID: repoID,
254+
ID: id,
247255
})
248256
}
249257
return &ret, nil

modules/indexer/issues/bleve_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestBleveIndexAndSearch(t *testing.T) {
7676
)
7777

7878
for _, kw := range keywords {
79-
res, err := indexer.Search(kw.Keyword, 2, 10, 0)
79+
res, err := indexer.Search(kw.Keyword, []int64{2}, 10, 0)
8080
assert.NoError(t, err)
8181

8282
var ids = make([]int64, 0, len(res.Hits))

modules/indexer/issues/db.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func (db *DBIndexer) Delete(ids ...int64) error {
2626
}
2727

2828
// Search dummy function
29-
func (db *DBIndexer) Search(kw string, repoID int64, limit, start int) (*SearchResult, error) {
30-
total, ids, err := models.SearchIssueIDsByKeyword(kw, repoID, limit, start)
29+
func (db *DBIndexer) Search(kw string, repoIDs []int64, limit, start int) (*SearchResult, error) {
30+
total, ids, err := models.SearchIssueIDsByKeyword(kw, repoIDs, limit, start)
3131
if err != nil {
3232
return nil, err
3333
}
@@ -37,8 +37,7 @@ func (db *DBIndexer) Search(kw string, repoID int64, limit, start int) (*SearchR
3737
}
3838
for _, id := range ids {
3939
result.Hits = append(result.Hits, Match{
40-
ID: id,
41-
RepoID: repoID,
40+
ID: id,
4241
})
4342
}
4443
return &result, nil

modules/indexer/issues/indexer.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ type IndexerData struct {
2828

2929
// Match represents on search result
3030
type Match struct {
31-
ID int64 `json:"id"`
32-
RepoID int64 `json:"repo_id"`
33-
Score float64 `json:"score"`
31+
ID int64 `json:"id"`
32+
Score float64 `json:"score"`
3433
}
3534

3635
// SearchResult represents search results
@@ -44,7 +43,7 @@ type Indexer interface {
4443
Init() (bool, error)
4544
Index(issue []*IndexerData) error
4645
Delete(ids ...int64) error
47-
Search(kw string, repoID int64, limit, start int) (*SearchResult, error)
46+
Search(kw string, repoIDs []int64, limit, start int) (*SearchResult, error)
4847
}
4948

5049
type indexerHolder struct {
@@ -262,9 +261,9 @@ func DeleteRepoIssueIndexer(repo *models.Repository) {
262261
}
263262

264263
// SearchIssuesByKeyword search issue ids by keywords and repo id
265-
func SearchIssuesByKeyword(repoID int64, keyword string) ([]int64, error) {
264+
func SearchIssuesByKeyword(repoIDs []int64, keyword string) ([]int64, error) {
266265
var issueIDs []int64
267-
res, err := holder.get().Search(keyword, repoID, 1000, 0)
266+
res, err := holder.get().Search(keyword, repoIDs, 1000, 0)
268267
if err != nil {
269268
return nil, err
270269
}

0 commit comments

Comments
 (0)