summaryrefslogtreecommitdiffstats
path: root/src/g2h/commit_page.py
blob: 84374e68306b279cce9b3ff09cd615f787ea0b62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os

from .page import Page

def _redact_local_segment(local_segment):
    if len(local_segment) == 0:
        return ''
    if len(local_segment) < 6:
        return local_segment[0] + '...'
    return local_segment[:2] + '...'

def redact_email(email):
    if email is None or len(email) == 0:
        return ''

    if '@' not in email:
        return _redact_local_segment(email)

    local, domain = email.split('@')
    redacted_local = _redact_local_segment(local)

    return redacted_local + '@' + 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)
        self.commit = commit

    def context(self):
        return {
            'commit': self.commit,
            'title': self.name + ': ' + self.commit.hexsha,
            'redacted_email': redact_email(self.commit.author.email),
            'content_subdir': self.content_subdir,
            'this_commit': self.commit
        }