summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--g2h/commit_page.py16
-rw-r--r--templates/commit.md2
-rw-r--r--test_repo/git.tgzbin16230 -> 16230 bytes
-rw-r--r--tests/commit_test.py19
5 files changed, 35 insertions, 4 deletions
diff --git a/README.md b/README.md
index ad762ea..f5b7732 100644
--- a/README.md
+++ b/README.md
@@ -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
index cc21d55..06a8be9 100644
--- a/test_repo/git.tgz
+++ b/test_repo/git.tgz
Binary files differ
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('@') == '@')