Skip to content

Commit b7034a2

Browse files
authored
Merge branch 'main' into goldmark-update
2 parents 1fa4199 + 7b04c97 commit b7034a2

File tree

9 files changed

+58
-20
lines changed

9 files changed

+58
-20
lines changed

models/repo_list.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ type SearchRepoOptions struct {
136136
Archived util.OptionalBool
137137
// only search topic name
138138
TopicOnly bool
139+
// only search repositories with specified primary language
140+
Language string
139141
// include description in keyword search
140142
IncludeDescription bool
141143
// None -> include has milestones AND has no milestone
@@ -439,6 +441,13 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
439441
cond = cond.And(keywordCond)
440442
}
441443

444+
if opts.Language != "" {
445+
cond = cond.And(builder.In("id", builder.
446+
Select("repo_id").
447+
From("language_stat").
448+
Where(builder.Eq{"language": opts.Language}).And(builder.Eq{"is_primary": true})))
449+
}
450+
442451
if opts.Fork != util.OptionalBoolNone {
443452
cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})
444453
}

modules/git/repo.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,22 @@ func InitRepository(ctx context.Context, repoPath string, bare bool) error {
7979

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

91-
return false, nil
93+
c, err := strconv.Atoi(strings.TrimSpace(output.String()))
94+
if err != nil {
95+
return true, fmt.Errorf("check empty: convert %s to count failed: %v", output.String(), err)
96+
}
97+
return c == 0, nil
9298
}
9399

94100
// CloneRepoOptions options when clone a repository

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ issues.filter_sort.moststars = Most stars
12631263
issues.filter_sort.feweststars = Fewest stars
12641264
issues.filter_sort.mostforks = Most forks
12651265
issues.filter_sort.fewestforks = Fewest forks
1266-
issues.keyword_search_unavailable = Currently searhing by keyword is not available. Please contact your site administrator.
1266+
issues.keyword_search_unavailable = Currently searching by keyword is not available. Please contact your site administrator.
12671267
issues.action_open = Open
12681268
issues.action_close = Close
12691269
issues.action_label = Label

options/locale/locale_ja-JP.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ comment_type_group_lock=ロック状態
563563
comment_type_group_review_request=レビュー依頼
564564
comment_type_group_pull_request_push=追加されたコミット
565565
comment_type_group_project=プロジェクト
566-
comment_type_group_issue_ref=イシューの参照
566+
comment_type_group_issue_ref=イシューの参照先
567567
saved_successfully=設定は正常に保存されました。
568568
privacy=プライバシー
569569
keep_activity_private=プロフィールページのアクティビティ表示を隠す

routers/web/explore/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
7878
topicOnly := ctx.FormBool("topic")
7979
ctx.Data["TopicOnly"] = topicOnly
8080

