Skip to content

Commit a778af7

Browse files
committed
Refactor the structure of the commit list page to align with GitHub's design of grouping by date.
1 parent 0668cce commit a778af7

File tree

6 files changed

+266
-7
lines changed

6 files changed

+266
-7
lines changed

routers/web/repo/commit.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"path"
1313
"strings"
14+
"time"
1415

1516
asymkey_model "code.gitea.io/gitea/models/asymkey"
1617
"code.gitea.io/gitea/models/db"
@@ -82,11 +83,12 @@ func Commits(ctx *context.Context) {
8283
ctx.ServerError("CommitsByRange", err)
8384
return
8485
}
85-
ctx.Data["Commits"], err = processGitCommits(ctx, commits)
86+
processedCommits, err := processGitCommits(ctx, commits)
8687
if err != nil {
8788
ctx.ServerError("processGitCommits", err)
8889
return
8990
}
91+
ctx.Data["GroupCommits"] = GroupCommitsByDate(processedCommits)
9092
commitIDs := make([]string, 0, len(commits))
9193
for _, c := range commits {
9294
commitIDs = append(commitIDs, c.ID.String())
@@ -198,11 +200,12 @@ func SearchCommits(ctx *context.Context) {
198200
return
199201
}
200202
ctx.Data["CommitCount"] = len(commits)
201-
ctx.Data["Commits"], err = processGitCommits(ctx, commits)
203+
processedCommits, err := processGitCommits(ctx, commits)
202204
if err != nil {
203205
ctx.ServerError("processGitCommits", err)
204206
return
205207
}
208+
ctx.Data["GroupCommits"] = GroupCommitsByDate(processedCommits)
206209

207210
ctx.Data["Keyword"] = query
208211
if all {
@@ -245,11 +248,12 @@ func FileHistory(ctx *context.Context) {
245248
ctx.ServerError("CommitsByFileAndRange", err)
246249
return
247250
}
248-
ctx.Data["Commits"], err = processGitCommits(ctx, commits)
251+
processedCommits, err := processGitCommits(ctx, commits)
249252
if err != nil {
250253
ctx.ServerError("processGitCommits", err)
251254
return
252255
}
256+
ctx.Data["GroupCommits"] = GroupCommitsByDate(processedCommits)
253257

254258
ctx.Data["Username"] = ctx.Repo.Owner.Name
255259
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
@@ -459,3 +463,38 @@ func processGitCommits(ctx *context.Context, gitCommits []*git.Commit) ([]*git_m
459463
}
460464
return commits, nil
461465
}
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+
}

routers/web/repo/compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ func PrepareCompareDiff(
661661
ctx.ServerError("processGitCommits", err)
662662
return false
663663
}
664-
ctx.Data["Commits"] = commits
664+
ctx.Data["GroupCommits"] = GroupCommitsByDate(commits)
665665
ctx.Data["CommitCount"] = len(commits)
666666

667667
title := ci.HeadBranch

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ func ViewPullCommits(ctx *context.Context) {
627627
ctx.ServerError("processGitCommits", err)
628628
return
629629
}
630-
ctx.Data["Commits"] = commits
630+
ctx.Data["GroupCommits"] = GroupCommitsByDate(commits)
631631
ctx.Data["CommitCount"] = len(commits)
632632

