hgext/bugzilla.py
author Jim Hague <jim.hague@acm.org>
Mon, 04 Apr 2011 13:31:37 +0100
changeset 13870 ce066d424bba
parent 13854 5ed036e42fd9
child 13871 22d200e49b10
permissions -rw-r--r--
bugzilla: correct sample configurations Use consistent sample domains and wording in all configuration examples. Add missing template and strip parameters to XMLRPC examples and correct Bugzilla URL key in XMLRPC+email.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     1
# bugzilla.py - bugzilla integration for mercurial
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     2
#
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     3
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
     4
# Copyright 2011 Jim Hague <jim.hague@acm.org>
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     5
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
     6
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10112
diff changeset
     7
# GNU General Public License version 2 or any later version.
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
     8
8935
f4f0e902b750 extensions: change descriptions for hook-providing extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8894
diff changeset
     9
'''hooks for integrating with the Bugzilla bug tracker
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
    10
9252
b03aa86f4c10 bugzilla: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9204
diff changeset
    11
This hook extension adds comments on bugs in Bugzilla when changesets
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    12
that refer to bugs by Bugzilla ID are seen. The comment is formatted using
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    13
the Mercurial template mechanism.
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
    14
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    15
The hook does not change bug status.
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
    16
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    17
Three basic modes of access to Bugzilla are provided:
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
    18
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    19
1. Access via the Bugzilla XMLRPC interface. Requires Bugzilla 3.4 or later.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    20
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    21
2. Check data via the Bugzilla XMLRPC interface and submit bug change
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    22
   via email to Bugzilla email interface. Requires Bugzilla 3.4 or later.
9203
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    23
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    24
2. Writing directly to the Bugzilla database. Only Bugzilla installations
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    25
   using MySQL are supported. Requires Python MySQLdb.
9203
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    26
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    27
Writing directly to the database is susceptible to schema changes, and
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    28
relies on a Bugzilla contrib script to send out bug change
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    29
notification emails. This script runs as the user running Mercurial,
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    30
must be run on the host with the Bugzilla install, and requires
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    31
permission to read Bugzilla configuration details and the necessary
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    32
MySQL user and password to have full access rights to the Bugzilla
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    33
database. For these reasons this access mode is now considered
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    34
deprecated, and will not be updated for new Bugzilla versions going
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    35
forward.
9203
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    36
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    37
Access via XMLRPC needs a Bugzilla username and password to be specified
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    38
in the configuration. Comments are added under that username. Since the
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    39
configuration must be readable by all Mercurial users, it is recommended
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    40
that the rights of that user are restricted in Bugzilla to the minimum
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    41
necessary to add comments.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    42
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    43
Access via XMLRPC/email behaves uses XMLRPC to query Bugzilla, but sends
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    44
email to the Bugzilla email interface to submit comments to bugs.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    45
The From: address in the email is set to the email address of the Mercurial
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    46
user, so the comment appears to come from the Mercurial user. In the event
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    47
that the Mercurial user email is not recognised by Bugzilla as a Bugzilla
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    48
user, the Bugzilla username and password used to log into Bugzilla are
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    49
used instead as the source of the comment.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    50
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    51
Configuration items common to all access modes:
9203
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    52
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
    53
bugzilla.version
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    54
  This access type to use. Values recognised are:
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    55
  xmlrpc       Bugzilla XMLRPC interface.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    56
  xmlrpc+email Bugzilla XMLRPC and email interfaces.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    57
  3.0          MySQL access, Bugzilla 3.0 and later.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    58
  2.18         MySQL access, Bugzilla 2.18 and up to but not including 3.0.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    59
  2.16         MySQL access, Bugzilla 2.16 and up to but not including 2.18.
7985
0edca606c0f1 bugzilla: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7762
diff changeset
    60
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
    61
bugzilla.regexp
9252
b03aa86f4c10 bugzilla: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9204
diff changeset
    62
  Regular expression to match bug IDs in changeset commit message.
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
    63
  Must contain one "()" group. The default expression matches ``Bug
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
    64
  1234``, ``Bug no. 1234``, ``Bug number 1234``, ``Bugs 1234,5678``,
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
    65
  ``Bug 1234 and 5678`` and variations thereof. Matching is case
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
    66
  insensitive.
9203
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    67
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
    68
bugzilla.style
9203
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    69
  The style file to use when formatting comments.
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    70
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
    71
bugzilla.template
9252
b03aa86f4c10 bugzilla: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9204
diff changeset
    72
  Template to use when formatting comments. Overrides style if
b03aa86f4c10 bugzilla: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9204
diff changeset
    73
  specified. In addition to the usual Mercurial keywords, the
b03aa86f4c10 bugzilla: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9204
diff changeset
    74
  extension specifies::
9203
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    75
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    76
    {bug}       The Bugzilla bug ID.
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    77
    {root}      The full pathname of the Mercurial repository.
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    78
    {webroot}   Stripped pathname of the Mercurial repository.
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    79
    {hgweb}     Base URL for browsing Mercurial repositories.
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
    80
13842
4cffce61bd92 bugzilla: fix bad reST markup
Martin Geisler <mg@aragost.com>
parents: 13841
diff changeset
    81
  Default ``changeset {node|short} in repo {root} refers to bug
4cffce61bd92 bugzilla: fix bad reST markup
Martin Geisler <mg@aragost.com>
parents: 13841
diff changeset
    82
  {bug}.\\ndetails:\\n\\t{desc|tabindent}``
9203
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
    83
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
    84
bugzilla.strip
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
    85
  The number of path separator characters to strip from the front of
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
    86
  the Mercurial repository path (``{root}`` in templates) to produce
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
    87
  ``{webroot}``. For example, a repository with ``{root}``
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
    88
  ``/var/local/my-project`` with a strip of 2 gives a value for
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
    89
  ``{webroot}`` of ``my-project``. Default 0.
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    90
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
    91
web.baseurl
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    92
  Base URL for browsing Mercurial repositories. Referenced from
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    93
  templates as {hgweb}.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
    94
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    95
Configuration items common to XMLRPC+email and MySQL access modes:
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    96
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
    97
bugzilla.usermap
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    98
  Path of file containing Mercurial committer email to Bugzilla user email
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
    99
  mappings. If specified, the file should contain one mapping per
13835
135bed43e20c bugzilla: show usermap syntax more clearly
Martin Geisler <mg@aragost.com>
parents: 13834
diff changeset
   100
  line::
135bed43e20c bugzilla: show usermap syntax more clearly
Martin Geisler <mg@aragost.com>
parents: 13834
diff changeset
   101
135bed43e20c bugzilla: show usermap syntax more clearly
Martin Geisler <mg@aragost.com>
parents: 13834
diff changeset
   102
    committer = Bugzilla user
135bed43e20c bugzilla: show usermap syntax more clearly
Martin Geisler <mg@aragost.com>
parents: 13834
diff changeset
   103
135bed43e20c bugzilla: show usermap syntax more clearly
Martin Geisler <mg@aragost.com>
parents: 13834
diff changeset
   104
  See also the [usermap] section.
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   105
13836
ed15922af2f9 bugzilla: markup section names as literal text
Martin Geisler <mg@aragost.com>
parents: 13835
diff changeset
   106
The ``[usermap]`` section is used to specify mappings of Mercurial
13834
0aa2cfd0b21a bugzilla: use standard section.name notation
Martin Geisler <mg@aragost.com>
parents: 13833
diff changeset
   107
committer email to Bugzilla user email. See also ``bugzilla.usermap``.
13835
135bed43e20c bugzilla: show usermap syntax more clearly
Martin Geisler <mg@aragost.com>
parents: 13834
diff changeset
   108
Contains entries of the form ``committer = Bugzilla user``.
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   109
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   110
XMLRPC access mode configuration:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   111
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   112
bugzilla.bzurl
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   113
  The base URL for the Bugzilla installation.
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   114
  Default ``http://localhost/bugzilla``.
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   115
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   116
bugzilla.user
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   117
  The username to use to log into Bugzilla via XMLRPC. Default
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   118
  ``bugs``.
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   119
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   120
bugzilla.password
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   121
  The password for Bugzilla login.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   122
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   123
XMLRPC+email access mode uses the XMLRPC access mode configuration items,
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   124
and also:
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   125
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   126
bugzilla.bzemail
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   127
  The Bugzilla email address.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   128
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   129
In addition, the Mercurial email settings must be configured. See the
13837
22f20d0fe2d3 bugzilla: refer to hgrc(5) man page with normal notation
Martin Geisler <mg@aragost.com>
parents: 13836
diff changeset
   130
documentation in hgrc(5), sections ``[email]`` and ``[smtp]``.
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   131
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   132
MySQL access mode configuration:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   133
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   134
bugzilla.host
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   135
  Hostname of the MySQL server holding the Bugzilla database.
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   136
  Default ``localhost``.
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   137
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   138
bugzilla.db
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   139
  Name of the Bugzilla database in MySQL. Default ``bugs``.
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   140
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   141
bugzilla.user
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   142
  Username to use to access MySQL server. Default ``bugs``.
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   143
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   144
bugzilla.password
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   145
  Password to use to access MySQL server.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   146
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   147
bugzilla.timeout
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   148
  Database connection timeout (seconds). Default 5.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   149
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   150
bugzilla.bzuser
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   151
  Fallback Bugzilla user name to record comments with, if changeset
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   152
  committer cannot be found as a Bugzilla user.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   153
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   154
bugzilla.bzdir
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   155
   Bugzilla install directory. Used by default notify. Default
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   156
   ``/var/www/html/bugzilla``.
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   157
13833
64ad07dff0a8 bugzilla: prefix each config option with section
Martin Geisler <mg@aragost.com>
parents: 13832
diff changeset
   158
bugzilla.notify
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   159
  The command to run to get Bugzilla to send bug change notification
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   160
  emails. Substitutes from a map with 3 keys, ``bzdir``, ``id`` (bug
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   161
  id) and ``user`` (committer bugzilla email). Default depends on
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   162
  version; from 2.18 it is "cd %(bzdir)s && perl -T
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   163
  contrib/sendbugmail.pl %(id)s %(user)s".
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   164
9203
e4dbd49b88a9 bugzilla: reformat list of configuration options
Martin Geisler <mg@lazybytes.net>
parents: 9054
diff changeset
   165
Activating the extension::
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   166
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   167
    [extensions]
10112
703db37d186b hgext: enable extensions without "hgext." prefix in help texts
Martin Geisler <mg@lazybytes.net>
parents: 9252
diff changeset
   168
    bugzilla =
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   169
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   170
    [hooks]
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   171
    # run bugzilla hook on every change pulled or pushed in here
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   172
    incoming.bugzilla = python:hgext.bugzilla.hook
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   173
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   174
Example configurations:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   175
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   176
XMLRPC example configuration. This uses the Bugzilla at
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   177
``http://my-project.org/bugzilla``, logging in as user
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   178
``bugmail@my-project.org`` with password ``plugh``. It is used with a
13870
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   179
collection of Mercurial repositories in ``/var/local/hg/repos/``,
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   180
with a web interface at ``http://my-project.org/hg``. ::
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   181
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   182
    [bugzilla]
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   183
    bzurl=http://my-project.org/bugzilla
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   184
    user=bugmail@my-project.org
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   185
    password=plugh
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   186
    version=xmlrpc
13870
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   187
    template=Changeset {node|short} in {root|basename}.
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   188
             {hgweb}/{webroot}/rev/{node|short}\\n
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   189
             {desc}\\n
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   190
    strip=5
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   191
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   192
    [web]
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   193
    baseurl=http://my-project.org/hg
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   194
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   195
XMLRPC+email example configuration. This uses the Bugzilla at
13841
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   196
``http://my-project.org/bugzilla``, logging in as user
367805c848e5 bugzilla: markup literal text as such
Martin Geisler <mg@aragost.com>
parents: 13837
diff changeset
   197
``bugmail@my-project.org`` wityh password ``plugh``. It is used with a
13870
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   198
collection of Mercurial repositories in ``/var/local/hg/repos/``,
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   199
with a web interface at ``http://my-project.org/hg``. Bug comments
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   200
are sent to the Bugzilla email address
13854
5ed036e42fd9 bugzilla: fix documentation typo
Patrick Mezard <pmezard@gmail.com>
parents: 13842
diff changeset
   201
``bugzilla@my-project.org``. ::
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   202
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   203
    [bugzilla]
13870
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   204
    bzurl=http://my-project.org/bugzilla
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   205
    user=bugmail@my-project.org
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   206
    password=plugh
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   207
    version=xmlrpc
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   208
    bzemail=bugzilla@my-project.org
13870
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   209
    template=Changeset {node|short} in {root|basename}.
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   210
             {hgweb}/{webroot}/rev/{node|short}\\n
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   211
             {desc}\\n
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   212
    strip=5
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   213
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   214
    [web]
13870
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   215
    baseurl=http://my-project.org/hg
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   216
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   217
    [usermap]
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   218
    user@emaildomain.com=user.name@bugzilladomain.com
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   219
13870
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   220
MySQL example configuration. This has a local Bugzilla 3.2 installation
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   221
in ``/opt/bugzilla-3.2``. The MySQL database is on ``localhost``,
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   222
the Bugzilla database name is ``bugs`` and MySQL is
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   223
accessed with MySQL username ``bugs`` password ``XYZZY``. It is used
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   224
with a collection of Mercurial repositories in ``/var/local/hg/repos/``,
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   225
with a web interface at ``http://my-project.org/hg``. ::
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   226
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   227
    [bugzilla]
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   228
    host=localhost
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   229
    password=XYZZY
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   230
    version=3.0
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   231
    bzuser=unknown@domain.com
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   232
    bzdir=/opt/bugzilla-3.2
9204
8d59e43854d9 bugzilla: wrap example template line
Martin Geisler <mg@lazybytes.net>
parents: 9203
diff changeset
   233
    template=Changeset {node|short} in {root|basename}.
8d59e43854d9 bugzilla: wrap example template line
Martin Geisler <mg@lazybytes.net>
parents: 9203
diff changeset
   234
             {hgweb}/{webroot}/rev/{node|short}\\n
8d59e43854d9 bugzilla: wrap example template line
Martin Geisler <mg@lazybytes.net>
parents: 9203
diff changeset
   235
             {desc}\\n
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   236
    strip=5
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   237
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   238
    [web]
13870
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   239
    baseurl=http://my-project.org/hg
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   240
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   241
    [usermap]
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   242
    user@emaildomain.com=user.name@bugzilladomain.com
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   243
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   244
All the above add a comment to the Bugzilla bug record of the form::
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   245
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   246
    Changeset 3b16791d6642 in repository-name.
13870
ce066d424bba bugzilla: correct sample configurations
Jim Hague <jim.hague@acm.org>
parents: 13854
diff changeset
   247
    http://my-project.org/hg/repository-name/rev/3b16791d6642
7504
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   248
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   249
    Changeset commit comment. Bug 1234.
d8cd79fbed3c Revise Bugzilla module comments into extension help.
Jim Hague <jim.hague@acm.org>
parents: 7493
diff changeset
   250
'''
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   251
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
   252
