diff --git a/public/pull-commits.css b/components/repository/commit-groups/commit-groups.css similarity index 77% rename from public/pull-commits.css rename to components/repository/commit-groups/commit-groups.css index 7c6bb12f..e4a19eb7 100644 --- a/public/pull-commits.css +++ b/components/repository/commit-groups/commit-groups.css @@ -1,5 +1,6 @@ -/* PR and compare-page date groups build on the global commit-row component. */ -:is(.github-pull-review, .github-compare) .pull-commit-group { +/* GitHub's commit history: a timeline of days, each a box of commit rows (the shared commit row) under "Commits on + ". The repository history, a pull request's commits and the compare page use it. */ +.theme-commit-group { position: relative; margin-left: 16px; padding: 0 0 16px 24px; @@ -37,10 +38,14 @@ & .message { min-width: 0; } - & .commit-summary { + /* Inline text, so a title with an issue link wraps like a sentence; the shared row's inline-flex would stack its + pieces side by side. As specific as that rule, and loaded after it. */ + & .message > .commit-summary { + display: inline; font-size: 16px; line-height: 24px; font-weight: 600; + white-space: normal; overflow-wrap: anywhere; } & .metadata { @@ -67,7 +72,7 @@ } } @media (max-width: 767.98px) { - :is(.github-pull-review, .github-compare) .pull-commit-group { + .theme-commit-group { margin-left: 8px; padding-left: 16px; & > ul > li.gitea-github-theme-commit { diff --git a/components/repository/commit-groups/commit-groups.tmpl b/components/repository/commit-groups/commit-groups.tmpl new file mode 100644 index 00000000..57712791 --- /dev/null +++ b/components/repository/commit-groups/commit-groups.tmpl @@ -0,0 +1,16 @@ +{{/* Commits grouped by the day they were committed, newest first as Forgejo lists them, each day a box of shared +commit rows. Called with the page context. */}} +{{$previousDate := ""}} +{{range .Commits}} + {{$time := .Committer.When}}{{if not $time}}{{$time = .Author.When}}{{end}} + {{$date := $time.Format "2006-01-02"}} + {{if ne $date $previousDate}} + {{if ne $previousDate ""}}{{end}} + {{$previousDate = $date}} +
+

{{svg "octicon-git-commit" 16}}Commits on {{$time.Format "Jan 2, 2006"}}

+
{{end}} diff --git a/scripts/assembleForgejo.ts b/scripts/assembleForgejo.ts index 6f9701e5..69f3ff3f 100644 --- a/scripts/assembleForgejo.ts +++ b/scripts/assembleForgejo.ts @@ -44,6 +44,7 @@ for (const directory of ["common", "project", "repository"]) { } for (const file of [ + "commits.css", "dashboard-lists.css", "organization.css", "profile-subpages.css", diff --git a/src/build-output.test.ts b/src/build-output.test.ts index 296e530d..1c894dd3 100644 --- a/src/build-output.test.ts +++ b/src/build-output.test.ts @@ -544,6 +544,24 @@ describe("Forgejo 15 native integration", () => { ); }); + it("shows the repository history as GitHub's Commits page grouped by day", () => { + const read = (...parts: string[]) => fs.readFileSync(path.join(ROOT_DIR, ...parts), "utf-8"); + const commits = read("templates", "repo", "commits.tmpl"); + expect(commits).toContain('{{ctx.Locale.Tr "repo.commits.commits"}}'); + expect(commits).not.toContain('template "repo/sub_menu"'); + expect(commits).toContain('"Items" "repo/commits_search_scope"'); + for (const list of [ + ["templates", "repo", "commits_list.tmpl"], + ["templates", "repo", "pulls", "commits_list.tmpl"], + ]) + expect(read(...list)).toContain('template "components/repository/commit-groups/commit-groups"'); + expect(read("components", "repository", "commit-groups", "commit-groups.tmpl")).toContain( + '
' + ); + expect(fs.existsSync(path.join(ROOT_DIR, "public", "pull-commits.css"))).toBe(false); + expect(read("templates", "base", "component_assets.tmpl")).toContain("/css/components/pages/commits.css"); + }); + it("matches GitHub's repository About, visibility, and code-search details", () => { const headerStyle = fs.readFileSync(path.join(ROOT_DIR, "styles", "templates", "repo", "header.ts"), "utf-8"); const headerTemplate = fs.readFileSync(path.join(ROOT_DIR, "templates", "repo", "home_header.tmpl"), "utf-8"); @@ -582,7 +600,10 @@ describe("Forgejo 15 native integration", () => { path.join(ROOT_DIR, "templates", "repo", "latest_commit_row.tmpl"), "utf-8" ); - const commitsListTemplate = fs.readFileSync(path.join(ROOT_DIR, "templates", "repo", "commits_list.tmpl"), "utf-8"); + const commitsListTemplate = fs.readFileSync( + path.join(ROOT_DIR, "components", "repository", "commit-groups", "commit-groups.tmpl"), + "utf-8" + ); const commitSubjectTemplate = fs.readFileSync( path.join(ROOT_DIR, "templates", "repo", "commit_message_subject.tmpl"), "utf-8" diff --git a/styles/pages/commits.css b/styles/pages/commits.css new file mode 100644 index 00000000..0a111722 --- /dev/null +++ b/styles/pages/commits.css @@ -0,0 +1,59 @@ +/* Commit history: GitHub's heading over a branch and search toolbar, then the commits grouped by day. Kept as a page + stylesheet, outside the size-limited theme files. */ +.github-commits-title { + margin: 0 0 16px; + padding-bottom: 8px; + border-bottom: 1px solid var(--color-light-border); + font-size: 24px; + font-weight: 600; + line-height: 36px; +} + +.github-commits-toolbar { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 8px; + margin-bottom: 16px; +} + +.github-commits-ref, +.github-commits-actions, +.github-commits-search { + display: flex; + align-items: center; + gap: 8px; + min-width: 0; +} + +.github-commits-ref .repo-path { + margin: 0; + font-size: 16px; +} + +.github-commits-search .theme-search-field { + width: 260px; +} + +.github-commits-renamed { + margin: 0 0 16px; + color: var(--color-text-light-1); + font-size: 12px; +} + +@media (max-width: 767.98px) { + .github-commits-actions { + flex: 1 1 100%; + flex-wrap: wrap; + } + + .github-commits-search { + flex: 1 1 100%; + } + + .github-commits-search .theme-search-field { + flex: 1; + width: auto; + } +} diff --git a/templates/base/component_assets.tmpl b/templates/base/component_assets.tmpl index cf2f498e..0d33d2f6 100644 --- a/templates/base/component_assets.tmpl +++ b/templates/base/component_assets.tmpl @@ -18,10 +18,12 @@ + + diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl new file mode 100644 index 00000000..fa00acbf --- /dev/null +++ b/templates/repo/commits.tmpl @@ -0,0 +1,36 @@ +{{/* GitHub's commit history: a "Commits" heading over a toolbar with the branch picker on the left and the search and +commit graph on the right, then the commits grouped by day. GitHub shows no commit, branch and tag counters here. */}} +{{template "base/head" .}} +{{$scope := ctx.Locale.Tr "repo.commits.search_branch"}}{{if .All}}{{$scope = ctx.Locale.Tr "repo.commits.search_all"}}{{end}} +
+
+ {{template "base/alert" .}} +

{{ctx.Locale.Tr "repo.commits.commits"}}

+
+
+ {{template "repo/branch_dropdown" dict "root" .}} + {{template "repo/filepath" .}} +
+
+ + {{svg "octicon-git-branch" 16}}{{ctx.Locale.Tr "repo.commit_graph"}} +
+
+ {{if .Commits}} + {{template "repo/commits_list" .}} + {{else}} +
+ {{svg "octicon-git-commit" 24}} +

{{ctx.Locale.Tr "search.no_results"}}

+
+ {{end}} + {{if .OldFilename}} +

{{ctx.Locale.Tr "repo.commits.renamed_from" .OldFilename}} ({{ctx.Locale.Tr "repo.commits.browse_further"}})

+ {{end}} + {{template "base/paginate" .}} +
+
+{{template "base/footer" .}} diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index 8839bfea..0db4dd40 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -1,8 +1,2 @@ -{{/* GitHub-style commit history using the shared commit row. */}} -
-
    - {{range .Commits}} - {{template "repo/commit_list_item" dict "Commit" . "Page" $}} - {{end}} -
-
+{{/* GitHub groups a repository's history by day, as on a pull request's commits. */}} +{{template "components/repository/commit-groups/commit-groups" .}} diff --git a/templates/repo/commits_search_scope.tmpl b/templates/repo/commits_search_scope.tmpl new file mode 100644 index 00000000..b11eb01a --- /dev/null +++ b/templates/repo/commits_search_scope.tmpl @@ -0,0 +1,2 @@ +{{template "components/common/dropdown/option" dict "Type" "radio" "Name" "all" "Value" "false" "Label" (ctx.Locale.Tr "repo.commits.search_branch") "Checked" (not .All)}} +{{template "components/common/dropdown/option" dict "Type" "radio" "Name" "all" "Value" "true" "Label" (ctx.Locale.Tr "repo.commits.search_all") "Checked" .All}} diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index ab0508ed..3b34ba96 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -228,7 +228,6 @@ {{if $showDiffBox}} -
{{if and .Commits (gt .CommitCount 0)}} {{/* GitHub's summary row and its commits grouped by day. */}} diff --git a/templates/repo/pulls/commits.tmpl b/templates/repo/pulls/commits.tmpl index 02c00fb9..f8d9fe95 100644 --- a/templates/repo/pulls/commits.tmpl +++ b/templates/repo/pulls/commits.tmpl @@ -1,5 +1,4 @@ {{template "base/head" .}} -
{{template "repo/issue/view_title" .}} diff --git a/templates/repo/pulls/commits_list.tmpl b/templates/repo/pulls/commits_list.tmpl index 47237636..ed82b9f9 100644 --- a/templates/repo/pulls/commits_list.tmpl +++ b/templates/repo/pulls/commits_list.tmpl @@ -1,15 +1 @@ -{{/* Retain Forgejo's chronological grouping and reuse the history-row component. */}} -{{$previousDate := ""}} -{{range .Commits}} - {{$time := .Committer.When}}{{if not $time}}{{$time = .Author.When}}{{end}} - {{$date := $time.Format "2006-01-02"}} - {{if ne $date $previousDate}} - {{if ne $previousDate ""}}
{{end}} - {{$previousDate = $date}} -
-

{{svg "octicon-git-commit" 16}}Commits on {{$time.Format "Jan 2, 2006"}}

-
{{end}} +{{template "components/repository/commit-groups/commit-groups" .}}