Skip to content

Commit f7c4de4

Browse files
committed
Adjust branch links in feeds.tmpl - Fix go-gitea#17943
Signed-off-by: Andrew Thornton <[email protected]>
1 parent beb8d6f commit f7c4de4

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

models/action.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"code.gitea.io/gitea/modules/log"
2424
"code.gitea.io/gitea/modules/setting"
2525
"code.gitea.io/gitea/modules/timeutil"
26+
"code.gitea.io/gitea/modules/util"
2627

2728
"xorm.io/builder"
2829
)
@@ -252,6 +253,21 @@ func (a *Action) GetBranch() string {
252253
return strings.TrimPrefix(a.RefName, git.BranchPrefix)
253254
}
254255

256+
// GetRefLink returns the action's ref link.
257+
func (a *Action) GetRefLink() string {
258+
switch {
259+
case strings.HasPrefix(a.RefName, git.BranchPrefix):
260+
return a.GetRepoLink() + "/src/branch/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.BranchPrefix))
261+
case strings.HasPrefix(a.RefName, git.TagPrefix):
262+
return a.GetRepoLink() + "/src/tag/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.TagPrefix))
263+
case len(a.RefName) == 40 && git.SHAPattern.MatchString(a.RefName):
264+
return a.GetRepoLink() + "/src/commit/" + a.RefName
265+
default:
266+
log.Warn("Unexpected ref type for GetBranchLink: %s in %d", a.RefName, a.RepoID)
267+
return a.GetRepoLink() + "/src/branch/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.BranchPrefix))
268+
}
269+
}
270+
255271
// GetTag returns the action's repository tag.
256272
func (a *Action) GetTag() string {
257273
return strings.TrimPrefix(a.RefName, git.TagPrefix)

templates/user/dashboard/feeds.tmpl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
{{else if eq .GetOpType 2}}
1818
{{$.i18n.Tr "action.rename_repo" (.GetContent|Escape) (.GetRepoLink|Escape) (.ShortRepoPath|Escape) | Str2html}}
1919
{{else if eq .GetOpType 5}}
20-
{{ $branchLink := .GetBranch | PathEscapeSegments | Escape}}
2120
{{if .Content}}
22-
{{$.i18n.Tr "action.commit_repo" (.GetRepoLink|Escape) $branchLink (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
21+
{{$.i18n.Tr "action.commit_repo" (.GetRepoLink|Escape) (.GetRefLink|Escape) (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
2322
{{else}}
24-
{{$.i18n.Tr "action.create_branch" (.GetRepoLink|Escape) $branchLink (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
23+
{{$.i18n.Tr "action.create_branch" (.GetRepoLink|Escape) (.GetRefLink|Escape) (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
2524
{{end}}
2625
{{else if eq .GetOpType 6}}
2726
{{ $index := index .GetIssueInfos 0}}
@@ -32,8 +31,7 @@
3231
{{else if eq .GetOpType 8}}
3332
{{$.i18n.Tr "action.transfer_repo" .GetContent (.GetRepoLink|Escape) (.ShortRepoPath|Escape) | Str2html}}
3433
{{else if eq .GetOpType 9}}
35-
{{ $tagLink := .GetTag | PathEscapeSegments | Escape}}
36-
{{$.i18n.Tr "action.push_tag" (.GetRepoLink|Escape) $tagLink (.ShortRepoPath|Escape) .GetTag | Str2html}}
34+
{{$.i18n.Tr "action.push_tag" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.ShortRepoPath|Escape) .GetTag | Str2html}}
3735
{{else if eq .GetOpType 10}}
3836
{{ $index := index .GetIssueInfos 0}}
3937
{{$.i18n.Tr "action.comment_issue" (.GetRepoLink|Escape) $index (.ShortRepoPath|Escape) | Str2html}}
@@ -59,10 +57,9 @@
5957
{{ $index := index .GetIssueInfos 0}}
6058
{{$.i18n.Tr "action.delete_branch" (.GetRepoLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
6159
{{else if eq .GetOpType 18}}
62-
{{ $branchLink := .GetBranch | PathEscapeSegments}}
63-
{{$.i18n.Tr "action.mirror_sync_push" (.GetRepoLink|Escape) $branchLink (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
60+
{{$.i18n.Tr "action.mirror_sync_push" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
6461
{{else if eq .GetOpType 19}}
65-
{{$.i18n.Tr "action.mirror_sync_create" (.GetRepoLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
62+
{{$.i18n.Tr "action.mirror_sync_create" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
6663
{{else if eq .GetOpType 20}}
6764
{{$.i18n.Tr "action.mirror_sync_delete" (.GetRepoLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
6865
{{else if eq .GetOpType 21}}
@@ -75,9 +72,8 @@
7572
{{ $index := index .GetIssueInfos 0}}
7673
{{$.i18n.Tr "action.comment_pull" (.GetRepoLink|Escape) $index (.ShortRepoPath|Escape) | Str2html}}
7774
{{else if eq .GetOpType 24}}
78-
{{ $branchLink := .GetBranch | PathEscapeSegments | Escape}}
7975
{{ $linkText := .Content | RenderEmoji }}
80-
{{$.i18n.Tr "action.publish_release" (.GetRepoLink|Escape) $branchLink (.ShortRepoPath|Escape) $linkText | Str2html}}
76+
{{$.i18n.Tr "action.publish_release" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.ShortRepoPath|Escape) $linkText | Str2html}}
8177
{{else if eq .GetOpType 25}}
8278
{{ $index := index .GetIssueInfos 0}}
8379
{{ $reviewer := index .GetIssueInfos 1}}

0 commit comments

Comments
 (0)