hgext/bugzilla.py
changeset 7504 d8cd79fbed3c
parent 7493 518afef5e350
child 7618 6c89dd0a7797
equal deleted inserted replaced
7503:09508f8e2fa4 7504:d8cd79fbed3c
     2 #
     2 #
     3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
     3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
     4 #
     4 #
     5 # This software may be used and distributed according to the terms
     5 # This software may be used and distributed according to the terms
     6 # of the GNU General Public License, incorporated herein by reference.
     6 # of the GNU General Public License, incorporated herein by reference.
     7 #
     7 
     8 # hook extension to update comments of bugzilla bugs when changesets
     8 '''Bugzilla integration
     9 # that refer to bugs by id are seen.  this hook does not change bug
     9 
    10 # status, only comments.
    10 This hook extension adds comments on bugs in Bugzilla when changesets
    11 #
    11 that refer to bugs by Bugzilla ID are seen. The hook does not change bug
    12 # to configure, add items to '[bugzilla]' section of hgrc.
    12 status.
    13 #
    13 
    14 # to use, configure bugzilla extension and enable like this:
    14 The hook updates the Bugzilla database directly. Only Bugzilla installations
    15 #
    15 using MySQL are supported.
    16 #   [extensions]
    16 
    17 #   hgext.bugzilla =
    17 The hook relies on a Bugzilla script to send bug change notification emails.
    18 #
    18 That script changes between Bugzilla versions; the 'processmail' script used
    19 #   [hooks]
    19 prior to 2.18 is replaced in 2.18 and subsequent versions by
    20 #   # run bugzilla hook on every change pulled or pushed in here
    20 'config/sendbugmail.pl'. Note that these will be run by Mercurial as the user
    21 #   incoming.bugzilla = python:hgext.bugzilla.hook
    21 pushing the change; you will need to ensure the Bugzilla install file
    22 #
    22 permissions are set appropriately.
    23 # config items:
    23 
    24 #
    24 Configuring the extension:
    25 # section name is 'bugzilla'.
    25 
    26 #  [bugzilla]
    26     [bugzilla]
    27 #
    27     host       Hostname of the MySQL server holding the Bugzilla database.
    28 # REQUIRED:
    28     db         Name of the Bugzilla database in MySQL. Default 'bugs'.
    29 #   host = bugzilla # mysql server where bugzilla database lives
    29     user       Username to use to access MySQL server. Default 'bugs'.
    30 #   password = **   # user's password
    30     password   Password to use to access MySQL server.
    31 #   version = 2.16  # version of bugzilla installed
    31     timeout    Database connection timeout (seconds). Default 5.
    32 #
    32     version    Bugzilla version. Specify '3.0' for Bugzilla versions from
    33 # OPTIONAL:
    33                3.0 onwards, and '2.16' for versions prior to 3.0.
    34 #   bzuser = ...    # fallback bugzilla user name to record comments with
    34     bzuser     Fallback Bugzilla user name to record comments with, if
    35 #   db = bugs       # database to connect to
    35                changeset committer cannot be found as a Bugzilla user.
    36 #   notify = ...    # command to run to get bugzilla to send mail
    36     notify     The command to run to get Bugzilla to send bug change
    37 #   regexp = ...    # regexp to match bug ids (must contain one "()" group)
    37                notification emails. Substitutes one string parameter,
    38 #   strip = 0       # number of slashes to strip for url paths
    38                the bug ID. Default 'cd /var/www/html/bugzilla && '
    39 #   style = ...     # style file to use when formatting comments
    39                                    './processmail %s nobody@nowhere.com'.
    40 #   template = ...  # template to use when formatting comments
    40     regexp     Regular expression to match bug IDs in changeset commit message.
    41 #   timeout = 5     # database connection timeout (seconds)
    41                Must contain one "()" group. The default expression matches
    42 #   user = bugs     # user to connect to database as
    42                'Bug 1234', 'Bug no. 1234', 'Bug number 1234',
    43 #   [web]
    43                'Bugs 1234,5678', 'Bug 1234 and 5678' and variations thereof.
    44 #   baseurl = http://hgserver/... # root of hg web site for browsing commits
    44                Matching is case insensitive.
    45 #
    45     style      The style file to use when formatting comments.
    46 # if hg committer names are not same as bugzilla user names, use
    46     template   Template to use when formatting comments. Overrides
    47 # "usermap" feature to map from committer email to bugzilla user name.
    47                style if specified. In addition to the usual Mercurial
    48 # usermap can be in hgrc or separate config file.
    48                keywords, the extension specifies:
    49 #
    49                    {bug}       The Bugzilla bug ID.
    50 #   [bugzilla]
    50                    {root}      The full pathname of the Mercurial repository.
    51 #   usermap = filename # cfg file with "committer"="bugzilla user" info
    51                    {webroot}   Stripped pathname of the Mercurial repository.
    52 #   [usermap]
    52                    {hgweb}     Base URL for browsing Mercurial repositories.
    53 #   committer_email = bugzilla_user_name
    53                Default 'changeset {node|short} in repo {root} refers '
       
    54                        'to bug {bug}.\\ndetails:\\n\\t{desc|tabindent}'
       
    55     strip      The number of slashes to strip from the front of {root}
       
    56                to produce {webroot}. Default 0.
       
    57     usermap    Path of file containing Mercurial committer ID to Bugzilla user
       
    58                ID mappings. If specified, the file should contain one mapping
       
    59                per line, "committer"="Bugzilla user". See also the
       
    60                [usermap] section.
       
    61 
       
    62     [usermap]
       
    63     Any entries in this section specify mappings of Mercurial committer ID
       
    64     to Bugzilla user ID. See also [bugzilla].usermap.
       
    65     "committer"="Bugzilla user"
       
    66 
       
    67     [web]
       
    68     baseurl    Base URL for browsing Mercurial repositories. Reference from
       
    69                templates as {hgweb}.
       
    70 
       
    71 Activating the extension:
       
    72 
       
    73     [extensions]
       
    74     hgext.bugzilla =
       
    75 
       
    76     [hooks]
       
    77     # run bugzilla hook on every change pulled or pushed in here
       
    78     incoming.bugzilla = python:hgext.bugzilla.hook
       
    79 
       
    80 Example configuration:
       
    81 
       
    82 This example configuration is for a collection of Mercurial repositories
       
    83 in /var/local/hg/repos/ used with a local Bugzilla 3.2 installation in
       
    84 /opt/bugzilla-3.2.
       
    85 
       
    86     [bugzilla]
       
    87     host=localhost
       
    88     password=XYZZY
       
    89     version=3.0
       
    90     bzuser=unknown@domain.com
       
    91     notify=cd /opt/bugzilla-3.2 && perl -T contrib/sendbugmail.pl %%s bugmail@domain.com
       
    92     template=Changeset {node|short} in {root|basename}.\\n{hgweb}/{webroot}/rev/{node|short}\\n\\n{desc}\\n
       
    93     strip=5
       
    94 
       
    95     [web]
       
    96     baseurl=http://dev.domain.com/hg
       
    97 
       
    98     [usermap]
       
    99     user@emaildomain.com=user.name@bugzilladomain.com
       
   100 
       
   101 Commits add a comment to the Bugzilla bug record of the form:
       
   102 
       
   103     Changeset 3b16791d6642 in repository-name.
       
   104     http://dev.domain.com/hg/repository-name/rev/3b16791d6642
       
   105 
       
   106     Changeset commit comment. Bug 1234.
       
   107 '''
    54 
   108 
    55 from mercurial.i18n import _
   109 from mercurial.i18n import _
    56 from mercurial.node import short
   110 from mercurial.node import short
    57 from mercurial import cmdutil, templater, util
   111 from mercurial import cmdutil, templater, util
    58 import re, time
   112 import re, time