diff --git a/modules/git/commit.go b/modules/git/commit.go index b09be25ba099..4ff8f6148f74 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -43,8 +43,9 @@ func (c *Commit) Message() string { } // Summary returns first line of commit message. +// The string is forced to be valid UTF8 func (c *Commit) Summary() string { - return strings.Split(strings.TrimSpace(c.CommitMessage), "\n")[0] + return strings.ToValidUTF8(strings.Split(strings.TrimSpace(c.CommitMessage), "\n")[0], "?") } // ParentID returns oid of n-th parent (0-based index). diff --git a/services/packages/debian/repository.go b/services/packages/debian/repository.go index cbde53f9611d..fca3cf420320 100644 --- a/services/packages/debian/repository.go +++ b/services/packages/debian/repository.go @@ -67,7 +67,7 @@ func GetOrCreateKeyPair(ctx context.Context, ownerID int64) (string, string, err } func generateKeypair() (string, string, error) { - e, err := openpgp.NewEntity(setting.AppName, "Debian Registry", "", nil) + e, err := openpgp.NewEntity("", "Debian Registry", "", nil) if err != nil { return "", "", err } diff --git a/services/packages/rpm/repository.go b/services/packages/rpm/repository.go index 1d0dc83cae85..c9db0247f6d9 100644 --- a/services/packages/rpm/repository.go +++ b/services/packages/rpm/repository.go @@ -22,7 +22,6 @@ import ( "code.gitea.io/gitea/modules/json" packages_module "code.gitea.io/gitea/modules/packages" rpm_module "code.gitea.io/gitea/modules/packages/rpm" - "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" packages_service "code.gitea.io/gitea/services/packages" @@ -68,7 +67,7 @@ func GetOrCreateKeyPair(ctx context.Context, ownerID int64) (string, string, err } func generateKeypair() (string, string, error) { - e, err := openpgp.NewEntity(setting.AppName, "RPM Registry", "", nil) + e, err := openpgp.NewEntity("", "RPM Registry", "", nil) if err != nil { return "", "", err } @@ -126,7 +125,7 @@ type packageData struct { type packageCache = map[*packages_model.PackageFile]*packageData -// BuildSpecificRepositoryFiles builds metadata files for the repository +// BuildRepositoryFiles builds metadata files for the repository func BuildRepositoryFiles(ctx context.Context, ownerID int64) error { pv, err := GetOrCreateRepositoryVersion(ctx, ownerID) if err != nil { diff --git a/templates/repo/actions/runs_list.tmpl b/templates/repo/actions/runs_list.tmpl index 3b289fb68f2e..580fb08a9ee2 100644 --- a/templates/repo/actions/runs_list.tmpl +++ b/templates/repo/actions/runs_list.tmpl @@ -1,5 +1,5 @@
- {{if eq (len .Runs) 0}} + {{if not .Runs}}
{{svg "octicon-no-entry" 48}}

{{if $.IsFiltered}}{{ctx.Locale.Tr "actions.runs.no_results"}}{{else}}{{ctx.Locale.Tr "actions.runs.no_runs"}}{{end}}