from mercurial.i18n import _
6211
f89fd07fc51d Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents: 5975
diff changeset
   253
from mercurial.node import short
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   254
from mercurial import cmdutil, mail, templater, util
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   255
import re, time, xmlrpclib
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   256
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   257
class bzaccess(object):
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   258
    '''Base class for access to Bugzilla.'''
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   259
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   260
    def __init__(self, ui):
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   261
        self.ui = ui
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   262
        usermap = self.ui.config('bugzilla', 'usermap')
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   263
        if usermap:
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   264
            self.ui.readconfig(usermap, sections=['usermap'])
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   265
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   266
    def map_committer(self, user):
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   267
        '''map name of committer to Bugzilla user name.'''
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   268
        for committer, bzuser in self.ui.configitems('usermap'):
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   269
            if committer.lower() == user.lower():
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   270
                return bzuser
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   271
        return user
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   272
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   273
    # Methods to be implemented by access classes.
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   274
    def filter_real_bug_ids(self, ids):
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   275
        '''remove bug IDs that do not exist in Bugzilla from set.'''
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   276
        pass
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   277
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   278
    def filter_cset_known_bug_ids(self, node, ids):
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   279
        '''remove bug IDs where node occurs in comment text from set.'''
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   280
        pass
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   281
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   282
    def add_comment(self, bugid, text, committer):
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   283
        '''add comment to bug.
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   284
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   285
        If possible add the comment as being from the committer of
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   286
        the changeset. Otherwise use the default Bugzilla user.
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   287
        '''
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   288
        pass
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   289
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   290
    def notify(self, ids, committer):
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   291
        '''Force sending of Bugzilla notification emails.'''
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   292
        pass
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   293
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   294
# Bugzilla via direct access to MySQL database.
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   295
class bzmysql(bzaccess):
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   296
    '''Support for direct MySQL access to Bugzilla.
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   297
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   298
    The earliest Bugzilla version this is tested with is version 2.16.
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   299
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   300
    If your Bugzilla is version 3.2 or above, you are strongly
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   301
    recommended to use the XMLRPC access method instead.
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   302
    '''
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   303
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   304
    @staticmethod
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   305
    def sql_buglist(ids):
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   306
        '''return SQL-friendly list of bug ids'''
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   307
        return '(' + ','.join(map(str, ids)) + ')'
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   308
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   309
    _MySQLdb = None
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   310
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   311
    def __init__(self, ui):
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   312
        try:
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   313
            import MySQLdb as mysql
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   314
            bzmysql._MySQLdb = mysql
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   315
        except ImportError, err:
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   316
            raise util.Abort(_('python mysql support not available: %s') % err)
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   317
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   318
        bzaccess.__init__(self, ui)
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   319
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   320
        host = self.ui.config('bugzilla', 'host', 'localhost')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   321
        user = self.ui.config('bugzilla', 'user', 'bugs')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   322
        passwd = self.ui.config('bugzilla', 'password')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   323
        db = self.ui.config('bugzilla', 'db', 'bugs')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   324
        timeout = int(self.ui.config('bugzilla', 'timeout', 5))
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   325
        self.ui.note(_('connecting to %s:%s as %s, password %s\n') %
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   326
                     (host, db, user, '*' * len(passwd)))
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   327
        self.conn = bzmysql._MySQLdb.connect(host=host,
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   328
                                                   user=user, passwd=passwd,
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   329
                                                   db=db,
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   330
                                                   connect_timeout=timeout)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   331
        self.cursor = self.conn.cursor()
