summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--g2h/cli.py2
-rw-r--r--g2h/gen.py25
-rw-r--r--g2h/git.py6
-rw-r--r--templates/_head.md5
-rw-r--r--templates/log.md10
-rw-r--r--templates/overview.md12
-rw-r--r--test_repo/git.tgzbin16230 -> 16230 bytes
8 files changed, 51 insertions, 12 deletions
diff --git a/README.md b/README.md
index 1ee0121..3796be6 100644
--- a/README.md
+++ b/README.md
@@ -35,8 +35,9 @@ For a full list of options, their defaults and how they're changing the behavior
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.
+- [x] Commit log page.
Table with branch/tag, message summary and last modified date columns.
+ - [ ] Link commit messages to commit page.
- [ ] Tabbed log page.
- [ ] Commit page.
Collection of metadata at the beginning of the page.
diff --git a/g2h/cli.py b/g2h/cli.py
index 301203c..fc14582 100644
--- a/g2h/cli.py
+++ b/g2h/cli.py
@@ -20,12 +20,14 @@ def main():
git = Git(args.repo_path)
branches = git.get_branches()
+ commits = git.get_commits()
# 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(project_name, branches, tags)
+ gen.render_log(project_name, commits, branches, tags)
if __name__ == '__main__':
main()
diff --git a/g2h/gen.py b/g2h/gen.py
index 02162e8..91fab82 100644
--- a/g2h/gen.py
+++ b/g2h/gen.py
@@ -1,6 +1,14 @@
from jinja2 import Environment, FileSystemLoader
import os
+def ref_names_for_commit(refs, commit_sha):
+ ref_names = []
+ for ref in refs:
+ if ref.commit.hexsha == commit_sha:
+ ref_names.append(ref.name)
+
+ return ref_names
+
class Generator:
def __init__(self, output_dir):
self.output_dir = output_dir
@@ -15,6 +23,23 @@ class Generator:
with open(out_file, 'w', encoding='utf-8') as f:
f.write(content)
+ def render_log(self, name, commits, branches, tags):
+ commits_context = []
+ for commit in commits:
+ refs = ref_names_for_commit(branches, commit.hexsha) + ref_names_for_commit(tags, commit.hexsha)
+ commit_context = {
+ 'committed_datetime': commit.committed_datetime,
+ 'refs': refs,
+ 'summary': commit.summary
+ }
+ commits_context.append(commit_context)
+
+ context = {
+ 'commits': commits_context,
+ 'title': name
+ }
+ self._render('log.md', context, 'l.md')
+
def render_overview(self, name, branches, tags):
context = {
'branches': branches,
diff --git a/g2h/git.py b/g2h/git.py
index 9f3bba8..f3f4809 100644
--- a/g2h/git.py
+++ b/g2h/git.py
@@ -7,11 +7,11 @@ class Git:
except git.InvalidGitRepositoryError:
raise ValueError(f"Invalid git repository at {repo_path}")
- 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_commits(self):
+ return list(self.repo.iter_commits())
+
def get_tags(self):
return sorted(self.repo.tags, key=lambda b: b.commit.committed_date, reverse=True)
diff --git a/templates/_head.md b/templates/_head.md
new file mode 100644
index 0000000..a91e1b6
--- /dev/null
+++ b/templates/_head.md
@@ -0,0 +1,5 @@
+---
+title: {{ title }}
+---
+
+# {{ title }}
diff --git a/templates/log.md b/templates/log.md
new file mode 100644
index 0000000..70f719f
--- /dev/null
+++ b/templates/log.md
@@ -0,0 +1,10 @@
+{% include '_head.md' %}
+
+{% if commits %}
+| Message | Branches/Tags | Date |
+|---------|---------------|------|
+{%- for commit in commits %}
+| {{ commit.summary }} | {% if commit.refs %}{{ commit.refs | join(', ') }}{% endif %} | {{ commit.committed_datetime.strftime('%Y-%m-%d %H:%M:%S') }} |{% endfor %}
+{% else %}
+No commits found.
+{% endif %}
diff --git a/templates/overview.md b/templates/overview.md
index cc6f990..c1f1d05 100644
--- a/templates/overview.md
+++ b/templates/overview.md
@@ -1,23 +1,19 @@
----
-title: {{ title }}
----
-
-# {{ title }}
+{% include '_head.md' %}
{% 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 %}
+| {{ branch.name }} | {{ branch.commit.summary }} | {{ branch.commit.committed_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 %}
+| {{ tag.name }} | {{ tag.commit.summary }} | {{ tag.commit.committed_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 0ac0ff5..69bb3be 100644
--- a/test_repo/git.tgz
+++ b/test_repo/git.tgz
Binary files differ