diff --git a/templates/repo/diff/section_split.tmpl b/templates/repo/diff/section_split.tmpl index 94dea4ac4117..5b0d982e96f5 100644 --- a/templates/repo/diff/section_split.tmpl +++ b/templates/repo/diff/section_split.tmpl @@ -108,25 +108,27 @@ {{if and (eq .GetType 3) $hasmatch}} {{$match := index $section.Lines $line.Match}} - {{if or (gt (len $line.Comments) 0) (gt (len $match.Comments) 0)}} + {{if or $line.Comments $match.Comments}} - {{if gt (len $line.Comments) 0}} + {{if $line.Comments}} {{if eq $line.GetCommentSide "previous"}} {{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}} {{end}} {{end}} - {{if gt (len $match.Comments) 0}} + {{if $match.Comments}} {{if eq $match.GetCommentSide "previous"}} {{template "repo/diff/conversation" dict "." $.root "comments" $match.Comments}} {{end}} {{end}} - {{if eq $line.GetCommentSide "proposed"}} - {{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}} + {{if $line.Comments}} + {{if eq $line.GetCommentSide "proposed"}} + {{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}} + {{end}} {{end}} - {{if gt (len $match.Comments) 0}} + {{if $match.Comments}} {{if eq $match.GetCommentSide "proposed"}} {{template "repo/diff/conversation" dict "." $.root "comments" $match.Comments}} {{end}} @@ -134,13 +136,11 @@ {{end}} - {{else if gt (len $line.Comments) 0}} + {{else if $line.Comments}} - {{if gt (len $line.Comments) 0}} - {{if eq $line.GetCommentSide "previous"}} - {{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}} - {{end}} + {{if eq $line.GetCommentSide "previous"}} + {{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}} {{end}} diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl index d2345c3b88e3..2b901411e292 100644 --- a/templates/repo/diff/section_unified.tmpl +++ b/templates/repo/diff/section_unified.tmpl @@ -60,7 +60,7 @@ */}} {{end}} - {{if gt (len $line.Comments) 0}} + {{if $line.Comments}} {{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}} diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index f306435409e3..2a3ebc4e772d 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -81,12 +81,12 @@ {{end}} {{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
@@ -98,7 +98,7 @@ href="{{AppSubUrl}}/{{(index $.UserAndOrgForks 0).FullName}}" {{/*else is not required here, because the button shouldn't link to any site if you can't create a fork*/}} {{end}} - {{else if eq (len $.UserAndOrgForks) 0}} + {{else if not $.UserAndOrgForks}} href="{{AppSubUrl}}/repo/fork/{{.ID}}" {{else}} data-modal="#fork-repo-modal" diff --git a/templates/repo/issue/filters.tmpl b/templates/repo/issue/filters.tmpl index 1d200e23b7a7..56c65e240143 100644 --- a/templates/repo/issue/filters.tmpl +++ b/templates/repo/issue/filters.tmpl @@ -1,6 +1,6 @@
- {{if and ($.CanWriteIssuesOrPulls) (gt (len .Issues) 0)}} + {{if and $.CanWriteIssuesOrPulls .Issues}} {{end}} {{template "repo/issue/openclose" .}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 4be1f52dd5c6..c81cc5c10a64 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -339,7 +339,7 @@
{{end}} - {{if gt (len .WorkingUsers) 0}} + {{if .WorkingUsers}}
{{ctx.Locale.Tr "repo.issues.time_spent_from_all_authors" ($.Issue.TotalTrackedTime | Sec2Time) | Safe}} diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index e0d2e102e5ef..7fd1f4e0f8d0 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -140,7 +140,7 @@ {{ctx.Locale.TrN $waitingOfficial "repo.pulls.waiting_count_1" "repo.pulls.waiting_count_n" $waitingOfficial}} {{end}} - {{if and (not .PullRequest.HasMerged) (gt (len .PullRequest.ConflictedFiles) 0)}} + {{if and (not .PullRequest.HasMerged) .PullRequest.ConflictedFiles}} {{svg "octicon-x" 14}} {{ctx.Locale.TrN (len .PullRequest.ConflictedFiles) "repo.pulls.num_conflicting_files_1" "repo.pulls.num_conflicting_files_n" (len .PullRequest.ConflictedFiles)}} diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 3a080a3505a8..728715bbc75f 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -106,7 +106,7 @@ {{else if .GetOpType.InActions "comment_issue" "approve_pull_request" "reject_pull_request" "comment_pull"}} {{(.GetIssueTitle ctx) | RenderEmoji $.Context | RenderCodeBlock}} {{$comment := index .GetIssueInfos 1}} - {{if gt (len $comment) 0}} + {{if $comment}}
{{RenderMarkdownToHtml ctx $comment}}
{{end}} {{else if .GetOpType.InActions "merge_pull_request"}} diff --git a/templates/user/notification/notification_div.tmpl b/templates/user/notification/notification_div.tmpl index e98eff9cffb4..d8f8d462d359 100644 --- a/templates/user/notification/notification_div.tmpl +++ b/templates/user/notification/notification_div.tmpl @@ -24,7 +24,7 @@
- {{if eq (len .Notifications) 0}} + {{if not .Notifications}}
{{svg "octicon-inbox" 56 "gt-mb-4"}} {{if eq .Status 1}} diff --git a/templates/user/notification/notification_subscriptions.tmpl b/templates/user/notification/notification_subscriptions.tmpl index 7eb4c8ea446a..ec40d3afeaff 100644 --- a/templates/user/notification/notification_subscriptions.tmpl +++ b/templates/user/notification/notification_subscriptions.tmpl @@ -63,7 +63,7 @@
- {{if eq (len .Issues) 0}} + {{if not .Issues}} {{ctx.Locale.Tr "notification.no_subscriptions"}} {{else}} {{template "shared/issuelist" dict "." . "listType" "dashboard"}} diff --git a/templates/user/settings/keys_gpg.tmpl b/templates/user/settings/keys_gpg.tmpl index bd560fa325fe..481d7482b498 100644 --- a/templates/user/settings/keys_gpg.tmpl +++ b/templates/user/settings/keys_gpg.tmpl @@ -55,7 +55,7 @@ {{if .Verified}} {{svg "octicon-verified"}} {{ctx.Locale.Tr "settings.gpg_key_verified"}} {{end}} - {{if gt (len .Emails) 0}} + {{if .Emails}} {{svg "octicon-mail"}} {{ctx.Locale.Tr "settings.gpg_key_matched_identities"}} {{range .Emails}}{{.Email}} {{end}} {{end}}