7019
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   332
        self.longdesc_id = self.get_longdesc_id()
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   333
        self.user_ids = {}
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   334
        self.default_notify = "cd %(bzdir)s && ./processmail %(id)s %(user)s"
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   335
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   336
    def run(self, *args, **kwargs):
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   337
        '''run a query.'''
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   338
        self.ui.note(_('query: %s %s\n') % (args, kwargs))
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   339
        try:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   340
            self.cursor.execute(*args, **kwargs)
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   341
        except bzmysql._MySQLdb.MySQLError:
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   342
            self.ui.note(_('failed query: %s %s\n') % (args, kwargs))
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   343
            raise
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   344
7019
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   345
    def get_longdesc_id(self):
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   346
        '''get identity of longdesc field'''
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   347
        self.run('select fieldid from fielddefs where name = "longdesc"')
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   348
        ids = self.cursor.fetchall()
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   349
        if len(ids) != 1:
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   350
            raise util.Abort(_('unknown database schema'))
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   351
        return ids[0][0]
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   352
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   353
    def filter_real_bug_ids(self, ids):
13799
d04fc5582772 bugzilla: keep bug IDs in set.
Jim Hague <jim.hague@acm.org>
parents: 13798
diff changeset
   354
        '''filter not-existing bug ids from set.'''
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   355
        self.run('select bug_id from bugs where bug_id in %s' %
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   356
                 bzmysql.sql_buglist(ids))
