mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-11 11:28:02 -05:00
875b398e5e
Backport #26745
Fixes #26548
This PR refactors the rendering of markup links. The old code uses
`strings.Replace` to change some urls while the new code uses more
context to decide which link should be generated.
The added tests should ensure the same output for the old and new
behaviour (besides the bug).
We may need to refactor the rendering a bit more to make it clear how
the different helper methods render the input string. There are lots of
options (resolve links / images / mentions / git hashes / emojis / ...)
but you don't really know what helper uses which options. For example,
we currently support images in the user description which should not be
allowed I think:
<details>
<summary>Profile</summary>
https://try.gitea.io/KN4CK3R
![grafik](https://github.com/go-gitea/gitea/assets/1666336/109ae422-496d-4200-b52e-b3a528f553e5)
</details>
(cherry picked from commit 022552d5b6
)
126 lines
8.5 KiB
Go HTML Template
126 lines
8.5 KiB
Go HTML Template
<div id="activity-feed" class="flex-list">
|
|
{{range .Feeds}}
|
|
<div class="flex-item">
|
|
<div class="flex-item-leading">
|
|
{{ctx.AvatarUtils.AvatarByAction .}}
|
|
</div>
|
|
<div class="flex-item-main gt-gap-3">
|
|
<div>
|
|
{{if gt .ActUser.ID 0}}
|
|
<a href="{{AppSubUrl}}/{{(.GetActUserName ctx) | PathEscape}}" title="{{.GetDisplayNameTitle ctx}}">{{.GetDisplayName ctx}}</a>
|
|
{{else}}
|
|
{{.ShortActUserName ctx}}
|
|
{{end}}
|
|
{{if .GetOpType.InActions "create_repo"}}
|
|
{{ctx.Locale.Tr "action.create_repo" ((.GetRepoLink ctx)|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "rename_repo"}}
|
|
{{ctx.Locale.Tr "action.rename_repo" (.GetContent|Escape) ((.GetRepoLink ctx)|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "commit_repo"}}
|
|
{{if .Content}}
|
|
{{ctx.Locale.Tr "action.commit_repo" ((.GetRepoLink ctx)|Escape) ((.GetRefLink ctx)|Escape) (Escape .GetBranch) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else}}
|
|
{{ctx.Locale.Tr "action.create_branch" ((.GetRepoLink ctx)|Escape) ((.GetRefLink ctx)|Escape) (Escape .GetBranch) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{end}}
|
|
{{else if .GetOpType.InActions "create_issue"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.create_issue" ((printf "%s/issues/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "create_pull_request"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.create_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "transfer_repo"}}
|
|
{{ctx.Locale.Tr "action.transfer_repo" .GetContent ((.GetRepoLink ctx)|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "push_tag"}}
|
|
{{ctx.Locale.Tr "action.push_tag" ((.GetRepoLink ctx)|Escape) ((.GetRefLink ctx)|Escape) (.GetTag|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "comment_issue"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.comment_issue" ((printf "%s/issues/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "merge_pull_request"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.merge_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "close_issue"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.close_issue" ((printf "%s/issues/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "reopen_issue"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.reopen_issue" ((printf "%s/issues/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "close_pull_request"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.close_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "reopen_pull_request"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.reopen_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "delete_tag"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.delete_tag" ((.GetRepoLink ctx)|Escape) (.GetTag|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "delete_branch"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.delete_branch" ((.GetRepoLink ctx)|Escape) (.GetBranch|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "mirror_sync_push"}}
|
|
{{ctx.Locale.Tr "action.mirror_sync_push" ((.GetRepoLink ctx)|Escape) ((.GetRefLink ctx)|Escape) (.GetBranch|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "mirror_sync_create"}}
|
|
{{ctx.Locale.Tr "action.mirror_sync_create" ((.GetRepoLink ctx)|Escape) ((.GetRefLink ctx)|Escape) (.GetBranch|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "mirror_sync_delete"}}
|
|
{{ctx.Locale.Tr "action.mirror_sync_delete" ((.GetRepoLink ctx)|Escape) (.GetBranch|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "approve_pull_request"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.approve_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "reject_pull_request"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.reject_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "comment_pull"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{ctx.Locale.Tr "action.comment_pull" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
|
|
{{else if .GetOpType.InActions "publish_release"}}
|
|
{{$linkText := .Content | RenderEmoji $.Context}}
|
|
{{ctx.Locale.Tr "action.publish_release" ((.GetRepoLink ctx)|Escape) ((printf "%s/releases/tag/%s" (.GetRepoLink ctx) .GetTag)|Escape) ((.ShortRepoPath ctx)|Escape) $linkText | Str2html}}
|
|
{{else if .GetOpType.InActions "review_dismissed"}}
|
|
{{$index := index .GetIssueInfos 0}}
|
|
{{$reviewer := index .GetIssueInfos 1}}
|
|
{{ctx.Locale.Tr "action.review_dismissed" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) $reviewer | Str2html}}
|
|
{{end}}
|
|
{{TimeSince .GetCreate ctx.Locale}}
|
|
</div>
|
|
{{if .GetOpType.InActions "commit_repo" "mirror_sync_push"}}
|
|
{{$push := ActionContent2Commits .}}
|
|
{{$repoLink := (.GetRepoLink ctx)}}
|
|
<div class="gt-df gt-fc gt-gap-2">
|
|
{{range $push.Commits}}
|
|
{{$commitLink := printf "%s/commit/%s" $repoLink .Sha1}}
|
|
<div class="flex-text-block">
|
|
<img class="ui avatar" src="{{$push.AvatarLink $.Context .AuthorEmail}}" title="{{.AuthorName}}" width="16" height="16">
|
|
<a class="ui sha label" href="{{$commitLink}}">{{ShortSha .Sha1}}</a>
|
|
<span class="text truncate">
|
|
{{RenderCommitMessage $.Context .Message $.ComposeMetas}}
|
|
</span>
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
{{if and (gt $push.Len 1) $push.CompareURL}}
|
|
<a href="{{AppSubUrl}}/{{$push.CompareURL}}">{{ctx.Locale.Tr "action.compare_commits" $push.Len}} »</a>
|
|
{{end}}
|
|
{{else if .GetOpType.InActions "create_issue"}}
|
|
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji $.Context | RenderCodeBlock}}</span>
|
|
{{else if .GetOpType.InActions "create_pull_request"}}
|
|
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji $.Context | RenderCodeBlock}}</span>
|
|
{{else if .GetOpType.InActions "comment_issue" "approve_pull_request" "reject_pull_request" "comment_pull"}}
|
|
<a href="{{.GetCommentLink ctx}}" class="text truncate issue title">{{(.GetIssueTitle ctx) | RenderEmoji $.Context | RenderCodeBlock}}</a>
|
|
{{$comment := index .GetIssueInfos 1}}
|
|
{{if $comment}}
|
|
<div class="markup gt-font-14">{{RenderMarkdownToHtml ctx $comment}}</div>
|
|
{{end}}
|
|
{{else if .GetOpType.InActions "merge_pull_request"}}
|
|
<div class="flex-item-body text black">{{index .GetIssueInfos 1}}</div>
|
|
{{else if .GetOpType.InActions "close_issue" "reopen_issue" "close_pull_request" "reopen_pull_request"}}
|
|
<span class="text truncate issue title">{{(.GetIssueTitle ctx) | RenderEmoji $.Context | RenderCodeBlock}}</span>
|
|
{{else if .GetOpType.InActions "pull_review_dismissed"}}
|
|
<div class="flex-item-body text black">{{ctx.Locale.Tr "action.review_dismissed_reason"}}</div>
|
|
<div class="flex-item-body text black">{{index .GetIssueInfos 2 | RenderEmoji $.Context}}</div>
|
|
{{end}}
|
|
</div>
|
|
<div class="flex-item-trailing">
|
|
{{svg (printf "octicon-%s" (ActionIcon .GetOpType)) 32 "text grey gt-mr-2"}}
|
|
</div>
|
|
</div>
|
|
{{end}}
|
|
{{template "base/paginate" .}}
|
|
</div>
|