From 782a350e1f56292176ac8471195c889e47b2b841 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sun, 24 Aug 2025 12:53:59 +0200 Subject: g2h:Add branches, tags and project name to overview page --- README.md | 4 +++- g2h/cli.py | 12 +++++++++++- g2h/gen.py | 6 ++++-- g2h/git.py | 6 ++++++ mise.toml | 2 +- templates/overview.md | 22 +++++++++++++++++++--- test_repo/git.tgz | Bin 15988 -> 16230 bytes 7 files changed, 44 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cd14d1c..1ee0121 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,11 @@ For a full list of options, their defaults and how they're changing the behavior ## Features -- [ ] Overview page. +- [x] Overview page. Table of branches and table of tags. Each with name, most recent message summary and last modified date. + - [ ] Link branch and tag name to tree view. + - [ ] Link commit messages to commit page. - [ ] Commit log page. Table with branch/tag, message summary and last modified date columns. - [ ] Tabbed log page. diff --git a/g2h/cli.py b/g2h/cli.py index 1979045..301203c 100644 --- a/g2h/cli.py +++ b/g2h/cli.py @@ -1,4 +1,6 @@ import argparse +import os + from .git import Git from .gen import Generator @@ -6,16 +8,24 @@ def parse_args(): parser = argparse.ArgumentParser( prog='g2h', description='Convert a git repository into markdown files Hugo can understand.') + # TODO: Defaults for these two values should be $PWD. parser.add_argument('repo_path', help='Path to the root of git repository') parser.add_argument('out_dir', help='Path to where the generated files should be stored') + parser.add_argument('--name', help='Name of the project. Default: directory name of repo') return parser.parse_args() def main(): args = parse_args() git = Git(args.repo_path) + + branches = git.get_branches() + # TODO: Fix this for repo_path=(.|~) + project_name = args.name if args.name is not None else os.path.basename(args.repo_path) + tags = git.get_tags() + gen = Generator(args.out_dir) - gen.render_overview(git.get_all_commits()) + gen.render_overview(project_name, branches, tags) if __name__ == '__main__': main() diff --git a/g2h/gen.py b/g2h/gen.py index 4884072..02162e8 100644 --- a/g2h/gen.py +++ b/g2h/gen.py @@ -15,8 +15,10 @@ class Generator: with open(out_file, 'w', encoding='utf-8') as f: f.write(content) - def render_overview(self, commits): + def render_overview(self, name, branches, tags): context = { - 'commits': commits + 'branches': branches, + 'tags': tags, + 'title': name } self._render('overview.md', context, '_index.md') diff --git a/g2h/git.py b/g2h/git.py index e6984c4..9f3bba8 100644 --- a/g2h/git.py +++ b/g2h/git.py @@ -9,3 +9,9 @@ class Git: def get_all_commits(self): return list(self.repo.iter_commits()) + + def get_branches(self): + return sorted(self.repo.branches, key=lambda b: b.commit.committed_date, reverse=True) + + def get_tags(self): + return sorted(self.repo.tags, key=lambda b: b.commit.committed_date, reverse=True) diff --git a/mise.toml b/mise.toml index 78eb153..a6eaf5a 100644 --- a/mise.toml +++ b/mise.toml @@ -9,7 +9,7 @@ run = "pip install -r requirements.txt" [tasks.run] description = "Run g2h with the test repo" alias = "r" -run = "rm -rf ./test_out && python3 -m g2h.cli test_repo test_out" +run = "rm -rf ./test_out && python3 -m g2h.cli test_repo test_out --name 'Test repo'" [tasks.commit] run = [ diff --git a/templates/overview.md b/templates/overview.md index ce3e055..cc6f990 100644 --- a/templates/overview.md +++ b/templates/overview.md @@ -1,7 +1,23 @@ --- -title: Overview +title: {{ title }} --- -# Overview +# {{ title }} -{{ commits }} +{% if branches %} +| Branch | Commit | Date | +|--------|--------|------| +{%- for branch in branches %} +| {{ branch.name }} | {{ branch.commit.summary }} | {{ branch.commit.authored_datetime.strftime('%Y-%m-%d %H:%M:%S') }} |{% endfor %} +{% else %} +No branches found. +{% endif %} + +{% if tags %} +| Tag | Commit | Date | +|--------|--------|------| +{%- for tag in tags %} +| {{ tag.name }} | {{ tag.commit.summary }} | {{ tag.commit.authored_datetime.strftime('%Y-%m-%d %H:%M:%S') }} |{% endfor %} +{% else %} +No tags found. +{% endif %} diff --git a/test_repo/git.tgz b/test_repo/git.tgz index f0cf7b2..0ac0ff5 100644 Binary files a/test_repo/git.tgz and b/test_repo/git.tgz differ -- cgit v1.2.3