13799
d04fc5582772 bugzilla: keep bug IDs in set.
Jim Hague <jim.hague@acm.org>
parents: 13798
diff changeset
   357
        return set([c[0] for c in self.cursor.fetchall()])
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   358
13798
9c9fa78f4e2d bugzilla: rename filter_unknown_bug_ids to reflect its actual purpose.
Jim Hague <jim.hague@acm.org>
parents: 11567
diff changeset
   359
    def filter_cset_known_bug_ids(self, node, ids):
13799
d04fc5582772 bugzilla: keep bug IDs in set.
Jim Hague <jim.hague@acm.org>
parents: 13798
diff changeset
   360
        '''filter bug ids that already refer to this changeset from set.'''
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   361
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   362
        self.run('''select bug_id from longdescs where
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   363
                    bug_id in %s and thetext like "%%%s%%"''' %
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   364
                 (bzmysql.sql_buglist(ids), short(node)))
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   365
        for (id,) in self.cursor.fetchall():
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   366
            self.ui.status(_('bug %d already knows about changeset %s\n') %
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   367
                           (id, short(node)))
13799
d04fc5582772 bugzilla: keep bug IDs in set.
Jim Hague <jim.hague@acm.org>
parents: 13798
diff changeset
   368
            ids.discard(id)
d04fc5582772 bugzilla: keep bug IDs in set.
Jim Hague <jim.hague@acm.org>
parents: 13798
diff changeset
   369
        return ids
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   370
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   371
    def notify(self, ids, committer):
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   372
        '''tell bugzilla to send mail.'''
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   373
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   374
        self.ui.status(_('telling bugzilla to send mail:\n'))
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   375
        (user, userid) = self.get_bugzilla_user(committer)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   376
        for id in ids:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   377
            self.ui.status(_('  bug %s\n') % id)
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   378
            cmdfmt = self.ui.config('bugzilla', 'notify', self.default_notify)
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   379
            bzdir = self.ui.config('bugzilla', 'bzdir', '/var/www/html/bugzilla')
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   380
            try:
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   381
                # Backwards-compatible with old notify string, which
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   382
                # took one string. This will throw with a new format
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   383
                # string.
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   384
                cmd = cmdfmt % id
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   385
            except TypeError:
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   386
                cmd = cmdfmt % {'bzdir': bzdir, 'id': id, 'user': user}
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   387
            self.ui.note(_('running notify command %s\n') % cmd)
