Skip to content

Commit ceb8174

Browse files
committed
Include all public repositories in search result
1 parent 82b6465 commit ceb8174

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

models/repo_list.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ type SearchRepoOptions struct {
105105
Starred bool `json:"-"`
106106
Page int `json:"-"`
107107
IsProfile bool `json:"-"`
108+
AllPublic bool `json:"-"` // Include also all public repositories
108109
// Limit of result
109110
//
110111
// maximum: setting.ExplorePagingNum
@@ -149,11 +150,6 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
149150
starJoin = true
150151
}
151152

152-
opts.Keyword = strings.ToLower(opts.Keyword)
153-
if opts.Keyword != "" {
154-
cond = cond.And(builder.Like{"lower_name", opts.Keyword})
155-
}
156-
157153
// Append conditions
158154
if !opts.Starred && opts.OwnerID > 0 {
159155
var searcherReposCond builder.Cond = builder.Eq{"owner_id": opts.OwnerID}
@@ -184,6 +180,15 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
184180
cond = cond.And(builder.Eq{"is_private": false})
185181
}
186182

183+
if opts.OwnerID > 0 && opts.AllPublic {
184+
cond = builder.Or(cond, builder.Eq{"is_private": false})
185+
}
186+
187+
opts.Keyword = strings.ToLower(opts.Keyword)
188+
if opts.Keyword != "" {
189+
cond = cond.And(builder.Like{"lower_name", opts.Keyword})
190+
}
191+
187192
if len(opts.OrderBy) == 0 {
188193
opts.OrderBy = SearchOrderByAlphabetically
189194
}

routers/home.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func Swagger(ctx *context.Context) {
6060

6161
// RepoSearchOptions when calling search repositories
6262
type RepoSearchOptions struct {
63+
OwnerID int64
6364
Private bool
6465
PageSize int
6566
TplName base.TplName
@@ -113,11 +114,15 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
113114
keyword := strings.Trim(ctx.Query("q"), " ")
114115

115116
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
116-
Page: page,
117-
PageSize: opts.PageSize,
118-
OrderBy: orderBy,
119-
Private: opts.Private,
120-
Keyword: keyword,
117+
Page: page,
118+
PageSize: opts.PageSize,
119+
OrderBy: orderBy,
120+
Private: opts.Private,
121+
Keyword: keyword,
122+
OwnerID: opts.OwnerID,
123+
Searcher: ctx.User,
124+
Collaborate: true,
125+
AllPublic: true,
121126
})
122127
if err != nil {
123128
ctx.Handle(500, "SearchRepositoryByName", err)
@@ -137,9 +142,15 @@ func ExploreRepos(ctx *context.Context) {
137142
ctx.Data["PageIsExplore"] = true
138143
ctx.Data["PageIsExploreRepositories"] = true
139144

145+
var ownerID int64
146+
if ctx.User != nil && !ctx.User.IsAdmin {
147+
ownerID = ctx.User.ID
148+
}
149+
140150
RenderRepoSearch(ctx, &RepoSearchOptions{
141151
PageSize: setting.UI.ExplorePagingNum,
142-
Private: ctx.User != nil && ctx.User.IsAdmin,
152+
OwnerID: ownerID,
153+
Private: ctx.User != nil,
143154
TplName: tplExploreRepos,
144155
})
145156
}

0 commit comments

Comments
 (0)