diff --git a/modules/markup/html.go b/modules/markup/html.go index 5bca4c4596..4c25ab9985 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -1125,7 +1125,7 @@ func fullHashPatternProcessor(ctx *RenderContext, node *html.Node) { if hash != "" { text += " (" + hash + ")" } - replaceContent(node, start, end, createCodeLink(urlFull, text, "commit")) + replaceContent(node, start, end, createCodeLink(urlFull, text, "")) node = node.NextSibling.NextSibling } } @@ -1409,7 +1409,7 @@ func hashCurrentPatternProcessor(ctx *RenderContext, node *html.Node) { } link := util.URLJoin(ctx.Links.Prefix(), ctx.Metas["user"], ctx.Metas["repo"], "commit", hash) - replaceContent(node, m[2], m[3], createCodeLink(link, base.ShortSha(hash), "commit")) + replaceContent(node, m[2], m[3], createCodeLink(link, base.ShortSha(hash), "")) start = 0 node = node.NextSibling.NextSibling } diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go index 570e8c5e68..ed8ac206b9 100644 --- a/modules/markup/html_internal_test.go +++ b/modules/markup/html_internal_test.go @@ -340,52 +340,52 @@ func TestRender_AutoLink(t *testing.T) { t.Run("Commit", func(t *testing.T) { // render valid commit URLs tmp := util.URLJoin(TestRepoURL, "commit", "d8a994ef243349f321568f9e36d5c3f444b99cae") - assert(tmp, "d8a994ef24", TestRepoURLWithoutSlash) - assert(tmp, ""+TestOrgRepo+"@d8a994ef24", "/forgejo/forgejo") + assert(tmp, "d8a994ef24", TestRepoURLWithoutSlash) + assert(tmp, ""+TestOrgRepo+"@d8a994ef24", "/forgejo/forgejo") assert( tmp+"#diff-2", - "d8a994ef24 (diff-2)", + "d8a994ef24 (diff-2)", TestRepoURL, ) assert( tmp+"#diff-953bb4f01b7c77fa18f0cd54211255051e647dbc", - "d8a994ef24 (diff-953bb4f01b)", + "d8a994ef24 (diff-953bb4f01b)", TestRepoURLWithoutSlash, ) // render other commit URLs tmp = "https://external-link.gitea.io/go-gitea/gitea/commit/d8a994ef243349f321568f9e36d5c3f444b99cae#diff-2" - assert(tmp, "external-link.gitea.io/go-gitea/gitea@d8a994ef24 (diff-2)", TestOrgRepo) + assert(tmp, "external-link.gitea.io/go-gitea/gitea@d8a994ef24 (diff-2)", TestOrgRepo) defer test.MockVariableValue(&setting.AppURL, "https://external-link.gitea.io/")() - assert(tmp, "d8a994ef24 (diff-2)", "https://external-link.gitea.io/go-gitea/gitea") + assert(tmp, "d8a994ef24 (diff-2)", "https://external-link.gitea.io/go-gitea/gitea") tmp = TestAppURL + "gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20" - assert(tmp, "localhost:3000/gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea") + assert(tmp, "localhost:3000/gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea") defer test.MockVariableValue(&setting.AppURL, TestAppURL)() - assert(tmp, "190d949293", "http://localhost:3000/gogits/gogs") + assert(tmp, "190d949293", "http://localhost:3000/gogits/gogs") tmp = "http://localhost:3000/sub/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20" - assert(tmp, "localhost:3000/sub/gogits/gogs@190d949293", TestRepoURLWithoutSlash) - assert(tmp, "localhost:3000/sub/gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea") + assert(tmp, "localhost:3000/sub/gogits/gogs@190d949293", TestRepoURLWithoutSlash) + assert(tmp, "localhost:3000/sub/gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea") defer test.MockVariableValue(&setting.AppURL, TestAppURL+"sub/")() - assert(tmp, "190d949293", "http://localhost:3000/sub/gogits/gogs") + assert(tmp, "190d949293", "http://localhost:3000/sub/gogits/gogs") tmp = "http://localhost:3000/sub1/sub2/sub3/gogits/gogs/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20" defer test.MockVariableValue(&setting.AppURL, TestAppURL+"sub1/sub2/sub3/")() - assert(tmp, "190d949293", "http://localhost:3000/sub1/sub2/sub3/gogits/gogs") + assert(tmp, "190d949293", "http://localhost:3000/sub1/sub2/sub3/gogits/gogs") defer test.MockVariableValue(&setting.AppURL, TestAppURL)() - assert(tmp, "localhost:3000/sub1/sub2/sub3/gogits/gogs@190d949293", "http://localhost:3000/sub1/gogits/gogs") - assert(tmp, "localhost:3000/sub1/sub2/sub3/gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea") + assert(tmp, "localhost:3000/sub1/sub2/sub3/gogits/gogs@190d949293", "http://localhost:3000/sub1/gogits/gogs") + assert(tmp, "localhost:3000/sub1/sub2/sub3/gogits/gogs@190d949293", "https://external-link.gitea.io/go-gitea/gitea") // if the repository happens to be named like one of the known app routes (e.g. `src`), // we can parse the URL correctly, if there is no sub path tmp = "http://localhost:3000/gogits/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20" - assert(tmp, "gogits/src@190d949293", TestRepoURL) + assert(tmp, "gogits/src@190d949293", TestRepoURL) tmp = "http://localhost:3000/gogits/src/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20" - assert(tmp, "gogits/src@190d949293", TestRepoURL) + assert(tmp, "gogits/src@190d949293", TestRepoURL) // but if there is a sub path, we cannot reliably distinguish the repo name from the app route tmp = "http://localhost:3000/sub/gogits/src/commit/190d9492934af498c3f669d6a2431dc5459e5b20" - assert(tmp, "sub/gogits@190d949293", TestRepoURL) + assert(tmp, "sub/gogits@190d949293", TestRepoURL) }) t.Run("Compare", func(t *testing.T) { diff --git a/modules/templates/util_date.go b/modules/templates/util_date.go index 982a1b8050..0f757d914d 100644 --- a/modules/templates/util_date.go +++ b/modules/templates/util_date.go @@ -26,6 +26,11 @@ func (du *DateUtils) AbsoluteShort(time any) template.HTML { return dateTimeFormat("short", time) } +// AbsoluteShort renders in "Sun, 01 Jan, 2006" format +func (du *DateUtils) AbsoluteShortWithDay(time any) template.HTML { + return dateTimeFormat("short-with-day", time) +} + // AbsoluteLong renders in "January 01, 2006" format func (du *DateUtils) AbsoluteLong(time any) template.HTML { return dateTimeFormat("long", time) @@ -114,6 +119,10 @@ func dateTimeFormat(format string, datetime any) template.HTML { case "short", "long": // date only attrs = append(attrs, `month="`+format+`"`, `day="numeric"`) return template.HTML(fmt.Sprintf(`%s`, strings.Join(attrs, " "), datetimeEscaped, textEscaped)) + case "short-with-day": + attrs = append(attrs, `month="short"`, `day="numeric"`) + attrs[0] = `weekday="short"` + return template.HTML(fmt.Sprintf(`%s`, strings.Join(attrs, " "), datetimeEscaped, textEscaped)) case "full": // full date including time attrs = append(attrs, `format="datetime"`, `month="short"`, `day="numeric"`, `hour="numeric"`, `minute="numeric"`, `second="numeric"`, `data-tooltip-content`, `data-tooltip-interactive="true"`) return template.HTML(fmt.Sprintf(`%s`, strings.Join(attrs, " "), datetimeEscaped, textEscaped)) diff --git a/modules/templates/util_render_test.go b/modules/templates/util_render_test.go index 35412989e3..058acd2a9b 100644 --- a/modules/templates/util_render_test.go +++ b/modules/templates/util_render_test.go @@ -20,7 +20,7 @@ import ( "github.com/stretchr/testify/assert" ) -const testInput = ` space @mention-user +const testInput = ` space @mention-user /just/a/path.bin https://example.com/file.bin [local link](file.bin) @@ -113,7 +113,7 @@ func TestRenderCommitBody(t *testing.T) { [[remote link|https://example.com/image.jpg]] 88fc37a3c0...12fc37a3c0 (hash) com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb...12fc37a3c0a4dda553bdcfc80c178a58247f42fb pare -88fc37a3c0 +88fc37a3c0 com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit 👍 mail@domain.com @@ -125,7 +125,7 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit } func TestRenderCommitMessage(t *testing.T) { - expected := `space @mention-user ` + expected := `space @mention-user` assert.EqualValues(t, expected, RenderCommitMessage(t.Context(), testInput, testMetas)) } @@ -137,7 +137,7 @@ func TestRenderCommitMessageLinkSubject(t *testing.T) { } func TestRenderIssueTitle(t *testing.T) { - expected := ` space @mention-user + expected := ` space @mention-user /just/a/path.bin https://example.com/file.bin [local link](file.bin) @@ -163,7 +163,7 @@ mail@domain.com } func TestRenderRefIssueTitle(t *testing.T) { - expected := ` space @mention-user + expected := ` space @mention-user /just/a/path.bin https://example.com/file.bin [local link](file.bin) @@ -189,7 +189,7 @@ mail@domain.com } func TestRenderMarkdownToHtml(t *testing.T) { - expected := `

space @mention-user
+ expected := `

space @mention-user /just/a/path.bin https://example.com/file.bin local link diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index 2c0a93f2ba..e77b1cb581 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -28,6 +28,21 @@ + {{$class := "ui sha label"}} + {{if .Signature}} + {{$class = (print $class " isSigned")}} + {{if .Verification.Verified}} + {{if eq .Verification.TrustStatus "trusted"}} + {{$class = (print $class " isVerified")}} + {{else if eq .Verification.TrustStatus "untrusted"}} + {{$class = (print $class " isVerifiedUntrusted")}} + {{else}} + {{$class = (print $class " isVerifiedUnmatched")}} + {{end}} + {{else if .Verification.Warning}} + {{$class = (print $class " isWarning")}} + {{end}} + {{end}} {{$commitShaLink := ""}} {{if $.PageIsWiki}} {{$commitShaLink = (printf "%s/wiki/commit/%s" $commitRepoLink (PathEscape .ID.String))}} diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl index 87feb06a98..2146910293 100644 --- a/templates/repo/commits_table.tmpl +++ b/templates/repo/commits_table.tmpl @@ -1,27 +1,22 @@ -

-
- {{if or .PageIsCommits (gt .CommitCount 0)}} - {{ctx.Locale.TrPluralString .CommitCount "counters.n_commits" (ctx.Locale.PrettyNumber .CommitCount)}} - {{else if .IsNothingToCompare}} - {{ctx.Locale.Tr "repo.commits.nothing_to_compare"}} - {{else}} - {{ctx.Locale.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}} - {{end}} -
- {{if .IsDiffCompare}} -
- - {{if not .BaseIsCommit}}{{if .BaseIsBranch}}{{svg "octicon-git-branch"}}{{else if .BaseIsTag}}{{svg "octicon-tag"}}{{end}}{{.BaseBranch}}{{else}}{{ShortSha .BaseBranch}}{{end}} - - ... - - {{if not .HeadIsCommit}}{{if .HeadIsBranch}}{{svg "octicon-git-branch"}}{{else if .HeadIsTag}}{{svg "octicon-tag"}}{{end}}{{.HeadBranch}}{{else}}{{ShortSha .HeadBranch}}{{end}} - -
- {{end}} -

- {{if .PageIsCommits}} +

+
+ {{if or .PageIsCommits (gt .CommitCount 0)}} + {{ctx.Locale.TrPluralString .CommitCount "counters.n_commits" (ctx.Locale.PrettyNumber .CommitCount)}} + {{else if .IsNothingToCompare}} + {{ctx.Locale.Tr "repo.commits.nothing_to_compare"}} + {{else}} + {{ctx.Locale.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}} + {{end}} +
+ {{if .IsDiffCompare}} +
+ {{if not .BaseIsCommit}}{{if .BaseIsBranch}}{{svg "octicon-git-branch"}}{{else if .BaseIsTag}}{{svg "octicon-tag"}}{{end}}{{.BaseBranch}}{{else}}{{ShortSha .BaseBranch}}{{end}} + ... + {{if not .HeadIsCommit}}{{if .HeadIsBranch}}{{svg "octicon-git-branch"}}{{else if .HeadIsTag}}{{svg "octicon-tag"}}{{end}}{{.HeadBranch}}{{else}}{{ShortSha .HeadBranch}}{{end}} +
+ {{end}} +

@@ -34,7 +29,11 @@ {{end}} {{if and .Commits (gt .CommitCount 0)}} - {{template "repo/commits_list" .}} + {{if .PageIsPullCommits}} + {{template "repo/pulls/commits_list" .}} + {{else}} + {{template "repo/commits_list" .}} + {{end}} {{end}} {{if .OldFilename}} diff --git a/templates/repo/pulls/commits_list.tmpl b/templates/repo/pulls/commits_list.tmpl new file mode 100644 index 0000000000..f482f780fc --- /dev/null +++ b/templates/repo/pulls/commits_list.tmpl @@ -0,0 +1,114 @@ +{{$commitRepoLink := $.RepoLink}} +{{if $.CommitRepoLink}}{{$commitRepoLink = $.CommitRepoLink}}{{end}} +{{$prevDate := ""}} +{{range .Commits}} + {{$commitTime := .Committer.When}} + {{if not $commitTime}}{{$commitTime = .Author.When}}{{end}} + {{$commitDate := $commitTime.Format "2006-01-02"}} + {{if ne $commitDate $prevDate}} + {{if ne $prevDate ""}}
{{end}} + {{$prevDate = $commitDate}} + + +
+

{{DateUtils.AbsoluteShortWithDay $commitTime}}

+
+ {{end}} + +
+
+ {{$userName := .Author.Name}} + {{if .User}} + {{if and .User.FullName DefaultShowFullName}} + {{$userName = .User.FullName}} + {{end}} + {{ctx.AvatarUtils.Avatar .User 28}}{{$userName}} + {{else}} + {{ctx.AvatarUtils.AvatarByEmail .Author.Email .Author.Name 28}} + {{$userName}} + {{end}} +
+ +
+ {{$commitLink := (printf "%s/pulls/%d/commits/%s" $commitRepoLink $.Issue.Index (PathEscape .ID.String))}} +
+ {{RenderCommitMessageLinkSubject $.Context .Message $commitLink ($.Repository.ComposeMetas ctx)}} + {{if IsMultilineCommitMessage .Message}} + + {{end}} + + {{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}} + + {{if IsMultilineCommitMessage .Message}} +
{{RenderCommitBody $.Context .Message ($.Repository.ComposeMetas ctx)}}
+ {{end}} +
+
+ +
+
+ {{$commitShaLink := (printf "%s/pulls/%d/commits/%s" $commitRepoLink $.Issue.Index (PathEscape .ID.String))}} + {{template "repo/shabox" (dict + "sha1" .ID.String + "commitLink" $commitShaLink + "signature" .Signature + "verification" .Verification + )}} + +
+ + +
+ +
+ {{if .Committer}}{{DateUtils.TimeSince .Committer.When}}{{else}}{{DateUtils.TimeSince .Author.When}}{{end}} +
+ +
+ + {{if $.FileName}} + + {{svg "octicon-file-diff"}} + + {{end}} + + {{svg "octicon-file-code"}} + +
+
+{{end}} +
diff --git a/templates/shared/user/mention_highlight.tmpl b/templates/shared/user/mention_highlight.tmpl index 1551cef874..f7dd7fb894 100644 --- a/templates/shared/user/mention_highlight.tmpl +++ b/templates/shared/user/mention_highlight.tmpl @@ -1,7 +1,9 @@ {{if .IsSigned}}