6548
962eb403165b replace usage of os.popen() with util.popen()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6211
diff changeset
   388
            fp = util.popen('(%s) 2>&1' % cmd)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   389
            out = fp.read()
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   390
            ret = fp.close()
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   391
            if ret:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   392
                self.ui.warn(out)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   393
                raise util.Abort(_('bugzilla notify command %s') %
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   394
                                 util.explain_exit(ret)[0])
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   395
        self.ui.status(_('done\n'))
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   396
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   397
    def get_user_id(self, user):
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   398
        '''look up numeric bugzilla user id.'''
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   399
        try:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   400
            return self.user_ids[user]
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   401
        except KeyError:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   402
            try:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   403
                userid = int(user)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   404
            except ValueError:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   405
                self.ui.note(_('looking up user %s\n') % user)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   406
                self.run('''select userid from profiles
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   407
                            where login_name like %s''', user)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   408
                all = self.cursor.fetchall()
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   409
                if len(all) != 1:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   410
                    raise KeyError(user)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   411
                userid = int(all[0][0])
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   412
            self.user_ids[user] = userid
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   413
            return userid
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   414
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   415
    def get_bugzilla_user(self, committer):
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   416
        '''See if committer is a registered bugzilla user. Return
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   417
        bugzilla username and userid if so. If not, return default
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   418
        bugzilla username and userid.'''
2306
4c67ba93560b bugzilla: allow to map between committer email and bugzilla user name.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2239
diff changeset
   419
        user = self.map_committer(committer)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   420
        try:
2306
4c67ba93560b bugzilla: allow to map between committer email and bugzilla user name.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2239
diff changeset
   421
            userid = self.get_user_id(user)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   422
        except KeyError:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   423
            try:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   424
                defaultuser = self.ui.config('bugzilla', 'bzuser')
2306
4c67ba93560b bugzilla: allow to map between committer email and bugzilla user name.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2239
diff changeset
   425
                if not defaultuser:
4c67ba93560b bugzilla: allow to map between committer email and bugzilla user name.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2239
diff changeset
   426
                    raise util.Abort(_('cannot find bugzilla user id for %s') %
4c67ba93560b bugzilla: allow to map between committer email and bugzilla user name.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2239
diff changeset
   427
                                     user)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   428
                userid = self.get_user_id(defaultuser)
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   429
                user = defaultuser
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   430
            except KeyError:
2306
4c67ba93560b bugzilla: allow to map between committer email and bugzilla user name.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2239
diff changeset
   431
                raise util.Abort(_('cannot find bugzilla user id for %s or %s') %
4c67ba93560b bugzilla: allow to map between committer email and bugzilla user name.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2239
diff changeset
   432
                                 (user, defaultuser))
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   433
        return (user, userid)
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   434
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   435
    def add_comment(self, bugid, text, committer):
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   436
        '''add comment to bug. try adding comment as committer of
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   437
        changeset, otherwise as default bugzilla user.'''
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   438
        (user, userid) = self.get_bugzilla_user(committer)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   439
        now = time.strftime('%Y-%m-%d %H:%M:%S')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   440
        self.run('''insert into longdescs
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   441
                    (bug_id, who, bug_when, thetext)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   442
                    values (%s, %s, %s, %s)''',
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   443
                 (bugid, userid, now, text))
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   444
        self.run('''insert into bugs_activity (bug_id, who, bug_when, fieldid)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   445
                    values (%s, %s, %s, %s)''',
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   446
                 (bugid, userid, now, self.longdesc_id))
7493
518afef5e350 Fix Bugzilla integration to work with new Bugzilla 3.2.
Jim Hague <jim.hague@acm.org>
parents: 7369
diff changeset
   447
        self.conn.commit()
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   448
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   449
class bzmysql_2_18(bzmysql):
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   450
    '''support for bugzilla 2.18 series.'''
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   451
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   452
    def __init__(self, ui):
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   453
        bzmysql.__init__(self, ui)
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   454
        self.default_notify = \
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   455
            "cd %(bzdir)s && perl -T contrib/sendbugmail.pl %(id)s %(user)s"
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   456
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   457
class bzmysql_3_0(bzmysql_2_18):
7019
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   458
    '''support for bugzilla 3.0 series.'''
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   459
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   460
    def __init__(self, ui):
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   461
        bzmysql_2_18.__init__(self, ui)
