Skip to content

Commit

Permalink
Adjust branch links in feeds.tmpl - Fix go-gitea#17943
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Dec 15, 2021
1 parent beb8d6f commit f7c4de4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 16 additions & 0 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"

"xorm.io/builder"
)
Expand Down Expand Up @@ -252,6 +253,21 @@ func (a *Action) GetBranch() string {
return strings.TrimPrefix(a.RefName, git.BranchPrefix)
}

// GetRefLink returns the action's ref link.
func (a *Action) GetRefLink() string {
switch {
case strings.HasPrefix(a.RefName, git.BranchPrefix):
return a.GetRepoLink() + "/src/branch/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.BranchPrefix))
case strings.HasPrefix(a.RefName, git.TagPrefix):
return a.GetRepoLink() + "/src/tag/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.TagPrefix))
case len(a.RefName) == 40 && git.SHAPattern.MatchString(a.RefName):
return a.GetRepoLink() + "/src/commit/" + a.RefName
default:
log.Warn("Unexpected ref type for GetBranchLink: %s in %d", a.RefName, a.RepoID)
return a.GetRepoLink() + "/src/branch/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.BranchPrefix))
}
}

// GetTag returns the action's repository tag.
func (a *Action) GetTag() string {
return strings.TrimPrefix(a.RefName, git.TagPrefix)
Expand Down
16 changes: 6 additions & 10 deletions templates/user/dashboard/feeds.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
{{else if eq .GetOpType 2}}
{{$.i18n.Tr "action.rename_repo" (.GetContent|Escape) (.GetRepoLink|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{else if eq .GetOpType 5}}
{{ $branchLink := .GetBranch | PathEscapeSegments | Escape}}
{{if .Content}}
{{$.i18n.Tr "action.commit_repo" (.GetRepoLink|Escape) $branchLink (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
{{$.i18n.Tr "action.commit_repo" (.GetRepoLink|Escape) (.GetRefLink|Escape) (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
{{else}}
{{$.i18n.Tr "action.create_branch" (.GetRepoLink|Escape) $branchLink (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
{{$.i18n.Tr "action.create_branch" (.GetRepoLink|Escape) (.GetRefLink|Escape) (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
{{end}}
{{else if eq .GetOpType 6}}
{{ $index := index .GetIssueInfos 0}}
Expand All @@ -32,8 +31,7 @@
{{else if eq .GetOpType 8}}
{{$.i18n.Tr "action.transfer_repo" .GetContent (.GetRepoLink|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{else if eq .GetOpType 9}}
{{ $tagLink := .GetTag | PathEscapeSegments | Escape}}
{{$.i18n.Tr "action.push_tag" (.GetRepoLink|Escape) $tagLink (.ShortRepoPath|Escape) .GetTag | Str2html}}
{{$.i18n.Tr "action.push_tag" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.ShortRepoPath|Escape) .GetTag | Str2html}}
{{else if eq .GetOpType 10}}
{{ $index := index .GetIssueInfos 0}}
{{$.i18n.Tr "action.comment_issue" (.GetRepoLink|Escape) $index (.ShortRepoPath|Escape) | Str2html}}
Expand All @@ -59,10 +57,9 @@
{{ $index := index .GetIssueInfos 0}}
{{$.i18n.Tr "action.delete_branch" (.GetRepoLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{else if eq .GetOpType 18}}
{{ $branchLink := .GetBranch | PathEscapeSegments}}
{{$.i18n.Tr "action.mirror_sync_push" (.GetRepoLink|Escape) $branchLink (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{$.i18n.Tr "action.mirror_sync_push" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{else if eq .GetOpType 19}}
{{$.i18n.Tr "action.mirror_sync_create" (.GetRepoLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{$.i18n.Tr "action.mirror_sync_create" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{else if eq .GetOpType 20}}
{{$.i18n.Tr "action.mirror_sync_delete" (.GetRepoLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{else if eq .GetOpType 21}}
Expand All @@ -75,9 +72,8 @@
{{ $index := index .GetIssueInfos 0}}
{{$.i18n.Tr "action.comment_pull" (.GetRepoLink|Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{else if eq .GetOpType 24}}
{{ $branchLink := .GetBranch | PathEscapeSegments | Escape}}
{{ $linkText := .Content | RenderEmoji }}
{{$.i18n.Tr "action.publish_release" (.GetRepoLink|Escape) $branchLink (.ShortRepoPath|Escape) $linkText | Str2html}}
{{$.i18n.Tr "action.publish_release" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.ShortRepoPath|Escape) $linkText | Str2html}}
{{else if eq .GetOpType 25}}
{{ $index := index .GetIssueInfos 0}}
{{ $reviewer := index .GetIssueInfos 1}}
Expand Down

0 comments on commit f7c4de4

Please sign in to comment.