81+
language := ctx.FormTrim("language")
82+
ctx.Data["Language"] = language
83+
8184
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
8285
ListOptions: db.ListOptions{
8386
Page: page,
@@ -91,6 +94,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
9194
AllPublic: true,
9295
AllLimited: true,
9396
TopicOnly: topicOnly,
97+
Language: language,
9498
IncludeDescription: setting.UI.SearchRepoDescription,
9599
})
96100
if err != nil {
@@ -105,6 +109,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
105109
pager := context.NewPagination(int(count), opts.PageSize, page, 5)
106110
pager.SetDefaultParams(ctx)
107111
pager.AddParam(ctx, "topic", "TopicOnly")
112+
pager.AddParam(ctx, "language", "Language")
108113
ctx.Data["Page"] = pager
109114

110115
ctx.HTML(http.StatusOK, opts.TplName)

routers/web/org/home.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ func Home(ctx *context.Context) {
8383
keyword := ctx.FormTrim("q")
8484
ctx.Data["Keyword"] = keyword
8585

86+
language := ctx.FormTrim("language")
87+
ctx.Data["Language"] = language
88+
8689
page := ctx.FormInt("page")
8790
if page <= 0 {
8891
page = 1
@@ -103,6 +106,7 @@ func Home(ctx *context.Context) {
103106
OrderBy: orderBy,
104107
Private: ctx.IsSigned,
105108
Actor: ctx.User,
109+
Language: language,
106110
IncludeDescription: setting.UI.SearchRepoDescription,
107111
})
108112
if err != nil {
@@ -148,6 +152,7 @@ func Home(ctx *context.Context) {
148152

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

153158
ctx.HTML(http.StatusOK, tplOrgHome)

routers/web/user/profile.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ func Profile(ctx *context.Context) {
232232

233233
keyword := ctx.FormTrim("q")
234234
ctx.Data["Keyword"] = keyword
235+
236+
language := ctx.FormTrim("language")
237+
ctx.Data["Language"] = language
238+
235239
switch tab {
236240
case "followers":
237241
items, err := user_model.GetUserFollowers(ctxUser, db.ListOptions{
@@ -283,6 +287,7 @@ func Profile(ctx *context.Context) {
283287
StarredByID: ctxUser.ID,
284288
Collaborate: util.OptionalBoolFalse,
285289
TopicOnly: topicOnly,
290+
Language: language,
286291
IncludeDescription: setting.UI.SearchRepoDescription,
287292
})
288293
if err != nil {
@@ -314,6 +319,7 @@ func Profile(ctx *context.Context) {
314319
WatchedByID: ctxUser.ID,
315320
Collaborate: util.OptionalBoolFalse,
316321
TopicOnly: topicOnly,
322+
Language: language,
317323
IncludeDescription: setting.UI.SearchRepoDescription,
318324
})
319325
if err != nil {
@@ -335,6 +341,7 @@ func Profile(ctx *context.Context) {
335341
Private: ctx.IsSigned,
336342
Collaborate: util.OptionalBoolFalse,
337343
TopicOnly: topicOnly,
344+
Language: language,
338345
IncludeDescription: setting.UI.SearchRepoDescription,
339346
})
340347
if err != nil {
@@ -349,6 +356,9 @@ func Profile(ctx *context.Context) {
349356

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

354364
ctx.Data["ShowUserEmail"] = len(ctxUser.Email) > 0 && ctx.IsSigned && (!ctxUser.KeepEmailPrivate || ctxUser.ID == ctx.User.ID)

templates/explore/repo_list.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
</div>
4141
<div class="metas df ac">
4242
{{if .PrimaryLanguage }}
43-
<span class="text grey df ac mr-3"><i class="color-icon mr-3" style="background-color: {{.PrimaryLanguage.Color}}"></i>{{ .PrimaryLanguage.Language }}</span>
43+
<a href="{{$.Link}}?tab={{$.TabName}}&q={{$.Keyword}}&sort={{$.SortType}}&language={{.PrimaryLanguage.Language}}">
44+
<span class="text grey df ac mr-3"><i class="color-icon mr-3" style="background-color: {{.PrimaryLanguage.Color}}"></i>{{ .PrimaryLanguage.Language }}</span>
45+
</a>
4446
{{end}}
4547
{{if not $.DisableStars}}
4648
<span class="text grey df ac mr-3">{{svg "octicon-star" 16 "mr-3"}}{{.NumStars}}</span>

templates/explore/repo_search.tmpl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
77
</span>
88
<div class="menu">
9-
<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>
10-
<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>
11-
<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>
12-
<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>
13-
<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>
14-
<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>
9+
<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>
10+
<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>
11+
<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>
12+
<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>
13+
<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>
14+
<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>
1515
{{if not .DisableStars}}
16-
<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>
17-
<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>
16+
<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>
17+
<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>
1818
{{end}}
19-
<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>
20-
<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>
19+
<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>
20+
<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>
2121
</div>
2222
</div>
2323
</div>
2424
<form class="ui form ignore-dirty" style="max-width: 90%">
2525
<input type="hidden" name="tab" value="{{$.TabName}}">
2626
<input type="hidden" name="sort" value="{{$.SortType}}">
27+
<input type="hidden" name="language" value="{{$.Language}}">
2728
<div class="ui fluid action input">
2829
<input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
2930
<button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>

0 commit comments

Comments
 (0)