7019
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   462
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   463
    def get_longdesc_id(self):
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   464
        '''get identity of longdesc field'''
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   465
        self.run('select id from fielddefs where name = "longdesc"')
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   466
        ids = self.cursor.fetchall()
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   467
        if len(ids) != 1:
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   468
            raise util.Abort(_('unknown database schema'))
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   469
        return ids[0][0]
6b1ece890f9a Add support for Bugzilla 3.0 series to bugzilla hook.
Jim Hague <jim.hague@acm.org>
parents: 6762
diff changeset
   470
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   471
# Buzgilla via XMLRPC interface.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   472
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   473
class CookieSafeTransport(xmlrpclib.SafeTransport):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   474
    """A SafeTransport that retains cookies over its lifetime.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   475
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   476
    The regular xmlrpclib transports ignore cookies. Which causes
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   477
    a bit of a problem when you need a cookie-based login, as with
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   478
    the Bugzilla XMLRPC interface.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   479
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   480
    So this is a SafeTransport which looks for cookies being set
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   481
    in responses and saves them to add to all future requests.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   482
    It appears a SafeTransport can do both HTTP and HTTPS sessions,
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   483
    which saves us having to do a CookieTransport too.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   484
    """
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   485
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   486
    # Inspiration drawn from
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   487
    # http://blog.godson.in/2010/09/how-to-make-python-xmlrpclib-client.html
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   488
    # http://www.itkovian.net/base/transport-class-for-pythons-xml-rpc-lib/
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   489
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   490
    cookies = []
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   491
    def send_cookies(self, connection):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   492
        if self.cookies:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   493
            for cookie in self.cookies:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   494
                connection.putheader("Cookie", cookie)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   495
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   496
    def request(self, host, handler, request_body, verbose=0):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   497
        self.verbose = verbose
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   498
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   499
        # issue XML-RPC request
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   500
        h = self.make_connection(host)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   501
        if verbose:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   502
            h.set_debuglevel(1)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   503
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   504
        self.send_request(h, handler, request_body)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   505
        self.send_host(h, host)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   506
        self.send_cookies(h)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   507
        self.send_user_agent(h)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   508
        self.send_content(h, request_body)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   509
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   510
        # Deal with differences between Python 2.4-2.6 and 2.7.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   511
        # In the former h is a HTTP(S). In the latter it's a
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   512
        # HTTP(S)Connection. Luckily, the 2.4-2.6 implementation of
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   513
        # HTTP(S) has an underlying HTTP(S)Connection, so extract
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   514
        # that and use it.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   515
        try:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   516
            response = h.getresponse()
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   517
        except AttributeError:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   518
            response = h._conn.getresponse()
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   519
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   520
        # Add any cookie definitions to our list.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   521
        for header in response.msg.getallmatchingheaders("Set-Cookie"):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   522
            val = header.split(": ", 1)[1]
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   523
            cookie = val.split(";", 1)[0]
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   524
            self.cookies.append(cookie)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   525
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   526
        if response.status != 200:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   527
            raise xmlrpclib.ProtocolError(host + handler, response.status,
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   528
                                          response.reason, response.msg.headers)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   529
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   530
        payload = response.read()
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   531
        parser, unmarshaller = self.getparser()
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   532
        parser.feed(payload)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   533
        parser.close()
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   534
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   535
        return unmarshaller.close()
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   536
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   537
class bzxmlrpc(bzaccess):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   538
    """Support for access to Bugzilla via the Bugzilla XMLRPC API.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   539
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   540
    Requires a minimum Bugzilla version 3.4.
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   541
    """
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   542
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   543
    def __init__(self, ui):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   544
        bzaccess.__init__(self, ui)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   545
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   546
        bzweb = self.ui.config('bugzilla', 'bzurl',
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   547
                               'http://localhost/bugzilla/')
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   548
        bzweb = bzweb.rstrip("/") + "/xmlrpc.cgi"
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   549
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   550
        user = self.ui.config('bugzilla', 'user', 'bugs')
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   551
        passwd = self.ui.config('bugzilla', 'password')
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   552
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   553
        self.bzproxy = xmlrpclib.ServerProxy(bzweb, CookieSafeTransport())
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   554
        self.bzproxy.User.login(dict(login=user, password=passwd))
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   555
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   556
    def get_bug_comments(self, id):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   557
        """Return a string with all comment text for a bug."""
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   558
        c = self.bzproxy.Bug.comments(dict(ids=[id]))
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   559
        return ''.join([t['text'] for t in c['bugs'][str(id)]['comments']])
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   560
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   561
    def filter_real_bug_ids(self, ids):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   562
        res = set()
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   563
        bugs = self.bzproxy.Bug.get(dict(ids=sorted(ids), permissive=True))
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   564
        for bug in bugs['bugs']:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   565
            res.add(bug['id'])
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   566
        return res
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   567
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   568
    def filter_cset_known_bug_ids(self, node, ids):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   569
        for id in sorted(ids):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   570
            if self.get_bug_comments(id).find(short(node)) != -1:
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   571
                self.ui.status(_('bug %d already knows about changeset %s\n') %
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   572
                               (id, short(node)))
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   573
                ids.discard(id)
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   574
        return ids
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   575
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   576
    def add_comment(self, bugid, text, committer):
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   577
        self.bzproxy.Bug.add_comment(dict(id=bugid, comment=text))
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   578
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   579
class bzxmlrpcemail(bzxmlrpc):
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   580
    """Read data from Bugzilla via XMLRPC, send updates via email.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   581
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   582
    Advantages of sending updates via email:
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   583
      1. Comments can be added as any user, not just logged in user.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   584
      2. Bug statuses and other fields not accessible via XMLRPC can
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   585
        be updated. This is not currently used.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   586
    """
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   587
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   588
    def __init__(self, ui):
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   589
        bzxmlrpc.__init__(self, ui)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   590
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   591
        self.bzemail = self.ui.config('bugzilla', 'bzemail')
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   592
        if not self.bzemail:
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   593
            raise util.Abort(_("configuration 'bzemail' missing"))
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   594
        mail.validateconfig(self.ui)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   595
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   596
    def send_bug_modify_email(self, bugid, commands, comment, committer):
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   597
        '''send modification message to Bugzilla bug via email.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   598
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   599
        The message format is documented in the Bugzilla email_in.pl
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   600
        specification. commands is a list of command lines, comment is the
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   601
        comment text.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   602
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   603
        To stop users from crafting commit comments with
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   604
        Bugzilla commands, specify the bug ID via the message body, rather
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   605
        than the subject line, and leave a blank line after it.
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   606
        '''
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   607
        user = self.map_committer(committer)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   608
        matches = self.bzproxy.User.get(dict(match=[user]))
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   609
        if not matches['users']:
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   610
            user = self.ui.config('bugzilla', 'user', 'bugs')
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   611
            matches = self.bzproxy.User.get(dict(match=[user]))
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   612
            if not matches['users']:
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   613
                raise util.Abort(_("default bugzilla user %s email not found") %
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   614
                                 user)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   615
        user = matches['users'][0]['email']
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   616
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   617
        text = "\n".join(commands) + "\n@bug_id = %d\n\n" % bugid + comment
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   618
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   619
        _charsets = mail._charsets(self.ui)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   620
        user = mail.addressencode(self.ui, user, _charsets)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   621
        bzemail = mail.addressencode(self.ui, self.bzemail, _charsets)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   622
        msg = mail.mimeencode(self.ui, text, _charsets)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   623
        msg['From'] = user
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   624
        msg['To'] = bzemail
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   625
        msg['Subject'] = mail.headencode(self.ui, "Bug modification", _charsets)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   626
        sendmail = mail.connect(self.ui)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   627
        sendmail(user, bzemail, msg.as_string())
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   628
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   629
    def add_comment(self, bugid, text, committer):
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   630
        self.send_bug_modify_email(bugid, [], text, committer)
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   631
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   632
class bugzilla(object):
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   633
    # supported versions of bugzilla. different versions have
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   634
    # different schemas.
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   635
    _versions = {
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   636
        '2.16': bzmysql,
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   637
        '2.18': bzmysql_2_18,
13801
60256f7f30c1 bugzilla: add XMLRPC interface.
Jim Hague <jim.hague@acm.org>
parents: 13800
diff changeset
   638
        '3.0':  bzmysql_3_0,
13802
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   639
        'xmlrpc': bzxmlrpc,
49b5a1aaf726 bugzilla: add modified XMLRPC mode that uses email to send bug comments.
Jim Hague <jim.hague@acm.org>
parents: 13801
diff changeset
   640
        'xmlrpc+email': bzxmlrpcemail
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   641
        }
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   642
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   643
    _default_bug_re = (r'bugs?\s*,?\s*(?:#|nos?\.?|num(?:ber)?s?)?\s*'
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   644
                       r'((?:\d+\s*(?:,?\s*(?:and)?)?\s*)+)')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   645
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   646
    _bz = None
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   647
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   648
    def __init__(self, ui, repo):
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   649
        self.ui = ui
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   650
        self.repo = repo
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   651
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   652
    def bz(self):
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   653
        '''return object that knows how to talk to bugzilla version in
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   654
        use.'''
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   655
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   656
        if bugzilla._bz is None:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   657
            bzversion = self.ui.config('bugzilla', 'version')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   658
            try:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   659
                bzclass = bugzilla._versions[bzversion]
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   660
            except KeyError:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   661
                raise util.Abort(_('bugzilla version %s not supported') %
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   662
                                 bzversion)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   663
            bugzilla._bz = bzclass(self.ui)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   664
        return bugzilla._bz
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   665
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   666
    def __getattr__(self, key):
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   667
        return getattr(self.bz(), key)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   668
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   669
    _bug_re = None
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   670
    _split_re = None
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   671
3976
f8849648b0e2 bugzilla: use contexts, simplify
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3891
diff changeset
   672
    def find_bug_ids(self, ctx):
