From 0b3f38b3786c1b738165778d210453e1c2bfe309 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sun, 24 Aug 2025 17:37:43 +0200 Subject: g2h: Add commit page --- README.md | 9 +++++++-- g2h/cli.py | 2 ++ g2h/commit_page.py | 14 ++++++++++++++ g2h/page_factory.py | 4 ++++ templates/commit.md | 9 +++++++++ test_repo/git.tgz | Bin 16230 -> 16230 bytes tests/commit_test.py | 19 +++++++++++++++++++ 7 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 g2h/commit_page.py create mode 100644 templates/commit.md create mode 100644 tests/commit_test.py diff --git a/README.md b/README.md index 3796be6..e78a55c 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,16 @@ For a full list of options, their defaults and how they're changing the behavior Table with branch/tag, message summary and last modified date columns. - [ ] Link commit messages to commit page. - [ ] Tabbed log page. -- [ ] Commit page. +- [x] Commit page. Collection of metadata at the beginning of the page. - Consisting of commit hash, commit date, author, (redact email), parent(s) and child(ren). + Consisting of commit hash, commit date, author Followed by the commit message and then a list of changed files. + - [ ] Add redacted email to authro. + - [ ] Add links to parent(s). + - [ ] Add links to child(ren). - [ ] Show diffstat on commit page. + - [ ] Add button to browse tree. + - [ ] Add button to download tree tarball. - [ ] Tree view. Show the state of the tree at the current commit. Folders should be traversable by clicking and clicking on a file should open that file's page. diff --git a/g2h/cli.py b/g2h/cli.py index 1391ec2..3d7028e 100644 --- a/g2h/cli.py +++ b/g2h/cli.py @@ -28,6 +28,8 @@ def main(): factory = PageFactory(args.out_dir, project_name) factory.new_overview(branches, tags).render() factory.new_log(commits, branches, tags).render() + for commit in commits: + factory.new_commit(commit).render() if __name__ == '__main__': main() diff --git a/g2h/commit_page.py b/g2h/commit_page.py new file mode 100644 index 0000000..325df85 --- /dev/null +++ b/g2h/commit_page.py @@ -0,0 +1,14 @@ +import os + +from .page import Page + +class CommitPage(Page): + def __init__(self, out_dir, name, commit): + super(CommitPage, self).__init__('commit.md', out_dir, os.path.join(commit.hexsha, 'index.md'), name) + self.commit = commit + + def context(self): + return { + 'commit': self.commit, + 'title': self.name + ': ' + self.commit.hexsha + } diff --git a/g2h/page_factory.py b/g2h/page_factory.py index dae9675..f946e7a 100644 --- a/g2h/page_factory.py +++ b/g2h/page_factory.py @@ -1,3 +1,4 @@ +from .commit_page import CommitPage from .overview_page import OverviewPage from .log_page import LogPage @@ -6,6 +7,9 @@ class PageFactory: self.out_dir = out_dir self.name = name + def new_commit(self, commit): + return CommitPage(self.out_dir, self.name, commit) + def new_overview(self, branches, tags): return OverviewPage(self.out_dir, self.name, branches, tags) diff --git a/templates/commit.md b/templates/commit.md new file mode 100644 index 0000000..fcf57b7 --- /dev/null +++ b/templates/commit.md @@ -0,0 +1,9 @@ +{% include '_head.md' %} + +**Commit**: {{ commit.hexsha }} +**Author**: {{ commit.author }} +**Date**: {{ commit.committed_datetime.strftime('%Y-%m-%d %H:%M:%S') }} + +``` +{{ commit.message }} +``` diff --git a/test_repo/git.tgz b/test_repo/git.tgz index 3c96007..5d00f06 100644 Binary files a/test_repo/git.tgz and b/test_repo/git.tgz differ diff --git a/tests/commit_test.py b/tests/commit_test.py new file mode 100644 index 0000000..e36f835 --- /dev/null +++ b/tests/commit_test.py @@ -0,0 +1,19 @@ +from g2h.commit_page import CommitPage +from unittest.mock import MagicMock + +def test_init(): + commit = MagicMock() + commit.hexsha = '123' + page = CommitPage('test/commit', 'commit test', commit) + assert(page.name == 'commit test') + assert(page.out_file_path == 'test/commit/123/index.md') + assert(page.template.name == 'commit.md') + +def test_context(): + commit = MagicMock() + commit.hexsha = '123' + page = CommitPage('test/commit', 'commit test', commit) + context = page.context() + assert(context['title'] == 'commit test: 123') + assert(context['commit'] == commit) + -- cgit v1.2.3