Skip to content

Commit

Permalink
Merge branch 'main' into goldmark-update
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 authored Jan 28, 2022
2 parents 1fa4199 + 7b04c97 commit b7034a2
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 20 deletions.
9 changes: 9 additions & 0 deletions models/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ type SearchRepoOptions struct {
Archived util.OptionalBool
// only search topic name
TopicOnly bool
// only search repositories with specified primary language
Language string
// include description in keyword search
IncludeDescription bool
// None -> include has milestones AND has no milestone
Expand Down Expand Up @@ -439,6 +441,13 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
cond = cond.And(keywordCond)
}

if opts.Language != "" {
cond = cond.And(builder.In("id", builder.
Select("repo_id").
From("language_stat").
Where(builder.Eq{"language": opts.Language}).And(builder.Eq{"is_primary": true})))
}

if opts.Fork != util.OptionalBoolNone {
cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})
}
Expand Down
20 changes: 13 additions & 7 deletions modules/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,22 @@ func InitRepository(ctx context.Context, repoPath string, bare bool) error {

// IsEmpty Check if repository is empty.
func (repo *Repository) IsEmpty() (bool, error) {
var errbuf strings.Builder
if err := NewCommandContext(repo.Ctx, "log", "-1").RunInDirPipeline(repo.Path, nil, &errbuf); err != nil {
if strings.Contains(errbuf.String(), "fatal: bad default revision 'HEAD'") ||
strings.Contains(errbuf.String(), "fatal: your current branch 'master' does not have any commits yet") {
return true, nil
}
var errbuf, output strings.Builder
if err := NewCommandContext(repo.Ctx, "rev-list", "--all", "--count", "--max-count=1").
RunWithContext(&RunContext{
Timeout: -1,
Dir: repo.Path,
Stdout: &output,
Stderr: &errbuf,
}); err != nil {
return true, fmt.Errorf("check empty: %v - %s", err, errbuf.String())
}

return false, nil
c, err := strconv.Atoi(strings.TrimSpace(output.String()))
if err != nil {
return true, fmt.Errorf("check empty: convert %s to count failed: %v", output.String(), err)
}
return c == 0, nil
}

// CloneRepoOptions options when clone a repository
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ issues.filter_sort.moststars = Most stars
issues.filter_sort.feweststars = Fewest stars
issues.filter_sort.mostforks = Most forks
issues.filter_sort.fewestforks = Fewest forks
issues.keyword_search_unavailable = Currently searhing by keyword is not available. Please contact your site administrator.
issues.keyword_search_unavailable = Currently searching by keyword is not available. Please contact your site administrator.
issues.action_open = Open
issues.action_close = Close
issues.action_label = Label
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_ja-JP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ comment_type_group_lock=ロック状態
comment_type_group_review_request=レビュー依頼
comment_type_group_pull_request_push=追加されたコミット
comment_type_group_project=プロジェクト
comment_type_group_issue_ref=イシューの参照
comment_type_group_issue_ref=イシューの参照先
saved_successfully=設定は正常に保存されました。
privacy=プライバシー
keep_activity_private=プロフィールページのアクティビティ表示を隠す
Expand Down
5 changes: 5 additions & 0 deletions routers/web/explore/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
topicOnly := ctx.FormBool("topic")
ctx.Data["TopicOnly"] = topicOnly

language := ctx.FormTrim("language")
ctx.Data["Language"] = language

repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
ListOptions: db.ListOptions{
Page: page,
Expand All @@ -91,6 +94,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
AllPublic: true,
AllLimited: true,
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
})
if err != nil {
Expand All @@ -105,6 +109,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
pager := context.NewPagination(int(count), opts.PageSize, page, 5)
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "topic", "TopicOnly")
pager.AddParam(ctx, "language", "Language")
ctx.Data["Page"] = pager

ctx.HTML(http.StatusOK, opts.TplName)
Expand Down
5 changes: 5 additions & 0 deletions routers/web/org/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func Home(ctx *context.Context) {
keyword := ctx.FormTrim("q")
ctx.Data["Keyword"] = keyword

language := ctx.FormTrim("language")
ctx.Data["Language"] = language

page := ctx.FormInt("page")
if page <= 0 {
page = 1
Expand All @@ -103,6 +106,7 @@ func Home(ctx *context.Context) {
OrderBy: orderBy,
Private: ctx.IsSigned,
Actor: ctx.User,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
})
if err != nil {
Expand Down Expand Up @@ -148,6 +152,7 @@ func Home(ctx *context.Context) {

pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5)
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "language", "Language")
ctx.Data["Page"] = pager

ctx.HTML(http.StatusOK, tplOrgHome)
Expand Down
10 changes: 10 additions & 0 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ func Profile(ctx *context.Context) {

keyword := ctx.FormTrim("q")
ctx.Data["Keyword"] = keyword

language := ctx.FormTrim("language")
ctx.Data["Language"] = language

switch tab {
case "followers":
items, err := user_model.GetUserFollowers(ctxUser, db.ListOptions{
Expand Down Expand Up @@ -283,6 +287,7 @@ func Profile(ctx *context.Context) {
StarredByID: ctxUser.ID,
Collaborate: util.OptionalBoolFalse,
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
})
if err != nil {
Expand Down Expand Up @@ -314,6 +319,7 @@ func Profile(ctx *context.Context) {
WatchedByID: ctxUser.ID,
Collaborate: util.OptionalBoolFalse,
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
})
if err != nil {
Expand All @@ -335,6 +341,7 @@ func Profile(ctx *context.Context) {
Private: ctx.IsSigned,
Collaborate: util.OptionalBoolFalse,
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
})
if err != nil {
Expand All @@ -349,6 +356,9 @@ func Profile(ctx *context.Context) {

pager := context.NewPagination(total, setting.UI.User.RepoPagingNum, page, 5)
pager.SetDefaultParams(ctx)
if tab != "followers" && tab != "following" && tab != "activity" && tab != "projects" {
pager.AddParam(ctx, "language", "Language")
}
ctx.Data["Page"] = pager

ctx.Data["ShowUserEmail"] = len(ctxUser.Email) > 0 && ctx.IsSigned && (!ctxUser.KeepEmailPrivate || ctxUser.ID == ctx.User.ID)
Expand Down
4 changes: 3 additions & 1 deletion templates/explore/repo_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
</div>
<div class="metas df ac">
{{if .PrimaryLanguage }}
<span class="text grey df ac mr-3"><i class="color-icon mr-3" style="background-color: {{.PrimaryLanguage.Color}}"></i>{{ .PrimaryLanguage.Language }}</span>
<a href="{{$.Link}}?tab={{$.TabName}}&q={{$.Keyword}}&sort={{$.SortType}}&language={{.PrimaryLanguage.Language}}">
<span class="text grey df ac mr-3"><i class="color-icon mr-3" style="background-color: {{.PrimaryLanguage.Color}}"></i>{{ .PrimaryLanguage.Language }}</span>
</a>
{{end}}
{{if not $.DisableStars}}
<span class="text grey df ac mr-3">{{svg "octicon-star" 16 "mr-3"}}{{.NumStars}}</span>
Expand Down
21 changes: 11 additions & 10 deletions templates/explore/repo_search.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
</span>
<div class="menu">
<a class="{{if eq .SortType "newest"}}active{{end}} item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a>
<a class="{{if eq .SortType "oldest"}}active{{end}} item" href="{{$.Link}}?sort=oldest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.oldest"}}</a>
<a class="{{if eq .SortType "alphabetically"}}active{{end}} item" href="{{$.Link}}?sort=alphabetically&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
<a class="{{if eq .SortType "reversealphabetically"}}active{{end}} item" href="{{$.Link}}?sort=reversealphabetically&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
<a class="{{if eq .SortType "recentupdate"}}active{{end}} item" href="{{$.Link}}?sort=recentupdate&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.recentupdate"}}</a>
<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?sort=leastupdate&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
<a class="{{if eq .SortType "newest"}}active{{end}} item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}&tab={{$.TabName}}&language={{$.Language}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a>
<a class="{{if eq .SortType "oldest"}}active{{end}} item" href="{{$.Link}}?sort=oldest&q={{$.Keyword}}&tab={{$.TabName}}&language={{$.Language}}">{{.i18n.Tr "repo.issues.filter_sort.oldest"}}</a>
<a class="{{if eq .SortType "alphabetically"}}active{{end}} item" href="{{$.Link}}?sort=alphabetically&q={{$.Keyword}}&tab={{$.TabName}}&language={{$.Language}}">{{.i18n.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
<a class="{{if eq .SortType "reversealphabetically"}}active{{end}} item" href="{{$.Link}}?sort=reversealphabetically&q={{$.Keyword}}&tab={{$.TabName}}&language={{$.Language}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
<a class="{{if eq .SortType "recentupdate"}}active{{end}} item" href="{{$.Link}}?sort=recentupdate&q={{$.Keyword}}&tab={{$.TabName}}&language={{$.Language}}">{{.i18n.Tr "repo.issues.filter_sort.recentupdate"}}</a>
<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?sort=leastupdate&q={{$.Keyword}}&tab={{$.TabName}}&language={{$.Language}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
{{if not .DisableStars}}
<a class="{{if eq .SortType "moststars"}}active{{end}} item" href="{{$.Link}}?sort=moststars&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.moststars"}}</a>
<a class="{{if eq .SortType "feweststars"}}active{{end}} item" href="{{$.Link}}?sort=feweststars&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.feweststars"}}</a>
<a class="{{if eq .SortType "moststars"}}active{{end}} item" href="{{$.Link}}?sort=moststars&q={{$.Keyword}}&tab={{$.TabName}}&language={{$.Language}}">{{.i18n.Tr "repo.issues.filter_sort.moststars"}}</a>
<a class="{{if eq .SortType "feweststars"}}active{{end}} item" href="{{$.Link}}?sort=feweststars&q={{$.Keyword}}&tab={{$.TabName}}&language={{$.Language}}">{{.i18n.Tr "repo.issues.filter_sort.feweststars"}}</a>
{{end}}
<a class="{{if eq .SortType "mostforks"}}active{{end}} item" href="{{$.Link}}?sort=mostforks&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.mostforks"}}</a>
<a class="{{if eq .SortType "fewestforks"}}active{{end}} item" href="{{$.Link}}?sort=fewestforks&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.fewestforks"}}</a>
<a class="{{if eq .SortType "mostforks"}}active{{end}} item" href="{{$.Link}}?sort=mostforks&q={{$.Keyword}}&tab={{$.TabName}}&language={{$.Language}}">{{.i18n.Tr "repo.issues.filter_sort.mostforks"}}</a>
<a class="{{if eq .SortType "fewestforks"}}active{{end}} item" href="{{$.Link}}?sort=fewestforks&q={{$.Keyword}}&tab={{$.TabName}}&language={{$.Language}}">{{.i18n.Tr "repo.issues.filter_sort.fewestforks"}}</a>
</div>
</div>
</div>
<form class="ui form ignore-dirty" style="max-width: 90%">
<input type="hidden" name="tab" value="{{$.TabName}}">
<input type="hidden" name="sort" value="{{$.SortType}}">
<input type="hidden" name="language" value="{{$.Language}}">
<div class="ui fluid action input">
<input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
<button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>
Expand Down

0 comments on commit b7034a2

Please sign in to comment.