13799
d04fc5582772 bugzilla: keep bug IDs in set.
Jim Hague <jim.hague@acm.org>
parents: 13798
diff changeset
   673
        '''return set of integer bug IDs from commit comment.
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   674
13799
d04fc5582772 bugzilla: keep bug IDs in set.
Jim Hague <jim.hague@acm.org>
parents: 13798
diff changeset
   675
        Extract bug IDs from changeset comments. Filter out any that are
d04fc5582772 bugzilla: keep bug IDs in set.
Jim Hague <jim.hague@acm.org>
parents: 13798
diff changeset
   676
        not known to Bugzilla, and any that already have a reference to
d04fc5582772 bugzilla: keep bug IDs in set.
Jim Hague <jim.hague@acm.org>
parents: 13798
diff changeset
   677
        the given changeset in their comments.
d04fc5582772 bugzilla: keep bug IDs in set.
Jim Hague <jim.hague@acm.org>
parents: 13798
diff changeset
   678
        '''
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   679
        if bugzilla._bug_re is None:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   680
            bugzilla._bug_re = re.compile(
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   681
                self.ui.config('bugzilla', 'regexp', bugzilla._default_bug_re),
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   682
                re.IGNORECASE)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   683
            bugzilla._split_re = re.compile(r'\D+')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   684
        start = 0
