Skip to content

Commit 079a1ff

Browse files
BlenderDefendersilverwindwxiaoguang
authored
De-emphasize signed commits (#31160)
The new code structure is easier to make more improvements or refactor, for example: change the colors to de-emphasize more, or design some new layouts. --------- Co-authored-by: silverwind <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent ea198f9 commit 079a1ff

17 files changed

+299
-550
lines changed

routers/web/devtest/devtest.go

+82-10
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
}
+13
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

+50-129
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
{{template "base/head" .}}
2+
{{$commitLinkBase := print $.RepoLink (Iif $.PageIsWiki "/wiki" "") "/commit"}}
23
<div role="main" aria-label="{{.Title}}" class="page-content repository diff">
34
{{template "repo/header" .}}
45
<div class="ui container fluid padded">
5-
{{$class := ""}}
6-
{{if .Commit.Signature}}
7-
{{$class = (print $class " isSigned")}}
8-
{{if .Verification.Verified}}
9-
{{if eq .Verification.TrustStatus "trusted"}}
10-
{{$class = (print $class " isVerified")}}
11-
{{else if eq .Verification.TrustStatus "untrusted"}}
12-
{{$class = (print $class " isVerifiedUntrusted")}}
13-
{{else}}
14-
{{$class = (print $class " isVerifiedUnmatched")}}
15-
{{end}}
16-
{{else if .Verification.Warning}}
17-
{{$class = (print $class " isWarning")}}
18-
{{end}}
19-
{{end}}
20-
<div class="ui top attached header clearing segment tw-relative commit-header {{$class}}">
6+
<div class="ui top attached header clearing segment tw-relative commit-header">
217
<div class="tw-flex tw-mb-4 tw-gap-1">
228
<h3 class="tw-mb-0 tw-flex-1"><span class="commit-summary" title="{{.Commit.Summary}}">{{ctx.RenderUtils.RenderCommitMessage .Commit.Message ($.Repository.ComposeMetas ctx)}}</span>{{template "repo/commit_statuses" dict "Status" .CommitStatus "Statuses" .CommitStatuses}}</h3>
239
{{if not $.PageIsWiki}}
@@ -142,125 +128,59 @@
142128
{{end}}
143129
{{template "repo/commit_load_branches_and_tags" .}}
144130
</div>
145-
<div class="ui{{if not .Commit.Signature}} bottom{{end}} attached segment tw-flex tw-items-center tw-justify-between tw-py-1 commit-header-row tw-flex-wrap {{$class}}">
146-
<div class="tw-flex tw-items-center author">
147-
{{if .Author}}
148-
{{ctx.AvatarUtils.Avatar .Author 28 "tw-mr-2"}}
149-
{{if .Author.FullName}}
150-
<a href="{{.Author.HomeLink}}"><strong>{{.Author.FullName}}</strong></a>
151-
{{else}}
152-
<a href="{{.Author.HomeLink}}"><strong>{{.Commit.Author.Name}}</strong></a>
153-
{{end}}
131+
132+
<div class="ui bottom attached segment flex-text-block tw-flex-wrap">
133+
<div class="flex-text-inline">
134+
{{if .Author}}
135+
{{ctx.AvatarUtils.Avatar .Author 20}}
136+
{{if .Author.FullName}}
137+
<a href="{{.Author.HomeLink}}"><strong>{{.Author.FullName}}</strong></a>
154138
{{else}}
155-
{{ctx.AvatarUtils.AvatarByEmail .Commit.Author.Email .Commit.Author.Email 28 "tw-mr-2"}}
156-
<strong>{{.Commit.Author.Name}}</strong>
139+
<a href="{{.Author.HomeLink}}"><strong>{{.Commit.Author.Name}}</strong></a>
157140
{{end}}
158-
<span class="text grey tw-ml-2" id="authored-time">{{DateUtils.TimeSince .Commit.Author.When}}</span>
159-
{{if or (ne .Commit.Committer.Name .Commit.Author.Name) (ne .Commit.Committer.Email .Commit.Author.Email)}}
160-
<span class="text grey tw-mx-2">{{ctx.Locale.Tr "repo.diff.committed_by"}}</span>
161-
{{if ne .Verification.CommittingUser.ID 0}}
162-
{{ctx.AvatarUtils.Avatar .Verification.CommittingUser 28 "tw-mx-2"}}
163-
<a href="{{.Verification.CommittingUser.HomeLink}}"><strong>{{.Commit.Committer.Name}}</strong></a>
164-
{{else}}
165-
{{ctx.AvatarUtils.AvatarByEmail .Commit.Committer.Email .Commit.Committer.Name 28 "tw-mr-2"}}
166-
<strong>{{.Commit.Committer.Name}}</strong>
167-
{{end}}
168-
{{end}}
169-
</div>
170-
<div class="tw-flex tw-items-center">
171-
{{if .Parents}}
172-
<div>
173-
<span>{{ctx.Locale.Tr "repo.diff.parent"}}</span>
174-
{{range .Parents}}
175-
{{if $.PageIsWiki}}
176-
<a class="ui primary sha label" href="{{$.RepoLink}}/wiki/commit/{{PathEscape .}}">{{ShortSha .}}</a>
177-
{{else}}
178-
<a class="ui primary sha label" href="{{$.RepoLink}}/commit/{{PathEscape .}}">{{ShortSha .}}</a>
179-
{{end}}
180-
{{end}}
181-
</div>
182-
{{end}}
183-
<div class="item">
184-
<span>{{ctx.Locale.Tr "repo.diff.commit"}}</span>
185-
<span class="ui primary sha label">{{ShortSha .CommitID}}</span>
186-
</div>
187-
</div>
188-
</div>
189-
{{if .Commit.Signature}}
190-
<div class="ui bottom attached message tw-text-left tw-flex tw-items-center tw-justify-between commit-header-row tw-flex-wrap tw-mb-0 {{$class}}">
191-
<div class="tw-flex tw-items-center">
192-
{{if .Verification.Verified}}
193-
{{if ne .Verification.SigningUser.ID 0}}
194-
{{svg "gitea-lock" 16 "tw-mr-2"}}
195-
{{if eq .Verification.TrustStatus "trusted"}}
196-
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.signed_by"}}:</span>
197-
{{else if eq .Verification.TrustStatus "untrusted"}}
198-
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.signed_by_untrusted_user"}}:</span>
199-
{{else}}
200-
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.signed_by_untrusted_user_unmatched"}}:</span>
201-
{{end}}
202-
{{ctx.AvatarUtils.Avatar .Verification.SigningUser 28 "tw-mr-2"}}
203-
<a href="{{.Verification.SigningUser.HomeLink}}"><strong>{{.Verification.SigningUser.GetDisplayName}}</strong></a>
204-
{{else}}
205-
<span title="{{ctx.Locale.Tr "gpg.default_key"}}">{{svg "gitea-lock-cog" 16 "tw-mr-2"}}</span>
206-
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.signed_by"}}:</span>
207-
{{ctx.AvatarUtils.AvatarByEmail .Verification.SigningEmail "" 28 "tw-mr-2"}}
208-
<strong>{{.Verification.SigningUser.GetDisplayName}}</strong>
209-
{{end}}
141+
{{else}}
142+
{{ctx.AvatarUtils.AvatarByEmail .Commit.Author.Email .Commit.Author.Email 20}}
143+
<strong>{{.Commit.Author.Name}}</strong>
144+
{{end}}
145+
</div>
146+
147+
<span class="text grey">{{DateUtils.TimeSince .Commit.Author.When}}</span>
148+
149+
<div class="flex-text-inline">
150+
{{if or (ne .Commit.Committer.Name .Commit.Author.Name) (ne .Commit.Committer.Email .Commit.Author.Email)}}
151+
<span class="text grey">{{ctx.Locale.Tr "repo.diff.committed_by"}}</span>
152+
{{if ne .Verification.CommittingUser.ID 0}}
153+
{{ctx.AvatarUtils.Avatar .Verification.CommittingUser 20}}
154+
<a href="{{.Verification.CommittingUser.HomeLink}}"><strong>{{.Commit.Committer.Name}}</strong></a>
210155
{{else}}
211-
{{svg "gitea-unlock" 16 "tw-mr-2"}}
212-
<span class="ui text">{{ctx.Locale.Tr .Verification.Reason}}</span>
156+
{{ctx.AvatarUtils.AvatarByEmail .Commit.Committer.Email .Commit.Committer.Name 20}}
157+
<strong>{{.Commit.Committer.Name}}</strong>
213158
{{end}}
214-
</div>
215-
<div class="tw-flex tw-items-center">
216-
{{if .Verification.Verified}}
217-
{{if ne .Verification.SigningUser.ID 0}}
218-
{{svg "octicon-verified" 16 "tw-mr-2"}}
219-
{{if .Verification.SigningSSHKey}}
220-
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.ssh_key_fingerprint"}}:</span>
221-
{{.Verification.SigningSSHKey.Fingerprint}}
222-
{{else}}
223-
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.gpg_key_id"}}:</span>
224-
{{.Verification.SigningKey.PaddedKeyID}}
225-
{{end}}
226-
{{else}}
227-
{{svg "octicon-unverified" 16 "tw-mr-2"}}
228-
{{if .Verification.SigningSSHKey}}
229-
<span class="ui text tw-mr-2" data-tooltip-content="{{ctx.Locale.Tr "gpg.default_key"}}">{{ctx.Locale.Tr "repo.commits.ssh_key_fingerprint"}}:</span>
230-
{{.Verification.SigningSSHKey.Fingerprint}}
231-
{{else}}
232-
<span class="ui text tw-mr-2" data-tooltip-content="{{ctx.Locale.Tr "gpg.default_key"}}">{{ctx.Locale.Tr "repo.commits.gpg_key_id"}}:</span>
233-
{{.Verification.SigningKey.PaddedKeyID}}
234-
{{end}}
235-
{{end}}
236-
{{else if .Verification.Warning}}
237-
{{svg "octicon-unverified" 16 "tw-mr-2"}}
238-
{{if .Verification.SigningSSHKey}}
239-
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.ssh_key_fingerprint"}}:</span>
240-
{{.Verification.SigningSSHKey.Fingerprint}}
241-
{{else}}
242-
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.gpg_key_id"}}:</span>
243-
{{.Verification.SigningKey.PaddedKeyID}}
244-
{{end}}
245-
{{else}}
246-
{{if .Verification.SigningKey}}
247-
{{if ne .Verification.SigningKey.KeyID ""}}
248-
{{svg "octicon-verified" 16 "tw-mr-2"}}
249-
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.gpg_key_id"}}:</span>
250-
{{.Verification.SigningKey.PaddedKeyID}}
251-
{{end}}
252-
{{end}}
253-
{{if .Verification.SigningSSHKey}}
254-
{{if ne .Verification.SigningSSHKey.Fingerprint ""}}
255-
{{svg "octicon-verified" 16 "tw-mr-2"}}
256-
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.ssh_key_fingerprint"}}:</span>
257-
{{.Verification.SigningSSHKey.Fingerprint}}
258-
{{end}}
159+
{{end}}
160+
</div>
161+
162+
{{if .Verification}}
163+
{{template "repo/commit_sign_badge" dict "CommitSignVerification" .Verification}}
164+
{{end}}
165+
166+
<div class="tw-flex-1"></div>
167+
168+
<div class="flex-text-inline tw-gap-5">
169+
{{if .Parents}}
170+
<div class="flex-text-inline">
171+
<span>{{ctx.Locale.Tr "repo.diff.parent"}}</span>
172+
{{range .Parents}}
173+
<a class="ui label commit-id-short" href="{{$commitLinkBase}}/{{PathEscape .}}">{{ShortSha .}}</a>
259174
{{end}}
260-
{{end}}
175+
</div>
176+
{{end}}
177+
<div class="flex-text-inline">
178+
<span>{{ctx.Locale.Tr "repo.diff.commit"}}</span>
179+
<a class="ui label commit-id-short" href="{{$commitLinkBase}}/{{PathEscape .CommitID}}">{{ShortSha .CommitID}}</a>
261180
</div>
262181
</div>
263-
{{end}}
182+
</div>
183+
264184
{{if .NoteRendered}}
265185
<div class="ui top attached header segment git-notes">
266186
{{svg "octicon-note" 16 "tw-mr-2"}}
@@ -276,12 +196,13 @@
276196
{{else}}
277197
<strong>{{.NoteCommit.Author.Name}}</strong>
278198
{{end}}
279-
<span class="text grey" id="note-authored-time">{{DateUtils.TimeSince .NoteCommit.Author.When}}</span>
199+
<span class="text grey">{{DateUtils.TimeSince .NoteCommit.Author.When}}</span>
280200
</div>
281201
<div class="ui bottom attached info segment git-notes">
282202
<pre class="commit-body">{{.NoteRendered | SanitizeHTML}}</pre>
283203
</div>
284204
{{end}}
205+
285206
{{template "repo/diff/box" .}}
286207
</div>
287208
</div>

0 commit comments

Comments
 (0)