633633
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{{$index := 0}}
2+
{{range .GroupCommits}}
3+
{{$index = Eval $index "+" 1}}
4+
<div class="ui timeline commits_list_group_by_date" data-index="{{$index}}">
5+
6+
<div class="timeline-badge-wrapper">
7+
<div class="timeline-badge">
8+
{{svg "octicon-git-commit"}}
9+
</div>
10+
</div>
11+
12+
<div class="timeline-body">
13+
<h3 class="flex-text-block tw-py-2 timeline-heading">
14+
Commits on {{DateUtils.AbsoluteShort .Date}}
15+
</h3>
16+
<div class="tw-flex tw-mt-2 timeline-list-container">
17+
<ul class="commits-list">
18+
{{range .Commits}}
19+
{{$commitRepoLink := $.RepoLink}}{{if $.CommitRepoLink}}{{$commitRepoLink = $.CommitRepoLink}}{{end}}
20+
<li class="commits-list-item">
21+
<div class="tw-pt-4 tw-pl-4 title">
22+
<h4>
23+
<span class="message-wrapper">
24+
{{if $.PageIsWiki}}
25+
<span class="commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{.Summary | ctx.RenderUtils.RenderEmoji}}</span>
26+
{{else}}
27+
{{$commitLink:= printf "%s/commit/%s" $commitRepoLink (PathEscape .ID.String)}}
28+
<span class="commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{ctx.RenderUtils.RenderCommitMessageLinkSubject .Message $commitLink ($.Repository.ComposeMetas ctx)}}</span>
29+
{{end}}
30+
</span>
31+
{{if IsMultilineCommitMessage .Message}}
32+
<button class="ui button ellipsis-button" aria-expanded="false" data-global-click="onRepoEllipsisButtonClick">...</button>
33+
{{end}}
34+
{{if IsMultilineCommitMessage .Message}}
35+
<pre class="commit-body tw-hidden">{{ctx.RenderUtils.RenderCommitBody .Message ($.Repository.ComposeMetas ctx)}}</pre>
36+
{{end}}
37+
{{if $.CommitsTagsMap}}
38+
{{range (index $.CommitsTagsMap .ID.String)}}
39+
{{- template "repo/tag/name" dict "RepoLink" $.Repository.Link "TagName" .TagName "IsRelease" (not .IsTag) -}}
40+
{{end}}
41+
{{end}}
42+
</h4>
43+
</div>
44+
<div class="tw-flex tw-items-center tw-gap-1 tw-pb-4 tw-pl-4 description">
45+
<div class="author">
46+
{{$userName := .Author.Name}}
47+
{{if .User}}
48+
{{if and .User.FullName DefaultShowFullName}}
49+
{{$userName = .User.FullName}}
50+
{{end}}
51+
{{ctx.AvatarUtils.Avatar .User 28 "tw-mr-2"}}<a class="muted author-wrapper" href="{{.User.HomeLink}}">{{$userName}}</a>
52+
{{else}}
53+
{{ctx.AvatarUtils.AvatarByEmail .Author.Email .Author.Name 28 "tw-mr-2"}}
54+
<span class="author-wrapper">{{$userName}}</span>
55+
{{end}}
56+
</div>
57+
<span>
58+
{{if .Committer}}
59+
committed
60+
{{else}}
61+
authored
62+
{{end}}
63+
</span>
64+
{{if .Committer}}
65+
{{DateUtils.TimeSince .Committer.When}}
66+
{{else}}
67+
{{DateUtils.TimeSince .Author.When}}
68+
{{end}}
69+
{{if .Statuses}}
70+
<span>·</span>
71+
{{end}}
72+
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
73+
</div>
74+
<div class="tw-flex tw-flex-wrap tw-items-center tw-gap-2 tw-pr-4 metadata">
75+
{{$commitBaseLink := ""}}
76+
{{if $.PageIsWiki}}
77+
{{$commitBaseLink = printf "%s/wiki/commit" $commitRepoLink}}
78+
{{else if $.PageIsPullCommits}}
79+
{{$commitBaseLink = printf "%s/pulls/%d/commits" $commitRepoLink $.Issue.Index}}
80+
{{else if $.Reponame}}
81+
{{$commitBaseLink = printf "%s/commit" $commitRepoLink}}
82+
{{end}}
83+
<div>
84+
{{template "repo/commit_sign_badge" dict "Commit" . "CommitBaseLink" $commitBaseLink "CommitSignVerification" .Verification}}
85+
</div>
86+
<div class="tw-flex tw-flex-wrap tw-items-center tw-gap-2">
87+
<div>
88+
<button class="btn interact-bg tw-p-2 copy-commit-id" data-tooltip-content="{{ctx.Locale.Tr "copy_hash"}}" data-clipboard-text="{{.ID}}">{{svg "octicon-copy"}}</button>
89+
</div>
90+
{{/* at the moment, wiki doesn't support these "view" links like "view at history point" */}}
91+
{{if not $.PageIsWiki}}
92+
{{/* view single file diff */}}
93+
{{if $.FileName}}
94+
<a class="btn interact-bg tw-p-2 view-single-diff" data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_file_diff"}}"
95+
href="{{$commitRepoLink}}/commit/{{.ID.String}}?files={{$.FileName}}"
96+
>{{svg "octicon-file-diff"}}</a>
97+
{{end}}
98+
99+
{{/* view at history point */}}
100+
{{$viewCommitLink := printf "%s/src/commit/%s" $commitRepoLink (PathEscape .ID.String)}}
101+
{{if $.FileName}}{{$viewCommitLink = printf "%s/%s" $viewCommitLink (PathEscapeSegments $.FileName)}}{{end}}
102+
<a class="btn interact-bg tw-p-2 view-commit-path" data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_path"}}" href="{{$viewCommitLink}}">{{svg "octicon-file-code"}}</a>
103+
{{end}}
104+
</div>
105+
</div>
106+
</li>
107+
{{end}}
108+
</ul>
109+
</div>
110+
</div>
111+
112+
</div>
113+
{{end}}

