Show More
@@ -29,14 +29,18 b' Configuring the extension:' | |||
|
29 | 29 | user Username to use to access MySQL server. Default 'bugs'. |
|
30 | 30 | password Password to use to access MySQL server. |
|
31 | 31 | timeout Database connection timeout (seconds). Default 5. |
|
32 |
version Bugzilla version. Specify '3.0' for Bugzilla versions |
|
|
33 | 3.0 onwards, and '2.16' for versions prior to 3.0. | |
|
32 | version Bugzilla version. Specify '3.0' for Bugzilla versions 3.0 and | |
|
33 | later, '2.18' for Bugzilla versions from 2.18 and '2.16' for | |
|
34 | versions prior to 2.18. | |
|
34 | 35 | bzuser Fallback Bugzilla user name to record comments with, if |
|
35 | 36 | changeset committer cannot be found as a Bugzilla user. |
|
37 | bzdir Bugzilla install directory. Used by default notify. | |
|
38 | Default '/var/www/html/bugzilla'. | |
|
36 | 39 | notify The command to run to get Bugzilla to send bug change |
|
37 |
notification emails. Substitutes |
|
|
38 | the bug ID. Default 'cd /var/www/html/bugzilla && ' | |
|
39 | './processmail %s nobody@nowhere.com'. | |
|
40 | notification emails. Substitutes from a map with 3 keys, | |
|
41 | 'bzdir', 'id' (bug id) and 'user' (committer bugzilla email). | |
|
42 | Default depends on version; from 2.18 it is | |
|
43 | "cd %(bzdir)s && perl -T contrib/sendbugmail.pl %(id)s %(user)s". | |
|
40 | 44 | regexp Regular expression to match bug IDs in changeset commit message. |
|
41 | 45 | Must contain one "()" group. The default expression matches |
|
42 | 46 | 'Bug 1234', 'Bug no. 1234', 'Bug number 1234', |
@@ -88,7 +92,7 b' in /var/local/hg/repos/ used with a loca' | |||
|
88 | 92 | password=XYZZY |
|
89 | 93 | version=3.0 |
|
90 | 94 | bzuser=unknown@domain.com |
|
91 | notify=cd /opt/bugzilla-3.2 && perl -T contrib/sendbugmail.pl %%s bugmail@domain.com | |
|
95 | bzdir=/opt/bugzilla-3.2 | |
|
92 | 96 | template=Changeset {node|short} in {root|basename}.\\n{hgweb}/{webroot}/rev/{node|short}\\n\\n{desc}\\n |
|
93 | 97 | strip=5 |
|
94 | 98 | |
@@ -136,6 +140,7 b' class bugzilla_2_16(object):' | |||
|
136 | 140 | self.cursor = self.conn.cursor() |
|
137 | 141 | self.longdesc_id = self.get_longdesc_id() |
|
138 | 142 | self.user_ids = {} |
|
143 | self.default_notify = "cd %(bzdir)s && ./processmail %(id)s %(user)s" | |
|
139 | 144 | |
|
140 | 145 | def run(self, *args, **kwargs): |
|
141 | 146 | '''run a query.''' |
@@ -172,15 +177,23 b' class bugzilla_2_16(object):' | |||
|
172 | 177 | unknown.pop(id, None) |
|
173 | 178 | return util.sort(unknown.keys()) |
|
174 | 179 | |
|
175 | def notify(self, ids): | |
|
180 | def notify(self, ids, committer): | |
|
176 | 181 | '''tell bugzilla to send mail.''' |
|
177 | 182 | |
|
178 | 183 | self.ui.status(_('telling bugzilla to send mail:\n')) |
|
184 | (user, userid) = self.get_bugzilla_user(committer) | |
|
179 | 185 | for id in ids: |
|
180 | 186 | self.ui.status(_(' bug %s\n') % id) |
|
181 | cmd = self.ui.config('bugzilla', 'notify', | |
|
182 | 'cd /var/www/html/bugzilla && ' | |
|
183 | './processmail %s nobody@nowhere.com') % id | |
|
187 | cmdfmt = self.ui.config('bugzilla', 'notify', self.default_notify) | |
|
188 | bzdir = self.ui.config('bugzilla', 'bzdir', '/var/www/html/bugzilla') | |
|
189 | try: | |
|
190 | # Backwards-compatible with old notify string, which | |
|
191 | # took one string. This will throw with a new format | |
|
192 | # string. | |
|
193 | cmd = cmdfmt % id | |
|
194 | except TypeError: | |
|
195 | cmd = cmdfmt % {'bzdir': bzdir, 'id': id, 'user': user} | |
|
196 | self.ui.note(_('running notify command %s\n') % cmd) | |
|
184 | 197 | fp = util.popen('(%s) 2>&1' % cmd) |
|
185 | 198 | out = fp.read() |
|
186 | 199 | ret = fp.close() |
@@ -215,9 +228,10 b' class bugzilla_2_16(object):' | |||
|
215 | 228 | return bzuser |
|
216 | 229 | return user |
|
217 | 230 | |
|
218 |
def |
|
|
219 | '''add comment to bug. try adding comment as committer of | |
|
220 | changeset, otherwise as default bugzilla user.''' | |
|
231 | def get_bugzilla_user(self, committer): | |
|
232 | '''see if committer is a registered bugzilla user. Return | |
|
233 | bugzilla username and userid if so. If not, return default | |
|
234 | bugzilla username and userid.''' | |
|
221 | 235 | user = self.map_committer(committer) |
|
222 | 236 | try: |
|
223 | 237 | userid = self.get_user_id(user) |
@@ -228,9 +242,16 b' class bugzilla_2_16(object):' | |||
|
228 | 242 | raise util.Abort(_('cannot find bugzilla user id for %s') % |
|
229 | 243 | user) |
|
230 | 244 | userid = self.get_user_id(defaultuser) |
|
245 | user = defaultuser | |
|
231 | 246 | except KeyError: |
|
232 | 247 | raise util.Abort(_('cannot find bugzilla user id for %s or %s') % |
|
233 | 248 | (user, defaultuser)) |
|
249 | return (user, userid) | |
|
250 | ||
|
251 | def add_comment(self, bugid, text, committer): | |
|
252 | '''add comment to bug. try adding comment as committer of | |
|
253 | changeset, otherwise as default bugzilla user.''' | |
|
254 | (user, userid) = self.get_bugzilla_user(committer) | |
|
234 | 255 | now = time.strftime('%Y-%m-%d %H:%M:%S') |
|
235 | 256 | self.run('''insert into longdescs |
|
236 | 257 | (bug_id, who, bug_when, thetext) |
@@ -241,11 +262,18 b' class bugzilla_2_16(object):' | |||
|
241 | 262 | (bugid, userid, now, self.longdesc_id)) |
|
242 | 263 | self.conn.commit() |
|
243 | 264 | |
|
244 |
class bugzilla_ |
|
|
265 | class bugzilla_2_18(bugzilla_2_16): | |
|
266 | '''support for bugzilla 2.18 series.''' | |
|
267 | ||
|
268 | def __init__(self, ui): | |
|
269 | bugzilla_2_16.__init__(self, ui) | |
|
270 | self.default_notify = "cd %(bzdir)s && perl -T contrib/sendbugmail.pl %(id)s %(user)s" | |
|
271 | ||
|
272 | class bugzilla_3_0(bugzilla_2_18): | |
|
245 | 273 | '''support for bugzilla 3.0 series.''' |
|
246 | 274 | |
|
247 | 275 | def __init__(self, ui): |
|
248 |
bugzilla_2_1 |
|
|
276 | bugzilla_2_18.__init__(self, ui) | |
|
249 | 277 | |
|
250 | 278 | def get_longdesc_id(self): |
|
251 | 279 | '''get identity of longdesc field''' |
@@ -260,6 +288,7 b' class bugzilla(object):' | |||
|
260 | 288 | # different schemas. |
|
261 | 289 | _versions = { |
|
262 | 290 | '2.16': bugzilla_2_16, |
|
291 | '2.18': bugzilla_2_18, | |
|
263 | 292 | '3.0': bugzilla_3_0 |
|
264 | 293 | } |
|
265 | 294 | |
@@ -375,7 +404,7 b' def hook(ui, repo, hooktype, node=None, ' | |||
|
375 | 404 | if ids: |
|
376 | 405 | for id in ids: |
|
377 | 406 | bz.update(id, ctx) |
|
378 | bz.notify(ids) | |
|
407 | bz.notify(ids, util.email(ctx.user())) | |
|
379 | 408 | except MySQLdb.MySQLError, err: |
|
380 | 409 | raise util.Abort(_('database error: %s') % err[1]) |
|
381 | 410 |
General Comments 0
You need to be logged in to leave comments.
Login now