Merge branch 'jk/mailmap-incomplete-line'
[git] / contrib / hooks / multimail / post-receive
1 #! /usr/bin/env python2
2
3 """Example post-receive hook based on git-multimail.
4
5 This script is a simple example of a post-receive hook implemented
6 using git_multimail.py as a Python module.  It is intended to be
7 customized before use; see the comments in the script to help you get
8 started.
9
10 It is possible to use git_multimail.py itself as a post-receive or
11 update hook, configured via git config settings and/or command-line
12 parameters.  But for more flexibility, it can also be imported as a
13 Python module by a custom post-receive script as done here.  The
14 latter has the following advantages:
15
16 * The tool's behavior can be customized using arbitrary Python code,
17   without having to edit git_multimail.py.
18
19 * Configuration settings can be read from other sources; for example,
20   user names and email addresses could be read from LDAP or from a
21   database.  Or the settings can even be hardcoded in the importing
22   Python script, if this is preferred.
23
24 This script is a very basic example of how to use git_multimail.py as
25 a module.  The comments below explain some of the points at which the
26 script's behavior could be changed or customized.
27
28 """
29
30 import sys
31 import os
32
33 # If necessary, add the path to the directory containing
34 # git_multimail.py to the Python path as follows.  (This is not
35 # necessary if git_multimail.py is in the same directory as this
36 # script):
37
38 #LIBDIR = 'path/to/directory/containing/module'
39 #sys.path.insert(0, LIBDIR)
40
41 import git_multimail
42
43
44 # It is possible to modify the output templates here; e.g.:
45
46 #git_multimail.FOOTER_TEMPLATE = """\
47 #
48 #-- \n\
49 #This email was generated by the wonderful git-multimail tool.
50 #"""
51
52
53 # Specify which "git config" section contains the configuration for
54 # git-multimail:
55 config = git_multimail.Config('multimailhook')
56
57
58 # Select the type of environment:
59 environment = git_multimail.GenericEnvironment(config=config)
60 #environment = git_multimail.GitoliteEnvironment(config=config)
61
62
63 # Choose the method of sending emails based on the git config:
64 mailer = git_multimail.choose_mailer(config, environment)
65
66 # Alternatively, you may hardcode the mailer using code like one of
67 # the following:
68
69 # Use "/usr/sbin/sendmail -t" to send emails.  The envelopesender
70 # argument is optional:
71 #mailer = git_multimail.SendMailer(
72 #    command=['/usr/sbin/sendmail', '-t'],
73 #    envelopesender='git-repo@example.com',
74 #    )
75
76 # Use Python's smtplib to send emails.  Both arguments are required.
77 #mailer = git_multimail.SMTPMailer(
78 #    envelopesender='git-repo@example.com',
79 #    # The smtpserver argument can also include a port number; e.g.,
80 #    #     smtpserver='mail.example.com:25'
81 #    smtpserver='mail.example.com',
82 #    )
83
84 # OutputMailer is intended only for testing; it writes the emails to
85 # the specified file stream.
86 #mailer = git_multimail.OutputMailer(sys.stdout)
87
88
89 # Read changes from stdin and send notification emails:
90 git_multimail.run_as_post_receive_hook(environment, mailer)