templates/repo/commits_table.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
</div>
3030
{{end}}
3131

32-
{{if and .Commits (gt .CommitCount 0)}}
33-
{{template "repo/commits_list" .}}
32+
{{if and .GroupCommits (gt .CommitCount 0)}}
33+
{{template "repo/commits_list_group_by_date" .}}
3434
{{end}}
3535

3636
{{template "base/paginate" .}}

web_src/css/repo.css

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,3 +2277,110 @@ tbody.commit-list {
22772277
.branch-selector-dropdown .scrolling.menu .loading-indicator {
22782278
height: 4em;
22792279
}
2280+
2281+
.commits_list_group_by_date.timeline {
2282+
display: flex;
2283+
margin-left: 16px;
2284+
position: relative;
2285+
padding-bottom: 6px;
2286+
}
2287+
2288+
.commits_list_group_by_date.timeline[data-index="1"] {
2289+
margin-top: 6px;
2290+
}
2291+
2292+
.commits_list_group_by_date.timeline::before {
2293+
background-color: var(--color-timeline);
2294+
bottom: 0;
2295+
content: "";
2296+
display: block;
2297+
left: 0;
2298+
position: absolute;
2299+
top: 0;
2300+
width: 2px;
2301+
}
2302+
2303+
.commits_list_group_by_date.timeline .timeline-badge-wrapper {
2304+
position: relative;
2305+
z-index: 1;
2306+
}
2307+
2308+
.commits_list_group_by_date.timeline .timeline-badge {
2309+
border-style: solid;
2310+
border-radius: var(--border-radius-full);
2311+
color: var(--color-text);
2312+
background-color: var(--color-box-body);
2313+
float: left;
2314+
display: flex;
2315+
align-items: center;
2316+
justify-content: center;
2317+
flex-shrink: 0;
2318+
margin-left: -16px;
2319+
width: 34px;
2320+
height: 34px;
2321+
overflow: hidden;
2322+
}
2323+
2324+
.commits_list_group_by_date.timeline .timeline-heading {
2325+
font-size: 15px;
2326+
font-weight: var(--font-weight-normal);
2327+
color: var(--color-text-light-2);
2328+
margin: 0;
2329+
}
2330+
2331+
.commits_list_group_by_date.timeline .timeline-body {
2332+
max-width: 100%;
2333+
flex: auto;
2334+
padding-left: 5px;
2335+
}
2336+
2337+
.commits_list_group_by_date.timeline .timeline-list-container {
2338+
border: 1px solid var(--color-secondary);
2339+
background: var(--color-box-body);
2340+
border-radius: var(--border-radius);
2341+
}
2342+
2343+
.commits_list_group_by_date.timeline .commits-list {
2344+
list-style: none;
2345+
margin: 0;
2346+
padding: 0;
2347+
flex: auto;
2348+
}
2349+
2350+
.commits_list_group_by_date.timeline .commits-list-item {
2351+
list-style: none;
2352+
display: grid;
2353+
gap: .5rem;
2354+
min-height: 2rem;
2355+
position: relative;
2356+
--core-grid-template-columns: minmax(30%, 1fr);
2357+
--last-grid-template-column: minmax(0, max-content);
2358+
grid-template-columns: var(--core-grid-template-columns) var(--last-grid-template-column);
2359+
grid-template-areas: "primary metadata" "main-content metadata";
2360+
grid-template-rows: repeat(2, auto);
2361+
}
2362+
2363+
.commits_list_group_by_date.timeline .commits-list-item:not(:last-child) {
2364+
border-bottom: 1px solid var(--color-secondary);
2365+
}
2366+
2367+
.commits_list_group_by_date.timeline .commits-list-item:hover {
2368+
background-color: var(--color-hover)
2369+
}
2370+
2371+
.commits_list_group_by_date.timeline .commits-list-item .title {
2372+
grid-area: primary;
2373+
}
2374+
2375+
.commits_list_group_by_date.timeline .commits-list-item .description {
2376+
grid-area: main-content;
2377+
}
2378+
2379+
.commits_list_group_by_date.timeline .commits-list-item .metadata {
2380+
grid-area: metadata;
2381+
}
2382+
2383+
.commits_list_group_by_date.timeline .author img {
2384+
width: 16px;
2385+
height: 16px;
2386+
}

0 commit comments

Comments
 (0)