diff options
Diffstat (limited to 'deployment/mgagit')
-rwxr-xr-x | deployment/mgagit/templates/git-post-receive-hook | 102 |
1 files changed, 97 insertions, 5 deletions
diff --git a/deployment/mgagit/templates/git-post-receive-hook b/deployment/mgagit/templates/git-post-receive-hook index c33c8a7e..cfa81615 100755 --- a/deployment/mgagit/templates/git-post-receive-hook +++ b/deployment/mgagit/templates/git-post-receive-hook @@ -41,6 +41,24 @@ Mageia Git Monkeys. """ git_multimail.REVISION_FOOTER_TEMPLATE = git_multimail.FOOTER_TEMPLATE +I18N_REVISION_HEADER_TEMPLATE = """\ +To: %(recipients)s +Subject: %(emailprefix)s%(oneline)s +MIME-Version: 1.0 +Content-Type: text/plain; charset=%(charset)s +Content-Transfer-Encoding: 8bit +From: %(fromaddr)s +Reply-To: %(reply_to)s +In-Reply-To: %(reply_to_msgid)s +References: %(reply_to_msgid)s +X-Git-Repo: %(repo_shortname)s +X-Git-Refname: %(refname)s +X-Git-Reftype: %(refname_type)s +X-Git-Rev: %(rev)s +Auto-Submitted: auto-generated +""" + + REPO_NAME_RE = re.compile(r'^/git/(?P<name>.+?)(?:\.git)?$') def repo_shortname(): basename = os.path.abspath(git_multimail.get_git_dir()) @@ -53,14 +71,15 @@ def repo_shortname(): # Override the Environment class to generate an apporpriate short name which is # used in git links and as an email prefix -class LinksEnvironment(git_multimail.Environment): +class MageiaEnvironment(git_multimail.Environment): def get_repo_shortname(self): return repo_shortname() -git_multimail.Environment = LinksEnvironment +git_multimail.Environment = MageiaEnvironment + # Override the Reviesion class to inject gitweb/cgit links and any referenced # bug URLs -class LinksRevision(git_multimail.Revision): +class MageiaLinksRevision(git_multimail.Revision): bz = None def bugzilla_init(self): @@ -166,7 +185,46 @@ class LinksRevision(git_multimail.Revision): return output -git_multimail.Revision = LinksRevision +# Override the Revision class to inject gitweb/cgit links and any referenced +# bug URLs +class MageiaI18NRevision(git_multimail.Revision): + """A Change consisting of a single git commit.""" + + def __init__(self, reference_change, rev, num, tot): + git_multimail.Change.__init__(self, reference_change.environment) + self.reference_change = reference_change + self.rev = rev + self.change_type = self.reference_change.change_type + self.refname = self.reference_change.refname + self.num = num + self.tot = tot + self.author = git_multimail.read_git_output(['log', '--no-walk', '--format=%aN <%aE>', self.rev.sha1]) + self.recipients = False + self.output = [] + + + i18n_folders = [] + # Check files and find i18n folders + for line in git_multimail.read_git_lines(['ls-tree', '-rd', self.rev.sha1]): + (modetypesha1, name) = line.split("\t", 1) + if name.endswith("/.tx"): + i18n_folders.append(os.path.dirname(name)) + + if len(i18n_folders): + self.output = git_multimail.read_git_lines( + ['log', '-C', '--stat', '-p', '--no-walk', self.rev.sha1, '--'] + i18n_folders, + keepends=True, + ) + if len(self.output): + # We have some output so lets send the mail... + self.recipients = 'i18n-reports@ml.mageia.org' + + def generate_email_body(self, push): + """Show this revision.""" + + return self.output + + if __name__ == '__main__': # Attempt to write a last-updated file for cgit cosmetics @@ -193,4 +251,38 @@ if __name__ == '__main__': except Exception: pass - git_multimail.main(sys.argv[1:]) + + config = git_multimail.Config('multimailhook') + + try: + environment = git_multimail.choose_environment( + config, osenv=os.environ, + ) + + mailer = git_multimail.choose_mailer(config, environment) + # For testing... + #mailer = git_multimail.OutputMailer(sys.stdout) + + changes = [] + for line in sys.stdin: + (oldrev, newrev, refname) = line.strip().split(' ', 2) + changes.append( + git_multimail.ReferenceChange.create(environment, oldrev, newrev, refname) + ) + push = git_multimail.Push(changes) + + + # First pass - regular commit mails + git_multimail.Revision = MageiaLinksRevision + push.send_emails(mailer, body_filter=environment.filter_body) + + # Second pass - i18n commit mails + git_multimail.REVISION_HEADER_TEMPLATE = I18N_REVISION_HEADER_TEMPLATE + git_multimail.Revision = MageiaI18NRevision + # Don't send the summary email, so nuke the change recipients + for change in push.changes: + change.recipients = False + push.send_emails(mailer, body_filter=environment.filter_body) + + except git_multimail.ConfigurationException, e: + sys.exit(str(e)) |