Skip to content

Commit adff3d6

Browse files
committed
fix
1 parent 71a17ef commit adff3d6

File tree

12 files changed

+196
-93
lines changed

12 files changed

+196
-93
lines changed

options/locale/locale_en-US.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ filter.private = Private
163163
no_results_found = No results found.
164164
internal_error_skipped = Internal error occurred but is skipped: %s
165165

166-
verified_commit = Verified commit
167-
unverified_commit = Unverified commit
168-
169166
[search]
170167
search = Search...
171168
type_tooltip = Search type

routers/web/devtest/devtest.go

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import (
99
"strings"
1010
"time"
1111

12+
"code.gitea.io/gitea/models/asymkey"
13+
"code.gitea.io/gitea/models/db"
14+
user_model "code.gitea.io/gitea/models/user"
15+
"code.gitea.io/gitea/modules/git"
1216
"code.gitea.io/gitea/modules/templates"
1317
"code.gitea.io/gitea/services/context"
1418
)
@@ -41,16 +45,85 @@ func FetchActionTest(ctx *context.Context) {
4145
ctx.JSONRedirect("")
4246
}
4347

44-
func Tmpl(ctx *context.Context) {
45-
now := time.Now()
46-
ctx.Data["TimeNow"] = now
47-
ctx.Data["TimePast5s"] = now.Add(-5 * time.Second)
48-
ctx.Data["TimeFuture5s"] = now.Add(5 * time.Second)
49-
ctx.Data["TimePast2m"] = now.Add(-2 * time.Minute)
50-
ctx.Data["TimeFuture2m"] = now.Add(2 * time.Minute)
51-
ctx.Data["TimePast1y"] = now.Add(-1 * 366 * 86400 * time.Second)
52-
ctx.Data["TimeFuture1y"] = now.Add(1 * 366 * 86400 * time.Second)
48+
func prepareMockData(ctx *context.Context) {
49+
if ctx.Req.URL.Path == "/devtest/gitea-ui" {
50+
now := time.Now()
51+
ctx.Data["TimeNow"] = now
52+
ctx.Data["TimePast5s"] = now.Add(-5 * time.Second)
53+
ctx.Data["TimeFuture5s"] = now.Add(5 * time.Second)
54+
ctx.Data["TimePast2m"] = now.Add(-2 * time.Minute)
55+
ctx.Data["TimeFuture2m"] = now.Add(2 * time.Minute)
56+
ctx.Data["TimePast1y"] = now.Add(-1 * 366 * 86400 * time.Second)
57+
ctx.Data["TimeFuture1y"] = now.Add(1 * 366 * 86400 * time.Second)
58+
}
59+
60+
if ctx.Req.URL.Path == "/devtest/commit-sign-badge" {
61+
var commits []*asymkey.SignCommit
62+
mockUsers, _ := db.Find[user_model.User](ctx, user_model.SearchUserOptions{ListOptions: db.ListOptions{PageSize: 1}})
63+
mockUser := mockUsers[0]
64+
commits = append(commits, &asymkey.SignCommit{
65+
Verification: &asymkey.CommitVerification{},
66+
UserCommit: &user_model.UserCommit{
67+
Commit: &git.Commit{ID: git.Sha1ObjectFormat.EmptyObjectID()},
68+
},
69+
})
70+
commits = append(commits, &asymkey.SignCommit{
71+
Verification: &asymkey.CommitVerification{
72+
Verified: true,
73+
Reason: "name / key-id",
74+
SigningUser: mockUser,
75+
SigningKey: &asymkey.GPGKey{KeyID: "12345678"},
76+
TrustStatus: "trusted",
77+
},
78+
UserCommit: &user_model.UserCommit{
79+
User: mockUser,
80+
Commit: &git.Commit{ID: git.Sha1ObjectFormat.EmptyObjectID()},
81+
},
82+
})
83+
commits = append(commits, &asymkey.SignCommit{
84+
Verification: &asymkey.CommitVerification{
85+
Verified: true,
86+
Reason: "name / key-id",
87+
SigningUser: mockUser,
88+
SigningSSHKey: &asymkey.PublicKey{Fingerprint: "aa:bb:cc:dd:ee"},
89+
TrustStatus: "untrusted",
90+
},
91+
UserCommit: &user_model.UserCommit{
92+
User: mockUser,
93+
Commit: &git.Commit{ID: git.Sha1ObjectFormat.EmptyObjectID()},
94+
},
95+
})
96+
commits = append(commits, &asymkey.SignCommit{
97+
Verification: &asymkey.CommitVerification{
98+
Verified: true,
99+
Reason: "name / key-id",
100+
SigningUser: mockUser,
101+
SigningSSHKey: &asymkey.PublicKey{Fingerprint: "aa:bb:cc:dd:ee"},
102+
TrustStatus: "other(unmatch)",
103+
},
104+
UserCommit: &user_model.UserCommit{
105+
User: mockUser,
106+
Commit: &git.Commit{ID: git.Sha1ObjectFormat.EmptyObjectID()},
107+
},
108+
})
109+
commits = append(commits, &asymkey.SignCommit{
110+
Verification: &asymkey.CommitVerification{
111+
Warning: true,
112+
Reason: "gpg.error",
113+
SigningEmail: "[email protected]",
114+
},
115+
UserCommit: &user_model.UserCommit{
116+
User: mockUser,
117+
Commit: &git.Commit{ID: git.Sha1ObjectFormat.EmptyObjectID()},
118+
},
119+
})
120+
121+
ctx.Data["MockCommits"] = commits
122+
}
123+
}
53124

125+
func Tmpl(ctx *context.Context) {
126+
prepareMockData(ctx)
54127
if ctx.Req.Method == "POST" {
55128
_ = ctx.Req.ParseForm()
56129
ctx.Flash.Info("form: "+ctx.Req.Method+" "+ctx.Req.RequestURI+"<br>"+
@@ -60,6 +133,5 @@ func Tmpl(ctx *context.Context) {
60133
)
61134
time.Sleep(2 * time.Second)
62135
}
63-
64136
ctx.HTML(http.StatusOK, templates.TplName("devtest"+path.Clean("/"+ctx.PathParam("sub"))))
65137
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{template "devtest/devtest-header"}}
2+
<div class="page-content devtest ui container">
3+
<div>
4+
<h1>Commit Sign Badges</h1>
5+
{{range $commit := .MockCommits}}
6+
<div class="flex-text-block tw-my-2">
7+
{{template "repo/commit_sign_badge" dict "Commit" $commit "CommitBaseLink" "/devtest/commit" "CommitSignVerification" $commit.Verification}}
8+
{{template "repo/commit_sign_badge" dict "CommitSignVerification" $commit.Verification}}
9+
</div>
10+
{{end}}
11+
</div>
12+
</div>
13+
{{template "devtest/devtest-footer"}}

templates/repo/commit_page.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
</div>
161161

162162
{{if .Verification}}
163-
{{template "repo/signature_badge" dict "CommitSignVerification" .Verification}}
163+
{{template "repo/commit_sign_badge" dict "CommitSignVerification" .Verification}}
164164
{{end}}
165165

166166
<div class="tw-flex-1"></div>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{{/* Template attributes:
2+
* Commit
3+
* CommitBaseLink
4+
* CommitSignVerification
5+
If you'd like to modify this template, you could test it on the devtest page
6+
*/}}
7+
{{- $commit := $.Commit -}}
8+
{{- $commitBaseLink := $.CommitBaseLink -}}
9+
{{- $verification := $.CommitSignVerification -}}
10+
{{- $extraClass := "" -}}
11+
{{- $verified := false -}}
12+
{{- $trusted := false -}}
13+
{{- $signingUser := NIL -}}
14+
{{- $signingEmail := "" -}}
15+
{{- $msgReasonPrefix := "" -}}
16+
{{- $msgReason := "" -}}
17+
{{- $msgSigningKey := "" -}}
18+
19+
{{- $signingUser = $verification.SigningUser -}}
20+
{{- $signingEmail = $verification.SigningEmail -}}
21+
{{- $extraClass = print $extraClass " commit-is-signed" -}}
22+
{{- if $verification.Verified -}}
23+
{{- /* reason is "{name} / {key-id}" */ -}}
24+
{{- $msgReason = $verification.Reason -}}
25+
{{- $verified = true -}}
26+
{{- if eq $verification.TrustStatus "trusted" -}}
27+
{{- $extraClass = print $extraClass " sign-trusted" -}}
28+
{{- $trusted = true -}}
29+
{{- else if eq $verification.TrustStatus "untrusted" -}}
30+
{{- $extraClass = print $extraClass " sign-untrusted" -}}
31+
{{- $msgReasonPrefix = ctx.Locale.Tr "repo.commits.signed_by_untrusted_user" -}}
32+
{{- else -}}
33+
{{- $extraClass = print $extraClass " sign-unmatched" -}}
34+
{{- $msgReasonPrefix = ctx.Locale.Tr "repo.commits.signed_by_untrusted_user_unmatched" -}}
35+
{{- end -}}
36+
{{- else -}}
37+
{{- if $verification.Warning -}}
38+
{{- $extraClass = print $extraClass " sign-warning" -}}
39+
{{- end -}}
40+
{{- $msgReason = ctx.Locale.Tr $verification.Reason -}}{{- /* dirty part: it is the translation key ..... */ -}}
41+
{{- end -}}
42+
43+
{{- if $msgReasonPrefix -}}
44+
{{- $msgReason = print $msgReasonPrefix ": " $msgReason -}}
45+
{{- end -}}
46+
47+
{{- if $verification.SigningSSHKey -}}
48+
{{- $msgSigningKey = print (ctx.Locale.Tr "repo.commits.ssh_key_fingerprint") ": " $verification.SigningSSHKey.Fingerprint -}}
49+
{{- else if $verification.SigningKey -}}
50+
{{- $msgSigningKey = print (ctx.Locale.Tr "repo.commits.gpg_key_id") ": " $verification.SigningKey.PaddedKeyID -}}
51+
{{- end -}}
52+
53+
{{- if $commit -}}
54+
<a {{if $commitBaseLink}}href="{{$commitBaseLink}}/{{$commit.ID}}"{{end}} class="ui label commit-id-short {{$extraClass}}" rel="nofollow">
55+
{{- ShortSha $commit.ID.String -}}
56+
{{- end -}}
57+
<span class="ui label commit-sign-badge {{$extraClass}}">
58+
{{- if $verified -}}
59+
{{- if and $signingUser $signingUser.ID -}}
60+
<span data-tooltip-content="{{$msgReason}}">{{svg "gitea-lock"}}</span>
61+
<span data-tooltip-content="{{$msgSigningKey}}">{{ctx.AvatarUtils.Avatar $signingUser 16}}</span>
62+
{{- else -}}
63+
<span data-tooltip-content="{{$msgReason}}">{{svg "gitea-lock-cog"}}</span>
64+
<span data-tooltip-content="{{$msgSigningKey}}">{{ctx.AvatarUtils.AvatarByEmail $signingEmail "" 16}}</span>
65+
{{- end -}}
66+
{{- else -}}
67+
<span data-tooltip-content="{{$msgReason}}">{{svg "gitea-unlock"}}</span>
68+
{{- end -}}
69+
</span>
70+
71+
{{- if $commit -}}
72+
</a>
73+
{{- end -}}

templates/repo/commits_list.tmpl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,15 @@
2929
</div>
3030
</td>
3131
<td class="sha">
32-
{{$commitShaLink := ""}}
32+
{{$commitBaseLink := ""}}
3333
{{if $.PageIsWiki}}
34-
{{$commitShaLink = (printf "%s/wiki/commit/%s" $commitRepoLink (PathEscape .ID.String))}}
34+
{{$commitBaseLink = printf "%s/wiki/commit" $commitRepoLink}}
3535
{{else if $.PageIsPullCommits}}
36-
{{$commitShaLink = (printf "%s/pulls/%d/commits/%s" $commitRepoLink $.Issue.Index (PathEscape .ID.String))}}
36+
{{$commitBaseLink = printf "%s/pulls/%d/commits" $commitRepoLink $.Issue.Index}}
3737
{{else if $.Reponame}}
38-
{{$commitShaLink = (printf "%s/commit/%s" $commitRepoLink (PathEscape .ID.String))}}
39-
{{end}}
40-
<a {{if $commitShaLink}}href="{{$commitShaLink}}"{{end}} class="ui label commit-id-short">{{ShortSha .ID.String}}</a>
41-
{{if .Verification}}
42-
{{template "repo/signature_badge" dict "CommitSignVerification" .Verification}}
38+
{{$commitBaseLink = printf "%s/commit" $commitRepoLink}}
4339
{{end}}
40+
{{template "repo/commit_sign_badge" dict "Commit" . "CommitBaseLink" $commitBaseLink "CommitSignVerification" .Verification}}
4441
</td>
4542
<td class="message">
4643
<span class="message-wrapper">

templates/repo/commits_list_small.tmpl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
{{ctx.AvatarUtils.AvatarByEmail .Author.Email .Author.Name 20}}
1212
{{end}}
1313

14-
{{$commitLink:= printf "%s/commit/%s" $.comment.Issue.PullRequest.BaseRepo.Link (PathEscape .ID.String)}}
14+
{{$commitBaseLink := printf "%s/commit" $.comment.Issue.PullRequest.BaseRepo.Link}}
15+
{{$commitLink:= printf "%s/%s" $commitBaseLink (PathEscape .ID.String)}}
1516

1617
<span class="tw-flex-1 tw-font-mono gt-ellipsis" title="{{.Summary}}">
1718
{{- ctx.RenderUtils.RenderCommitMessageLinkSubject .Message $commitLink ($.comment.Issue.PullRequest.BaseRepo.ComposeMetas ctx) -}}
@@ -23,10 +24,7 @@
2324

2425
<span class="tw-flex tw-items-center tw-gap-2">
2526
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
26-
<a href="{{$commitLink}}" rel="nofollow" class="ui label commit-id-short">{{ShortSha .ID.String}}</a>
27-
{{if .Verification}}
28-
{{template "repo/signature_badge" dict "CommitSignVerification" .Verification}}
29-
{{end}}
27+
{{template "repo/commit_sign_badge" dict "Commit" . "CommitBaseLink" $commitBaseLink "CommitSignVerification" .Verification}}
3028
</span>
3129
</div>
3230
{{if IsMultilineCommitMessage .Message}}

templates/repo/graph/commits.tmpl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
{{if $commit.OnlyRelation}}
66
<span></span>
77
{{else}}
8-
<a class="ui label commit-id-short" href="{{$.RepoLink}}/commit/{{$commit.Rev|PathEscape}}" rel="nofollow">{{ShortSha $commit.Commit.ID.String}}</a>
9-
10-
{{- if $commit.Verification -}}
11-
{{template "repo/signature_badge" dict "CommitSignVerification" $commit.Verification}}
12-
{{- end -}}
8+
{{template "repo/commit_sign_badge" dict "Commit" $commit.Commit "CommitBaseLink" (print $.RepoLink "/commit") "CommitSignVerification" $commit.Verification}}
139

1410
<span class="message tw-inline-block gt-ellipsis">
1511
<span>{{ctx.RenderUtils.RenderCommitMessage $commit.Subject ($.Repository.ComposeMetas ctx)}}</span>

templates/repo/latest_commit.tmpl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
{{end}}
1717
{{end}}
1818

19-
<a rel="nofollow" class="ui label commit-id-short" href="{{.RepoLink}}/commit/{{PathEscape .LatestCommit.ID.String}}">{{ShortSha .LatestCommit.ID.String}}</a>
20-
21-
{{if .LatestCommitVerification}}
22-
{{template "repo/signature_badge" dict "CommitSignVerification" .LatestCommitVerification}}
23-
{{end}}
19+
{{template "repo/commit_sign_badge" dict "Commit" .LatestCommit "CommitBaseLink" (print .RepoLink "/commit") "CommitSignVerification" .LatestCommitVerification}}
2420

2521
{{template "repo/commit_statuses" dict "Status" .LatestCommitStatus "Statuses" .LatestCommitStatuses}}
2622

templates/repo/signature_badge.tmpl

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)