Skip to content

Commit 30cea70

Browse files
authored
Refactor dashboard/feed.tmpl (#26956)
- ~~Refactor `ActionType` to `models/activities/action_type.go`~~ - Replace the magic number in `feed.tmlp` with `InAction`
1 parent f20e317 commit 30cea70

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

models/activities/action.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ func (at ActionType) String() string {
126126
}
127127
}
128128

129+
func (at ActionType) InActions(actions ...string) bool {
130+
for _, action := range actions {
131+
if action == at.String() {
132+
return true
133+
}
134+
}
135+
return false
136+
}
137+
129138
// Action represents user operation type and other information to
130139
// repository. It implemented interface base.Actioner so that can be
131140
// used in template render.

templates/user/dashboard/feeds.tmpl

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,75 +11,75 @@
1111
{{else}}
1212
{{.ShortActUserName}}
1313
{{end}}
14-
{{if eq .GetOpType 1}}
14+
{{if .GetOpType.InActions "create_repo"}}
1515
{{$.locale.Tr "action.create_repo" (.GetRepoLink|Escape) (.ShortRepoPath|Escape) | Str2html}}
16-
{{else if eq .GetOpType 2}}
16+
{{else if .GetOpType.InActions "rename_repo"}}
1717
{{$.locale.Tr "action.rename_repo" (.GetContent|Escape) (.GetRepoLink|Escape) (.ShortRepoPath|Escape) | Str2html}}
18-
{{else if eq .GetOpType 5}}
18+
{{else if .GetOpType.InActions "commit_repo"}}
1919
{{if .Content}}
2020
{{$.locale.Tr "action.commit_repo" (.GetRepoLink|Escape) (.GetRefLink|Escape) (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
2121
{{else}}
2222
{{$.locale.Tr "action.create_branch" (.GetRepoLink|Escape) (.GetRefLink|Escape) (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
2323
{{end}}
24-
{{else if eq .GetOpType 6}}
24+
{{else if .GetOpType.InActions "create_issue"}}
2525
{{$index := index .GetIssueInfos 0}}
2626
{{$.locale.Tr "action.create_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
27-
{{else if eq .GetOpType 7}}
27+
{{else if .GetOpType.InActions "create_pull_request"}}
2828
{{$index := index .GetIssueInfos 0}}
2929
{{$.locale.Tr "action.create_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
30-
{{else if eq .GetOpType 8}}
30+
{{else if .GetOpType.InActions "transfer_repo"}}
3131
{{$.locale.Tr "action.transfer_repo" .GetContent (.GetRepoLink|Escape) (.ShortRepoPath|Escape) | Str2html}}
32-
{{else if eq .GetOpType 9}}
32+
{{else if .GetOpType.InActions "push_tag"}}
3333
{{$.locale.Tr "action.push_tag" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.GetTag|Escape) (.ShortRepoPath|Escape) | Str2html}}
34-
{{else if eq .GetOpType 10}}
34+
{{else if .GetOpType.InActions "comment_issue"}}
3535
{{$index := index .GetIssueInfos 0}}
3636
{{$.locale.Tr "action.comment_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
37-
{{else if eq .GetOpType 11}}
37+
{{else if .GetOpType.InActions "merge_pull_request"}}
3838
{{$index := index .GetIssueInfos 0}}
3939
{{$.locale.Tr "action.merge_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
40-
{{else if eq .GetOpType 12}}
40+
{{else if .GetOpType.InActions "close_issue"}}
4141
{{$index := index .GetIssueInfos 0}}
4242
{{$.locale.Tr "action.close_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
43-
{{else if eq .GetOpType 13}}
43+
{{else if .GetOpType.InActions "reopen_issue"}}
4444
{{$index := index .GetIssueInfos 0}}
4545
{{$.locale.Tr "action.reopen_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
46-
{{else if eq .GetOpType 14}}
46+
{{else if .GetOpType.InActions "close_pull_request"}}
4747
{{$index := index .GetIssueInfos 0}}
4848
{{$.locale.Tr "action.close_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
49-
{{else if eq .GetOpType 15}}
49+
{{else if .GetOpType.InActions "reopen_pull_request"}}
5050
{{$index := index .GetIssueInfos 0}}
5151
{{$.locale.Tr "action.reopen_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
52-
{{else if eq .GetOpType 16}}
52+
{{else if .GetOpType.InActions "delete_tag"}}
5353
{{$index := index .GetIssueInfos 0}}
5454
{{$.locale.Tr "action.delete_tag" (.GetRepoLink|Escape) (.GetTag|Escape) (.ShortRepoPath|Escape) | Str2html}}
55-
{{else if eq .GetOpType 17}}
55+
{{else if .GetOpType.InActions "delete_branch"}}
5656
{{$index := index .GetIssueInfos 0}}
5757
{{$.locale.Tr "action.delete_branch" (.GetRepoLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
58-
{{else if eq .GetOpType 18}}
58+
{{else if .GetOpType.InActions "mirror_sync_push"}}
5959
{{$.locale.Tr "action.mirror_sync_push" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
60-
{{else if eq .GetOpType 19}}
60+
{{else if .GetOpType.InActions "mirror_sync_create"}}
6161
{{$.locale.Tr "action.mirror_sync_create" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
62-
{{else if eq .GetOpType 20}}
62+
{{else if .GetOpType.InActions "mirror_sync_delete"}}
6363
{{$.locale.Tr "action.mirror_sync_delete" (.GetRepoLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
64-
{{else if eq .GetOpType 21}}
64+
{{else if .GetOpType.InActions "approve_pull_request"}}
6565
{{$index := index .GetIssueInfos 0}}
6666
{{$.locale.Tr "action.approve_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
67-
{{else if eq .GetOpType 22}}
67+
{{else if .GetOpType.InActions "reject_pull_request"}}
6868
{{$index := index .GetIssueInfos 0}}
6969
{{$.locale.Tr "action.reject_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
70-
{{else if eq .GetOpType 23}}
70+
{{else if .GetOpType.InActions "comment_pull"}}
7171
{{$index := index .GetIssueInfos 0}}
7272
{{$.locale.Tr "action.comment_pull" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
73-
{{else if eq .GetOpType 24}}
73+
{{else if .GetOpType.InActions "publish_release"}}
7474
{{$linkText := .Content | RenderEmoji $.Context}}
7575
{{$.locale.Tr "action.publish_release" (.GetRepoLink|Escape) ((printf "%s/releases/tag/%s" .GetRepoLink .GetTag)|Escape) (.ShortRepoPath|Escape) $linkText | Str2html}}
76-
{{else if eq .GetOpType 25}}
76+
{{else if .GetOpType.InActions "review_dismissed"}}
7777
{{$index := index .GetIssueInfos 0}}
7878
{{$reviewer := index .GetIssueInfos 1}}
7979
{{$.locale.Tr "action.review_dismissed" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) $reviewer | Str2html}}
8080
{{end}}
8181
</div>
82-
{{if or (eq .GetOpType 5) (eq .GetOpType 18)}}
82+
{{if .GetOpType.InActions "commit_repo" "mirror_sync_push"}}
8383
{{$push := ActionContent2Commits .}}
8484
{{$repoLink := .GetRepoLink}}
8585
{{range $push.Commits}}
@@ -95,21 +95,21 @@
9595
{{if and (gt $push.Len 1) $push.CompareURL}}
9696
<a href="{{AppSubUrl}}/{{$push.CompareURL}}">{{$.locale.Tr "action.compare_commits" $push.Len}} »</a>
9797
{{end}}
98-
{{else if eq .GetOpType 6}}
98+
{{else if .GetOpType.InActions "create_issue"}}
9999
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji $.Context | RenderCodeBlock}}</span>
100-
{{else if eq .GetOpType 7}}
100+
{{else if .GetOpType.InActions "create_pull_request"}}
101101
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji $.Context | RenderCodeBlock}}</span>
102-
{{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22) (eq .GetOpType 23)}}
102+
{{else if .GetOpType.InActions "comment_issue" "approve_pull_request" "reject_pull_request" "comment_pull"}}
103103
<a href="{{.GetCommentLink}}" class="text truncate issue title">{{.GetIssueTitle | RenderEmoji $.Context | RenderCodeBlock}}</a>
104104
{{$comment := index .GetIssueInfos 1}}
105105
{{if gt (len $comment) 0}}
106106
<div class="flex-item-body">{{$comment | RenderEmoji $.Context | RenderCodeBlock}}</div>
107107
{{end}}
108-
{{else if eq .GetOpType 11}}
108+
{{else if .GetOpType.InActions "merge_pull_request"}}
109109
<div class="flex-item-body">{{index .GetIssueInfos 1}}</div>
110-
{{else if or (eq .GetOpType 12) (eq .GetOpType 13) (eq .GetOpType 14) (eq .GetOpType 15)}}
110+
{{else if .GetOpType.InActions "close_issue" "reopen_issue" "close_pull_request" "reopen_pull_request"}}
111111
<span class="text truncate issue title">{{.GetIssueTitle | RenderEmoji $.Context | RenderCodeBlock}}</span>
112-
{{else if eq .GetOpType 25}}
112+
{{else if .GetOpType.InActions "pull_review_dismissed"}}
113113
<div class="flex-item-body">{{$.locale.Tr "action.review_dismissed_reason"}}</div>
114114
<div class="flex-item-body">{{index .GetIssueInfos 2 | RenderEmoji $.Context}}</div>
115115
{{end}}

0 commit comments

Comments
 (0)