/[adm]/puppet/deployment/mgagit/templates/git-post-receive-hook
ViewVC logotype

Annotation of /puppet/deployment/mgagit/templates/git-post-receive-hook

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3354 - (hide annotations) (download)
Sun Oct 6 22:41:25 2013 UTC (10 years, 6 months ago) by colin
File size: 3784 byte(s)
mgagit: Add new templates for generationg per-commit notification emails.

This uses the git multimail project from upstream revision 3fcd7bffef
which is the master revision at the time of writing.

It also includes a monkey-patched version which we will use which adds
the ability to include links to the gitweb/cgit URL and also links
to any supported bugtracker.
1 colin 3354 #! /usr/bin/env python2
2    
3     import sys
4     import os
5     import re
6    
7     LIBDIR = '/usr/local/bin'
8     sys.path.insert(0, LIBDIR)
9    
10     import git_multimail
11    
12     # When editing this list, remember to edit the same list in
13     # modules/cgit/templates/filter.commit-links.sh
14     BUG_REFS = {
15     'Mageia': { 're': re.compile('mga#([0-9]+)'), 'replace': 'https://bugs.mageia.org/show_bug.cgi?id=%s' },
16     'Red Hat': { 're': re.compile('rhbz#([0-9]+)'), 'replace': 'https://bugzilla.redhat.com/show_bug.cgi?id=%s' },
17     'Free Desktop': { 're': re.compile('fdo#([0-9]+)'), 'replace': 'https://bugs.freedesktop.org/show_bug.cgi?id=%s' },
18     'KDE': { 're': re.compile('(?:bko|kde)#([0-9]+)'), 'replace': 'https://bugs.kde.org/show_bug.cgi?id=%s' },
19     'GNOME': { 're': re.compile('(?:bgo|gnome)#([0-9]+)'), 'replace': 'https://bugzilla.gnome.org/show_bug.cgi?id=%s' },
20     'Launchpad': { 're': re.compile('lp#([0-9]+)'), 'replace': 'https://launchpad.net/bugs/%s' },
21     }
22    
23     COMMIT_RE = re.compile('^commit ([a-f0-9]{40})')
24     COMMIT_REPLACE = 'http://gitweb.mageia.org/%s/commit/?id=%s'
25    
26    
27    
28     git_multimail.FOOTER_TEMPLATE = """\
29    
30     -- \n\
31     Mageia Git Monkeys.
32     """
33     git_multimail.REVISION_FOOTER_TEMPLATE = git_multimail.FOOTER_TEMPLATE
34    
35     # Override the Environment class to generate an apporpriate short name which is
36     # used in git links and as an email prefix
37     class LinksEnvironment(git_multimail.Environment):
38     REPO_NAME_RE = re.compile(r'^/git/(?P<name>.+?)$')
39    
40     def get_repo_shortname(self):
41     """Use the last part of the repo path, with ".git" stripped off if present."""
42    
43     basename = os.path.abspath(self.get_repo_path())
44     m = self.REPO_NAME_RE.match(basename)
45     print self.REPO_NAME_RE
46     if m:
47     return m.group('name')
48     else:
49     return basename
50    
51     git_multimail.Environment = LinksEnvironment
52    
53     # Override the Reviesion class to inject gitweb/cgit links and any referenced
54     # bug URLs
55     class LinksRevision(git_multimail.Revision):
56     def generate_email_body(self, push):
57     """Show this revision."""
58    
59     output = git_multimail.read_git_lines(
60     ['log'] + self.environment.commitlogopts + ['-1', self.rev.sha1],
61     keepends=True,
62     )
63     bugs = {}
64     commit = None
65     idx = 0
66     for line in output:
67     idx+=1
68     if line == "---\n":
69     if commit and COMMIT_REPLACE:
70     output.insert(idx, "\n")
71     output.insert(idx, " %s\n" % (COMMIT_REPLACE % (self.environment.get_repo_shortname(), commit)))
72     output.insert(idx, " Commit Link:\n")
73     idx+=3
74     if bugs:
75     output.insert(idx, " Bug links:\n")
76     idx+=1
77     for tracker,bugnos in bugs.items():
78     output.insert(idx, " %s\n" % tracker)
79     idx+=1
80     for bugno in bugnos:
81     output.insert(idx, " %s\n" % (BUG_REFS[tracker]['replace'] % bugno))
82     idx+=1
83     output.insert(idx, "\n")
84     idx+=1
85     break
86     m = COMMIT_RE.search(line)
87     if m:
88     commit = m.group(1);
89     for tracker in BUG_REFS.keys():
90     m = BUG_REFS[tracker]['re'].search(line)
91     if m:
92     bug = m.group(1)
93     if not tracker in bugs:
94     bugs[tracker] = [bug]
95     elif not bug in bugs[tracker]:
96     bugs[tracker].append(bug)
97    
98     return output
99    
100     git_multimail.Revision = LinksRevision
101    
102     if __name__ == '__main__':
103     git_multimail.main(sys.argv[1:])

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.30