Skip to content

Commit ec261b6

Browse files
authored
Refactor repo commit list (#23690)
### Before * The check of `if PullRequest.BaseRepo.Name` doesn't make sense, because the `$commitLink` is always constructed below * Many `if` blocks make the HTML tags (likely) not match in IDE. Although the rendered result matches, it's very unfriendly to editors or code analyzer, and it's difficult to read. ### After Move the `$commitLink` assignment ahead. Simplify the code, resolve the above problems.
1 parent b78c955 commit ec261b6

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

templates/repo/commits_list_small.tmpl

+8-15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
{{avatarByEmail $.root.Context .Author.Email .Author.Name}}
1414
{{end}}
1515

16+
{{$commitLink:= printf "%s/commit/%s" $.comment.Issue.PullRequest.BaseRepo.Link (PathEscape .ID.String)}}
17+
1618
<span class="ui float right shabox">
1719
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $.root}}
1820
{{$class := "ui sha label"}}
@@ -30,23 +32,14 @@
3032
{{$class = (printf "%s%s" $class " isWarning")}}
3133
{{end}}
3234
{{end}}
33-
{{if $.comment.Issue.PullRequest.BaseRepo.Name}}
34-
<a href="{{$.comment.Issue.PullRequest.BaseRepo.Link}}/commit/{{PathEscape .ID.String}}" rel="nofollow" class="{{$class}}">
35-
{{else}}
36-
<span class="{{$class}}">
37-
{{end}}
38-
<span class="shortsha">{{ShortSha .ID.String}}</span>
39-
{{if .Signature}}
40-
{{template "repo/shabox_badge" dict "root" $.root "verification" .Verification}}
41-
{{end}}
42-
{{if $.comment.Issue.PullRequest.BaseRepo.Name}}
43-
</a>
44-
{{else}}
45-
</span>
46-
{{end}}
35+
<a href="{{$commitLink}}" rel="nofollow" class="{{$class}}">
36+
<span class="shortsha">{{ShortSha .ID.String}}</span>
37+
{{if .Signature}}
38+
{{template "repo/shabox_badge" dict "root" $.root "verification" .Verification}}
39+
{{end}}
40+
</a>
4741
</span>
4842

49-
{{$commitLink:= printf "%s/commit/%s" $.comment.Issue.PullRequest.BaseRepo.Link (PathEscape .ID.String)}}
5043
<span class="gt-mono commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{RenderCommitMessageLinkSubject $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $commitLink $.comment.Issue.PullRequest.BaseRepo.ComposeMetas}}</span>
5144
{{if IsMultilineCommitMessage .Message}}
5245
<button class="ui button ellipsis-button" aria-expanded="false">...</button>

0 commit comments

Comments
 (0)