author | Patrick Mezard <pmezard@gmail.com> |
Tue, 26 Jul 2011 21:30:12 +0200 | |
changeset 14940 | d78b92353f26 |
parent 14869 | 647071c6dfcf |
child 15561 | ca572e94d8e7 |
permissions | -rw-r--r-- |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
1 |
# notify.py - email notifications for mercurial |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
2 |
# |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
3 |
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
4 |
# |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8154
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
10263 | 6 |
# GNU General Public License version 2 or any later version. |
7127
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
7 |
|
14940
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
8 |
'''hooks for sending email push notifications |
7127
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
9 |
|
14940
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
10 |
This extension let you run hooks sending email notifications when |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
11 |
changesets are being pushed, from the sending or receiving side. |
7127
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
12 |
|
14940
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
13 |
First, enable the extension as explained in :hg:`help extensions`, and |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
14 |
register the hook you want to run. ``incoming`` and ``outgoing`` hooks |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
15 |
are run by the changesets receiver while the ``outgoing`` one is for |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
16 |
the sender:: |
7127
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
17 |
|
9105
6188f2cc4a37
notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
9104
diff
changeset
|
18 |
[hooks] |
6188f2cc4a37
notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
9104
diff
changeset
|
19 |
# one email for each incoming changeset |
6188f2cc4a37
notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
9104
diff
changeset
|
20 |
incoming.notify = python:hgext.notify.hook |
14940
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
21 |
# one email for all incoming changesets |
9105
6188f2cc4a37
notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
9104
diff
changeset
|
22 |
changegroup.notify = python:hgext.notify.hook |
14940
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
23 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
24 |
# one email for all outgoing changesets |
14617
23f4e1e40988
notify: send changesets on 'outgoing' hook, updated doc
Ingo Bressler <dev@ingobressler.net>
parents:
13878
diff
changeset
|
25 |
outgoing.notify = python:hgext.notify.hook |
7127
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
26 |
|
14940
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
27 |
Now the hooks are running, subscribers must be assigned to |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
28 |
repositories. Use the ``[usersubs]`` section to map repositories to a |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
29 |
given email or the ``[reposubs]`` section to map emails to a single |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
30 |
repository:: |
9157
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
31 |
|
9105
6188f2cc4a37
notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
9104
diff
changeset
|
32 |
[usersubs] |
14940
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
33 |
# key is subscriber email, value is a comma-separated list of glob |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
34 |
# patterns |
9105
6188f2cc4a37
notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
9104
diff
changeset
|
35 |
user@host = pattern |
7127
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
36 |
|
9105
6188f2cc4a37
notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
9104
diff
changeset
|
37 |
[reposubs] |
14940
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
38 |
# key is glob pattern, value is a comma-separated list of subscriber |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
39 |
# emails |
9105
6188f2cc4a37
notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents:
9104
diff
changeset
|
40 |
pattern = user@host |
7127
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
41 |
|
14940
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
42 |
Glob patterns are matched against absolute path to repository |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
43 |
root. The subscriptions can be defined in their own file and |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
44 |
referenced with:: |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
45 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
46 |
[notify] |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
47 |
config = /path/to/subscriptionsfile |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
48 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
49 |
Alternatively, they can be added to Mercurial configuration files by |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
50 |
setting the previous entry to an empty value. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
51 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
52 |
At this point, notifications should be generated but will not be sent until you |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
53 |
set the ``notify.test`` entry to ``False``. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
54 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
55 |
Notifications content can be tweaked with the following configuration entries: |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
56 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
57 |
notify.test |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
58 |
If ``True``, print messages to stdout instead of sending them. Default: True. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
59 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
60 |
notify.sources |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
61 |
Space separated list of change sources. Notifications are sent only |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
62 |
if it includes the incoming or outgoing changes source. Incoming |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
63 |
sources can be ``serve`` for changes coming from http or ssh, |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
64 |
``pull`` for pulled changes, ``unbundle`` for changes added by |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
65 |
:hg:`unbundle` or ``push`` for changes being pushed |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
66 |
locally. Outgoing sources are the same except for ``unbundle`` which |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
67 |
is replaced by ``bundle``. Default: serve. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
68 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
69 |
notify.strip |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
70 |
Number of leading slashes to strip from url paths. By default, notifications |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
71 |
references repositories with their absolute path. ``notify.strip`` let you |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
72 |
turn them into relative paths. For example, ``notify.strip=3`` will change |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
73 |
``/long/path/repository`` into ``repository``. Default: 0. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
74 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
75 |
notify.domain |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
76 |
If subscribers emails or the from email have no domain set, complete them |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
77 |
with this value. |
7127
9df67ee30ef5
help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7116
diff
changeset
|
78 |
|
14940
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
79 |
notify.style |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
80 |
Style file to use when formatting emails. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
81 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
82 |
notify.template |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
83 |
Template to use when formatting emails. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
84 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
85 |
notify.incoming |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
86 |
Template to use when run as incoming hook, override ``notify.template``. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
87 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
88 |
notify.outgoing |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
89 |
Template to use when run as outgoing hook, override ``notify.template``. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
90 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
91 |
notify.changegroup |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
92 |
Template to use when running as changegroup hook, override |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
93 |
``notify.template``. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
94 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
95 |
notify.maxdiff |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
96 |
Maximum number of diff lines to include in notification email. Set to 0 |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
97 |
to disable the diff, -1 to include all of it. Default: 300. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
98 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
99 |
notify.maxsubject |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
100 |
Maximum number of characters in emails subject line. Default: 67. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
101 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
102 |
notify.diffstat |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
103 |
Set to True to include a diffstat before diff content. Default: True. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
104 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
105 |
notify.merge |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
106 |
If True, send notifications for merge changesets. Default: True. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
107 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
108 |
If set, the following entries will also be used to customize the notifications: |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
109 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
110 |
email.from |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
111 |
Email ``From`` address to use if none can be found in generated email content. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
112 |
|
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
113 |
web.baseurl |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
114 |
Root repository browsing URL to combine with repository paths when making |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
115 |
references. See also ``notify.strip``. |
d78b92353f26
notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents:
14869
diff
changeset
|
116 |
|
9068
27a41250a9ce
notify: wrapped docstrings at 78 characters
Martin Geisler <mg@lazybytes.net>
parents:
8935
diff
changeset
|
117 |
''' |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
118 |
|
3891 | 119 |
from mercurial.i18n import _ |
3877
abaee83ce0a6
Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents:
3876
diff
changeset
|
120 |
from mercurial import patch, cmdutil, templater, util, mail |
9313
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
121 |
import email.Parser, email.Errors, fnmatch, socket, time |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
122 |
|
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
123 |
# template for single changeset can include email headers. |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
124 |
single_template = ''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
125 |
Subject: changeset in {webroot}: {desc|firstline|strip} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
126 |
From: {author} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
127 |
|
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
128 |
changeset {node|short} in {root} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
129 |
details: {baseurl}{webroot}?cmd=changeset;node={node|short} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
130 |
description: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
131 |
\t{desc|tabindent|strip} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
132 |
'''.lstrip() |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
133 |
|
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
134 |
# template for multiple changesets should not contain email headers, |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
135 |
# because only first set of headers will be used and result will look |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
136 |
# strange. |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
137 |
multiple_template = ''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
138 |
changeset {node|short} in {root} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
139 |
details: {baseurl}{webroot}?cmd=changeset;node={node|short} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
140 |
summary: {desc|firstline} |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
141 |
''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
142 |
|
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
143 |
deftemplates = { |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
144 |
'changegroup': multiple_template, |
4498
4dfb9f232a63
Fixed indentation in hgext/notify.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4479
diff
changeset
|
145 |
} |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
146 |
|
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
147 |
class notifier(object): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
148 |
'''email notification class.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
149 |
|
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
150 |
def __init__(self, ui, repo, hooktype): |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
151 |
self.ui = ui |
2329
90368f89340a
notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2326
diff
changeset
|
152 |
cfg = self.ui.config('notify', 'config') |
90368f89340a
notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2326
diff
changeset
|
153 |
if cfg: |
8142
912bfef12ba6
ui: fold readsections into readconfig
Matt Mackall <mpm@selenic.com>
parents:
8029
diff
changeset
|
154 |
self.ui.readconfig(cfg, sections=['usersubs', 'reposubs']) |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
155 |
self.repo = repo |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
156 |
self.stripcount = int(self.ui.config('notify', 'strip', 0)) |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
157 |
self.root = self.strip(self.repo.root) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
158 |
self.domain = self.ui.config('notify', 'domain') |
7498
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
159 |
self.test = self.ui.configbool('notify', 'test', True) |
7116
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
160 |
self.charsets = mail._charsets(self.ui) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
161 |
self.subs = self.subscribers() |
9516
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
162 |
self.merge = self.ui.configbool('notify', 'merge', True) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
163 |
|
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
164 |
mapfile = self.ui.config('notify', 'style') |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
165 |
template = (self.ui.config('notify', hooktype) or |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
166 |
self.ui.config('notify', 'template')) |
3739
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
167 |
self.t = cmdutil.changeset_templater(self.ui, self.repo, |
7762
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7726
diff
changeset
|
168 |
False, None, mapfile, False) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
169 |
if not mapfile and not template: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
170 |
template = deftemplates.get(hooktype) or single_template |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
171 |
if template: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
172 |
template = templater.parsestring(template, quoted=False) |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
173 |
self.t.use_template(template) |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
174 |
|
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
175 |
def strip(self, path): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
176 |
'''strip leading slashes from local path, turn into web-safe path.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
177 |
|
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
178 |
path = util.pconvert(path) |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
179 |
count = self.stripcount |
2326
d0ba2f6b9d97
notify: fix off by one error.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2296
diff
changeset
|
180 |
while count > 0: |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
181 |
c = path.find('/') |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
182 |
if c == -1: |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
183 |
break |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
184 |
path = path[c + 1:] |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
185 |
count -= 1 |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
186 |
return path |
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
187 |
|
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
188 |
def fixmail(self, addr): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
189 |
'''try to clean up email addresses.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
190 |
|
5975
75d9fe70c654
templater: move email function to util
Matt Mackall <mpm@selenic.com>
parents:
4500
diff
changeset
|
191 |
addr = util.email(addr.strip()) |
4094
fbf0e9acfd83
notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4077
diff
changeset
|
192 |
if self.domain: |
fbf0e9acfd83
notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4077
diff
changeset
|
193 |
a = addr.find('@localhost') |
fbf0e9acfd83
notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4077
diff
changeset
|
194 |
if a != -1: |
fbf0e9acfd83
notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4077
diff
changeset
|
195 |
addr = addr[:a] |
fbf0e9acfd83
notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4077
diff
changeset
|
196 |
if '@' not in addr: |
fbf0e9acfd83
notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4077
diff
changeset
|
197 |
return addr + '@' + self.domain |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
198 |
return addr |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
199 |
|
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
200 |
def subscribers(self): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
201 |
'''return list of email addresses of subscribers to this repo.''' |
8154
06f1e4e309ed
notify: turned a set-like dict into a real set
Martin Geisler <mg@lazybytes.net>
parents:
8142
diff
changeset
|
202 |
subs = set() |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
203 |
for user, pats in self.ui.configitems('usersubs'): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
204 |
for pat in pats.split(','): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
205 |
if fnmatch.fnmatch(self.repo.root, pat.strip()): |
8154
06f1e4e309ed
notify: turned a set-like dict into a real set
Martin Geisler <mg@lazybytes.net>
parents:
8142
diff
changeset
|
206 |
subs.add(self.fixmail(user)) |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
207 |
for pat, users in self.ui.configitems('reposubs'): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
208 |
if fnmatch.fnmatch(self.repo.root, pat): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
209 |
for user in users.split(','): |
8154
06f1e4e309ed
notify: turned a set-like dict into a real set
Martin Geisler <mg@lazybytes.net>
parents:
8142
diff
changeset
|
210 |
subs.add(self.fixmail(user)) |
7498
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
211 |
return [mail.addressencode(self.ui, s, self.charsets, self.test) |
8154
06f1e4e309ed
notify: turned a set-like dict into a real set
Martin Geisler <mg@lazybytes.net>
parents:
8142
diff
changeset
|
212 |
for s in sorted(subs)] |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
213 |
|
9486
dd8d10c36c9c
notify: make it possible to pass extra info into templates
Bryan O'Sullivan <bos@serpentine.com>
parents:
9327
diff
changeset
|
214 |
def node(self, ctx, **props): |
9516
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
215 |
'''format one changeset, unless it is a suppressed merge.''' |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
216 |
if not self.merge and len(ctx.parents()) > 1: |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
217 |
return False |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
218 |
self.t.show(ctx, changes=ctx.changeset(), |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
219 |
baseurl=self.ui.config('web', 'baseurl'), |
9486
dd8d10c36c9c
notify: make it possible to pass extra info into templates
Bryan O'Sullivan <bos@serpentine.com>
parents:
9327
diff
changeset
|
220 |
root=self.repo.root, webroot=self.root, **props) |
9516
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
221 |
return True |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
222 |
|
2230
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
223 |
def skipsource(self, source): |
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
224 |
'''true if incoming changes from this source should be skipped.''' |
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
225 |
ok_sources = self.ui.config('notify', 'sources', 'serve').split() |
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
226 |
return source not in ok_sources |
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
227 |
|
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
228 |
def send(self, ctx, count, data): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
229 |
'''send message.''' |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
230 |
|
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
231 |
p = email.Parser.Parser() |
9313
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
232 |
try: |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
233 |
msg = p.parsestr(data) |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
234 |
except email.Errors.MessageParseError, inst: |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
235 |
raise util.Abort(inst) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
236 |
|
7116
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
237 |
# store sender and subject |
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
238 |
sender, subject = msg['From'], msg['Subject'] |
7658
44b3f7bbe2f3
notify: fix neglect of custom headers set via template
Christian Ebert <blacktrash@gmx.net>
parents:
7498
diff
changeset
|
239 |
del msg['From'], msg['Subject'] |
9313
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
240 |
|
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
241 |
if not msg.is_multipart(): |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
242 |
# create fresh mime message from scratch |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
243 |
# (multipart templates must take care of this themselves) |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
244 |
headers = msg.items() |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
245 |
payload = msg.get_payload() |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
246 |
# for notification prefer readability over data precision |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
247 |
msg = mail.mimeencode(self.ui, payload, self.charsets, self.test) |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
248 |
# reinstate custom headers |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
249 |
for k, v in headers: |
8736b1c853ff
notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents:
8935
diff
changeset
|
250 |
msg[k] = v |
7116
e981725da3fe
notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents:
6979
diff
changeset
|
251 |
|
7705
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
252 |
msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
253 |
|
7705
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
254 |
# try to make subject line exist and be useful |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
255 |
if not subject: |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
256 |
if count > 1: |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
257 |
subject = _('%s: %d new changesets') % (self.root, count) |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
258 |
else: |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
259 |
s = ctx.description().lstrip().split('\n', 1)[0].rstrip() |
7705
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
260 |
subject = '%s: %s' % (self.root, s) |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
261 |
maxsubject = int(self.ui.config('notify', 'maxsubject', 67)) |
13202
d83566f4453b
notify: use util.ellipsis() to truncate long subject
Yuya Nishihara <yuya@tcha.org>
parents:
10282
diff
changeset
|
262 |
if maxsubject: |
d83566f4453b
notify: use util.ellipsis() to truncate long subject
Yuya Nishihara <yuya@tcha.org>
parents:
10282
diff
changeset
|
263 |
subject = util.ellipsis(subject, maxsubject) |
7705
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
264 |
msg['Subject'] = mail.headencode(self.ui, subject, |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
265 |
self.charsets, self.test) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
266 |
|
7705
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
267 |
# try to make message have proper sender |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
268 |
if not sender: |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
269 |
sender = self.ui.config('email', 'from') or self.ui.username() |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
270 |
if '@' not in sender or '@localhost' in sender: |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
271 |
sender = self.fixmail(sender) |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
272 |
msg['From'] = mail.addressencode(self.ui, sender, |
c55e68e8f256
notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents:
7658
diff
changeset
|
273 |
self.charsets, self.test) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
274 |
|
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
275 |
msg['X-Hg-Notification'] = 'changeset %s' % ctx |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
276 |
if not msg['Message-Id']: |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
277 |
msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' % |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
278 |
(ctx, int(time.time()), |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
279 |
hash(self.repo.root), socket.getfqdn())) |
2230
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
280 |
msg['To'] = ', '.join(self.subs) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
281 |
|
9136
31177742f54a
for calls expecting bool args, pass bool instead of int
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9105
diff
changeset
|
282 |
msgtext = msg.as_string() |
7498
64840fcb79e1
notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents:
7369
diff
changeset
|
283 |
if self.test: |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
284 |
self.ui.write(msgtext) |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
285 |
if not msgtext.endswith('\n'): |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
286 |
self.ui.write('\n') |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
287 |
else: |
2329
90368f89340a
notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2326
diff
changeset
|
288 |
self.ui.status(_('notify: sending %d subscribers %d changes\n') % |
4498
4dfb9f232a63
Fixed indentation in hgext/notify.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4479
diff
changeset
|
289 |
(len(self.subs), count)) |
5975
75d9fe70c654
templater: move email function to util
Matt Mackall <mpm@selenic.com>
parents:
4500
diff
changeset
|
290 |
mail.sendmail(self.ui, util.email(msg['From']), |
2889
20b95aef3fe0
Move ui.sendmail to mail.connect/sendmail
Matt Mackall <mpm@selenic.com>
parents:
2874
diff
changeset
|
291 |
self.subs, msgtext) |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
292 |
|
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
293 |
def diff(self, ctx, ref=None): |
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
294 |
|
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
295 |
maxdiff = int(self.ui.config('notify', 'maxdiff', 300)) |
13878
a8d13ee0ce68
misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents:
13202
diff
changeset
|
296 |
prev = ctx.p1().node() |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
297 |
ref = ref and ref.node() or ctx.node() |
7308
b6f5490effbf
patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7127
diff
changeset
|
298 |
chunks = patch.diff(self.repo, prev, ref, opts=patch.diffopts(self.ui)) |
b6f5490effbf
patch: turn patch.diff() into a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7127
diff
changeset
|
299 |
difflines = ''.join(chunks).splitlines() |
6979 | 300 |
|
3096
f422c8265ae5
Add support for diffstat in commit emails, and move diffstat from
Matt Doar <matt@xensource.com>
parents:
3017
diff
changeset
|
301 |
if self.ui.configbool('notify', 'diffstat', True): |
f422c8265ae5
Add support for diffstat in commit emails, and move diffstat from
Matt Doar <matt@xensource.com>
parents:
3017
diff
changeset
|
302 |
s = patch.diffstat(difflines) |
4077
1305ba7dee88
Prevent type exception on concatenation if diffstat returns None.
Sean Dague <sean@dague.net>
parents:
3739
diff
changeset
|
303 |
# s may be nil, don't include the header if it is |
1305ba7dee88
Prevent type exception on concatenation if diffstat returns None.
Sean Dague <sean@dague.net>
parents:
3739
diff
changeset
|
304 |
if s: |
1305ba7dee88
Prevent type exception on concatenation if diffstat returns None.
Sean Dague <sean@dague.net>
parents:
3739
diff
changeset
|
305 |
self.ui.write('\ndiffstat:\n\n%s' % s) |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
306 |
|
6305
e8d447d91cdb
notify: print diffstat even if maxline == 0
Benoît Allard <benoit@aeteurope.nl>
parents:
6229
diff
changeset
|
307 |
if maxdiff == 0: |
e8d447d91cdb
notify: print diffstat even if maxline == 0
Benoît Allard <benoit@aeteurope.nl>
parents:
6229
diff
changeset
|
308 |
return |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
309 |
elif maxdiff > 0 and len(difflines) > maxdiff: |
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
310 |
msg = _('\ndiffs (truncated from %d to %d lines):\n\n') |
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
311 |
self.ui.write(msg % (len(difflines), maxdiff)) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
312 |
difflines = difflines[:maxdiff] |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
313 |
elif difflines: |
3739
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
314 |
self.ui.write(_('\ndiffs (%d lines):\n\n') % len(difflines)) |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
315 |
|
6979 | 316 |
self.ui.write("\n".join(difflines)) |
2201
f15056b29472
patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
317 |
|
2230
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
318 |
def hook(ui, repo, hooktype, node=None, source=None, **kwargs): |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
319 |
'''send email notifications to interested subscribers. |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
320 |
|
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
321 |
if used as changegroup hook, send one email for all changesets in |
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
322 |
changegroup. else send one email per changeset.''' |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
323 |
|
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
324 |
n = notifier(ui, repo, hooktype) |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
325 |
ctx = repo[node] |
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
326 |
|
2329
90368f89340a
notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2326
diff
changeset
|
327 |
if not n.subs: |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9327
diff
changeset
|
328 |
ui.debug('notify: no subscribers to repository %s\n' % n.root) |
2329
90368f89340a
notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2326
diff
changeset
|
329 |
return |
90368f89340a
notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2326
diff
changeset
|
330 |
if n.skipsource(source): |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9327
diff
changeset
|
331 |
ui.debug('notify: changes have source "%s" - skipping\n' % source) |
2230
332950340788
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2225
diff
changeset
|
332 |
return |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
333 |
|
3739
16f8e7d1dd54
fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents:
3679
diff
changeset
|
334 |
ui.pushbuffer() |
9516
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
335 |
data = '' |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
336 |
count = 0 |
14617
23f4e1e40988
notify: send changesets on 'outgoing' hook, updated doc
Ingo Bressler <dev@ingobressler.net>
parents:
13878
diff
changeset
|
337 |
if hooktype == 'changegroup' or hooktype == 'outgoing': |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
338 |
start, end = ctx.rev(), len(repo) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
339 |
for rev in xrange(start, end): |
9516
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
340 |
if n.node(repo[rev]): |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
341 |
count += 1 |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
342 |
else: |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
343 |
data += ui.popbuffer() |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
344 |
ui.note(_('notify: suppressing notification for merge %d:%s\n') % |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
345 |
(rev, repo[rev].hex()[:12])) |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
346 |
ui.pushbuffer() |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
347 |
if count: |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
348 |
n.diff(ctx, repo['tip']) |
2203
9569eea1707c
add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2201
diff
changeset
|
349 |
else: |
9516
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
350 |
if not n.node(ctx): |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
351 |
ui.popbuffer() |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
352 |
ui.note(_('notify: suppressing notification for merge %d:%s\n') % |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
353 |
(ctx.rev(), ctx.hex()[:12])) |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
354 |
return |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
355 |
count += 1 |
7726
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
356 |
n.diff(ctx) |
2486980fe211
notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7705
diff
changeset
|
357 |
|
9516
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
358 |
data += ui.popbuffer() |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
359 |
if count: |
f8048c334066
notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents:
9487
diff
changeset
|
360 |
n.send(ctx, count, data) |