diff options
| author | Christoph Schlosser <christoph@linux.com> | 2025-08-24 18:58:26 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christoph@linux.com> | 2025-08-24 18:58:26 +0200 |
| commit | bfb9afa2a57c3c302dde2c9669425d365c3f9b40 (patch) | |
| tree | b0f3f327becfd078b16ff777cde3b1ba93885954 | |
| parent | 3d06cd01a52382982964a2c40036ca1dabb76501 (diff) | |
| download | git2hugo-bfb9afa2a57c3c302dde2c9669425d365c3f9b40.tar.gz | |
g2h: Add redacted authors email to commit page
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | g2h/commit_page.py | 16 | ||||
| -rw-r--r-- | templates/commit.md | 2 | ||||
| -rw-r--r-- | test_repo/git.tgz | bin | 16230 -> 16230 bytes | |||
| -rw-r--r-- | tests/commit_test.py | 19 |
5 files changed, 35 insertions, 4 deletions
@@ -44,7 +44,7 @@ For a full list of options, their defaults and how they're changing the behavior Collection of metadata at the beginning of the page. Consisting of commit hash, commit date, author Followed by the commit message and then a list of changed files. - - [ ] Add redacted email to authro. + - [x] Add redacted email to author. - [ ] Add links to parent(s). - [ ] Add links to child(ren). - [ ] Show diffstat on commit page. diff --git a/g2h/commit_page.py b/g2h/commit_page.py index 716a4f8..7123c82 100644 --- a/g2h/commit_page.py +++ b/g2h/commit_page.py @@ -2,6 +2,19 @@ import os from .page import Page +def redact_email(email): + if email is None or len(email) == 0: + return '' + + if '@' not in email: + return email[0] + '...' + email[-1] + + local, domain = email.split('@') + redacted_local = local[0] + '...' + local[-1] if len(local) > 0 else '' + redacted_domain = domain.replace('.', '...') + + return redacted_local + '@' + redacted_domain + class CommitPage(Page): def __init__(self, out_dir, name, commit, content_subdir): super(CommitPage, self).__init__('commit.md', out_dir, os.path.join(commit.hexsha, 'index.md'), name, content_subdir) @@ -10,5 +23,6 @@ class CommitPage(Page): def context(self): return { 'commit': self.commit, - 'title': self.name + ': ' + self.commit.hexsha + 'title': self.name + ': ' + self.commit.hexsha, + 'redacted_email': redact_email(self.commit.author.email) } diff --git a/templates/commit.md b/templates/commit.md index fcf57b7..4ea5594 100644 --- a/templates/commit.md +++ b/templates/commit.md @@ -1,7 +1,7 @@ {% include '_head.md' %} **Commit**: {{ commit.hexsha }} -**Author**: {{ commit.author }} +**Author**: {{ commit.author }} <{{ redacted_email }}> **Date**: {{ commit.committed_datetime.strftime('%Y-%m-%d %H:%M:%S') }} ``` diff --git a/test_repo/git.tgz b/test_repo/git.tgz Binary files differindex cc21d55..06a8be9 100644 --- a/test_repo/git.tgz +++ b/test_repo/git.tgz diff --git a/tests/commit_test.py b/tests/commit_test.py index 1d79f1e..3a9871a 100644 --- a/tests/commit_test.py +++ b/tests/commit_test.py @@ -1,4 +1,4 @@ -from g2h.commit_page import CommitPage +from g2h.commit_page import CommitPage, redact_email from unittest.mock import MagicMock def test_init(): @@ -12,8 +12,25 @@ def test_init(): def test_context(): commit = MagicMock() commit.hexsha = '123' + commit.author.email = 'unit@te.st' page = CommitPage('test/commit', 'commit test', commit, '') context = page.context() assert(context['title'] == 'commit test: 123') assert(context['commit'] == commit) + assert(context['redacted_email'] == 'u...t@te...st') +def test_redacting_email(): + assert(redact_email(None) == '') + assert(redact_email('') == '') + assert(redact_email('a') == 'a...a') + assert(redact_email('az') == 'a...z') + assert(redact_email('root') == 'r...t') + assert(redact_email('root@localhost') == 'r...t@localhost') + assert(redact_email('test@example.com') == 't...t@example...com') + assert(redact_email('test@sub.example.com') == 't...t@sub...example...com') + assert(redact_email('az@example.com') == 'a...z@example...com') + assert(redact_email('a@example.com') == 'a...a@example...com') + assert(redact_email('@example.com') == '@example...com') + assert(redact_email('test@') == 't...t@') + assert(redact_email('az@') == 'a...z@') + assert(redact_email('@') == '@') |