@@ -11,6 +11,7 @@ import (
11
11
"net/http"
12
12
"path"
13
13
"strings"
14
+ "time"
14
15
15
16
asymkey_model "code.gitea.io/gitea/models/asymkey"
16
17
"code.gitea.io/gitea/models/db"
@@ -82,11 +83,12 @@ func Commits(ctx *context.Context) {
82
83
ctx .ServerError ("CommitsByRange" , err )
83
84
return
84
85
}
85
- ctx . Data [ "Commits" ] , err = processGitCommits (ctx , commits )
86
+ processedCommits , err : = processGitCommits (ctx , commits )
86
87
if err != nil {
87
88
ctx .ServerError ("processGitCommits" , err )
88
89
return
89
90
}
91
+ ctx .Data ["GroupCommits" ] = GroupCommitsByDate (processedCommits )
90
92
commitIDs := make ([]string , 0 , len (commits ))
91
93
for _ , c := range commits {
92
94
commitIDs = append (commitIDs , c .ID .String ())
@@ -198,11 +200,12 @@ func SearchCommits(ctx *context.Context) {
198
200
return
199
201
}
200
202
ctx .Data ["CommitCount" ] = len (commits )
201
- ctx . Data [ "Commits" ] , err = processGitCommits (ctx , commits )
203
+ processedCommits , err : = processGitCommits (ctx , commits )
202
204
if err != nil {
203
205
ctx .ServerError ("processGitCommits" , err )
204
206
return
205
207
}
208
+ ctx .Data ["GroupCommits" ] = GroupCommitsByDate (processedCommits )
206
209
207
210
ctx .Data ["Keyword" ] = query
208
211
if all {
@@ -245,11 +248,12 @@ func FileHistory(ctx *context.Context) {
245
248
ctx .ServerError ("CommitsByFileAndRange" , err )
246
249
return
247
250
}
248
- ctx . Data [ "Commits" ] , err = processGitCommits (ctx , commits )
251
+ processedCommits , err : = processGitCommits (ctx , commits )
249
252
if err != nil {
250
253
ctx .ServerError ("processGitCommits" , err )
251
254
return
252
255
}
256
+ ctx .Data ["GroupCommits" ] = GroupCommitsByDate (processedCommits )
253
257
254
258
ctx .Data ["Username" ] = ctx .Repo .Owner .Name
255
259
ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
@@ -459,3 +463,38 @@ func processGitCommits(ctx *context.Context, gitCommits []*git.Commit) ([]*git_m
459
463
}
460
464
return commits , nil
461
465
}
466
+
467
+ // GroupedCommits defines the structure for grouped commits.
468
+ type GroupedCommits struct {
469
+ Date time.Time
470
+ Commits []* git_model.SignCommitWithStatuses
471
+ }
472
+
473
+ // GroupCommitsByDate groups the commits by date (in days).
474
+ func GroupCommitsByDate (commits []* git_model.SignCommitWithStatuses ) []GroupedCommits {
475
+ grouped := make (map [string ][]* git_model.SignCommitWithStatuses )
476
+
477
+ for _ , commit := range commits {
478
+ var sigTime time.Time
479
+ if commit .Committer != nil {
480
+ sigTime = commit .Committer .When
481
+ } else if commit .Author != nil {
482
+ sigTime = commit .Author .When
483
+ }
484
+
485
+ // Extract the date part
486
+ date := sigTime .Format ("2006年01月02日" )
487
+ grouped [date ] = append (grouped [date ], commit )
488
+ }
489
+
490
+ result := make ([]GroupedCommits , 0 , len (grouped ))
491
+ for dateStr , commitsGroup := range grouped {
492
+ date , _ := time .Parse ("2006年01月02日" , dateStr )
493
+ result = append (result , GroupedCommits {
494
+ Date : date ,
495
+ Commits : commitsGroup ,
496
+ })
497
+ }
498
+
499
+ return result
500
+ }
0 commit comments