Merge 831eecefb3
into d0fef4395f
This commit is contained in:
commit
73368be9d1
|
@ -9,3 +9,7 @@
|
|||
-
|
||||
repo_id: 1
|
||||
topic_id: 3
|
||||
|
||||
-
|
||||
repo_id: 2
|
||||
topic_id: 2
|
||||
|
|
|
@ -184,7 +184,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err
|
|||
|
||||
if opts.Collaborate != util.OptionalBoolFalse {
|
||||
collaborateCond := builder.And(
|
||||
builder.Expr("id IN (SELECT repo_id FROM `access` WHERE access.user_id = ?)", opts.OwnerID),
|
||||
builder.Expr("repository.id IN (SELECT repo_id FROM `access` WHERE access.user_id = ?)", opts.OwnerID),
|
||||
builder.Neq{"owner_id": opts.OwnerID})
|
||||
if !opts.Private {
|
||||
collaborateCond = collaborateCond.And(builder.Expr("owner_id NOT IN (SELECT org_id FROM org_user WHERE org_user.uid = ? AND org_user.is_public = ?)", opts.OwnerID, false))
|
||||
|
@ -202,7 +202,10 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err
|
|||
}
|
||||
|
||||
if opts.Keyword != "" {
|
||||
cond = cond.And(builder.Like{"lower_name", strings.ToLower(opts.Keyword)})
|
||||
var keywordCond = builder.NewCond()
|
||||
keywordCond = keywordCond.Or(builder.Like{"lower_name", strings.ToLower(opts.Keyword)})
|
||||
keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(opts.Keyword)})
|
||||
cond = cond.And(keywordCond)
|
||||
}
|
||||
|
||||
if opts.Fork != util.OptionalBoolNone {
|
||||
|
@ -224,9 +227,15 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err
|
|||
sess.Join("INNER", "star", "star.repo_id = repository.id")
|
||||
}
|
||||
|
||||
if opts.Keyword != "" {
|
||||
sess.Join("LEFT", "repo_topic", "repo_topic.repo_id = repository.id")
|
||||
sess.Join("LEFT", "topic", "repo_topic.topic_id = topic.id")
|
||||
}
|
||||
|
||||
count, err := sess.
|
||||
Where(cond).
|
||||
Count(new(Repository))
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("Count: %v", err)
|
||||
}
|
||||
|
@ -236,11 +245,23 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err
|
|||
sess.Join("INNER", "star", "star.repo_id = repository.id")
|
||||
}
|
||||
|
||||
if opts.Keyword != "" {
|
||||
sess.Join("LEFT", "repo_topic", "repo_topic.repo_id = repository.id")
|
||||
sess.Join("LEFT", "topic", "repo_topic.topic_id = topic.id")
|
||||
}
|
||||
|
||||
if opts.Keyword != "" {
|
||||
sess.Select("repository.*")
|
||||
sess.GroupBy("repository.id")
|
||||
sess.OrderBy("repository." + opts.OrderBy.String())
|
||||
} else {
|
||||
sess.OrderBy(opts.OrderBy.String())
|
||||
}
|
||||
|
||||
repos := make(RepositoryList, 0, opts.PageSize)
|
||||
if err = sess.
|
||||
Where(cond).
|
||||
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
|
||||
OrderBy(opts.OrderBy.String()).
|
||||
Find(&repos); err != nil {
|
||||
return nil, 0, fmt.Errorf("Repo: %v", err)
|
||||
}
|
||||
|
|
|
@ -222,3 +222,28 @@ func TestSearchRepositoryByName(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchRepositoryByTopicName(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
opts *SearchRepoOptions
|
||||
count int
|
||||
}{
|
||||
{name: "AllPublic/SearchPublicRepositoriesFromTopic",
|
||||
opts: &SearchRepoOptions{OwnerID: 2, AllPublic: true, Keyword: "golang"},
|
||||
count: 1},
|
||||
{name: "AllPublic/SearchPrivateRepositoriesFromTopic",
|
||||
opts: &SearchRepoOptions{OwnerID: 2, AllPublic: true, Keyword: "database", Private: true},
|
||||
count: 2},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
_, count, err := SearchRepositoryByName(testCase.opts)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(testCase.count), count)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
{{if .Topics }}
|
||||
<div>
|
||||
{{range .Topics}}
|
||||
{{if ne . "" }}<div class="ui green basic label topic">{{.}}</div>{{end}}
|
||||
{{if ne . "" }}<a href="/explore/repos?q={{.}}"><div class="ui green basic label topic">{{.}}</div></a>{{end}}
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
{{end}}
|
||||
</div>
|
||||
<div class="ui repo-topic" id="repo-topic">
|
||||
{{range .Topics}}<div class="ui green basic label topic" style="cursor:pointer;">{{.Name}}</div>{{end}}
|
||||
{{if .IsRepositoryAdmin}}<a id="manage_topic" style="cursor:pointer;margin-left:10px;">{{.i18n.Tr "repo.topic.manage_topics"}}</a>{{end}}
|
||||
{{range .Topics}}<a class="ui green basic label topic" style="cursor:pointer;" href="/explore/repos?q={{.Name}}">{{.Name}}</a>{{end}}
|
||||
{{if .IsRepositoryAdmin}}<a id="manage_topic" style="cursor:pointer;margin-left:10px;" href="/explore/repos?q={{.Name}}">{{.i18n.Tr "repo.topic.manage_topics"}}</a>{{end}}
|
||||
</div>
|
||||
{{if .IsRepositoryAdmin}}
|
||||
<div class="ui repo-topic-edit grid form segment error" id="topic_edit" >
|
||||
|
@ -34,7 +34,7 @@
|
|||
<div class="ui fluid multiple search selection dropdown">
|
||||
<input type="hidden" name="topics" value="{{range $i, $v := .Topics}}{{.Name}}{{if lt (Add $i 1) (len $.Topics)}},{{end}}{{end}}">
|
||||
{{range .Topics}}
|
||||
<a class="ui green basic label topic transition visible" data-value="{{.Name}}" style="display: inline-block !important;">{{.Name}}<i class="delete icon"></i></a>
|
||||
<a class="ui green basic label topic transition visible" data-value="{{.Name}}" style="display: inline-block !important;" href="/explore/repos?q={{.Name}}">{{.Name}}<i class="delete icon"></i></a>
|
||||
{{end}}
|
||||
<div class="text"></div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user