@@ -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}
0 commit comments