8455
a858b54d072b bugzilla: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8225
diff changeset
   685
        ids = set()
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   686
        while True:
3976
f8849648b0e2 bugzilla: use contexts, simplify
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3891
diff changeset
   687
            m = bugzilla._bug_re.search(ctx.description(), start)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   688
            if not m:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   689
                break
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   690
            start = m.end()
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   691
            for id in bugzilla._split_re.split(m.group(1)):
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   692
                if not id:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   693
                    continue
8455
a858b54d072b bugzilla: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8225
diff changeset
   694
                ids.add(int(id))
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   695
        if ids:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   696
            ids = self.filter_real_bug_ids(ids)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   697
        if ids:
13798
9c9fa78f4e2d bugzilla: rename filter_unknown_bug_ids to reflect its actual purpose.
Jim Hague <jim.hague@acm.org>
parents: 11567
diff changeset
   698
            ids = self.filter_cset_known_bug_ids(ctx.node(), ids)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   699
        return ids
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   700
3976
f8849648b0e2 bugzilla: use contexts, simplify
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3891
diff changeset
   701
    def update(self, bugid, ctx):
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   702
        '''update bugzilla bug with reference to changeset.'''
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   703
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   704
        def webroot(root):
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   705
            '''strip leading prefix of repo root and turn into
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   706
            url-safe path.'''
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   707
            count = int(self.ui.config('bugzilla', 'strip', 0))
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   708
            root = util.pconvert(root)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   709
            while count > 0:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   710
                c = root.find('/')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   711
                if c == -1:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   712
                    break
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   713
                root = root[c + 1:]
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   714
                count -= 1
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   715
            return root
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   716
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   717
        mapfile = self.ui.config('bugzilla', 'style')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   718
        tmpl = self.ui.config('bugzilla', 'template')
3741
0897bf8d54c7 update bugzilla extension to use ui buffers
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   719
        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: 7618
diff changeset
   720
                                        False, None, mapfile, False)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   721
        if not mapfile and not tmpl:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   722
            tmpl = _('changeset {node|short} in repo {root} refers '
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   723
                     'to bug {bug}.\ndetails:\n\t{desc|tabindent}')
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   724
        if tmpl:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   725
            tmpl = templater.parsestring(tmpl, quoted=False)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   726
            t.use_template(tmpl)
3741
0897bf8d54c7 update bugzilla extension to use ui buffers
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   727
        self.ui.pushbuffer()
7369
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7280
diff changeset
   728
        t.show(ctx, changes=ctx.changeset(),
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   729
               bug=str(bugid),
2197
5de8b44f0446 define standard name for base url to use when printing hgweb urls.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2192
diff changeset
   730
               hgweb=self.ui.config('web', 'baseurl'),
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   731
               root=self.repo.root,
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   732
               webroot=webroot(self.repo.root))
3741
0897bf8d54c7 update bugzilla extension to use ui buffers
Matt Mackall <mpm@selenic.com>
parents: 3643
diff changeset
   733
        data = self.ui.popbuffer()
5975
75d9fe70c654 templater: move email function to util
Matt Mackall <mpm@selenic.com>
parents: 4431
diff changeset
   734
        self.add_comment(bugid, data, util.email(ctx.user()))
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   735
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   736
def hook(ui, repo, hooktype, node=None, **kwargs):
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   737
    '''add comment to bugzilla for each changeset that refers to a
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   738
    bugzilla bug id. only add a comment once per bug, so same change
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   739
    seen multiple times does not fill bug with duplicate data.'''
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   740
    if node is None:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   741
        raise util.Abort(_('hook type %s does not pass a changeset id') %
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   742
                         hooktype)
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   743
    try:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   744
        bz = bugzilla(ui, repo)
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6548
diff changeset
   745
        ctx = repo[node]
3976
f8849648b0e2 bugzilla: use contexts, simplify
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3891
diff changeset
   746
        ids = bz.find_bug_ids(ctx)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   747
        if ids:
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   748
            for id in ids:
3976
f8849648b0e2 bugzilla: use contexts, simplify
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3891
diff changeset
   749
                bz.update(id, ctx)
7618
6c89dd0a7797 Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail.
Jim Hague <jim.hague@acm.org>
parents: 7504
diff changeset
   750
            bz.notify(ids, util.email(ctx.user()))
13800
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   751
    except Exception, e:
c2ef8159dabe bugzilla: localise all MySQL direct access inside access class.
Jim Hague <jim.hague@acm.org>
parents: 13799
diff changeset
   752
        raise util.Abort(_('Bugzilla error: %s') % e)
2192
2be3ac7abc21 add bugzilla integration hook. example of writing hook in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   753