##// END OF EJS Templates
wrapfunction: use sysstr instead of bytes as argument in "bookflow"...
wrapfunction: use sysstr instead of bytes as argument in "bookflow" This is as valid and simpler, it will help us to eventually get ride of `safehasattr`.

File last commit:

r49801:642e31cb default
r51668:3c8a31be default
Show More
bugzilla.py
1251 lines | 41.5 KiB | text/x-python | PythonLexer
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 # bugzilla.py - bugzilla integration for mercurial
#
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
Jim Hague
bugzilla: support Bugzilla 4.4.3+ API login token authentication (issue4257)...
r21542 # Copyright 2011-4 Jim Hague <jim.hague@acm.org>
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 #
Martin Geisler
updated license to be explicit about GPL version 2
r8225 # This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
Dirkjan Ochtman
extensions: change descriptions for hook-providing extensions...
r8935 '''hooks for integrating with the Bugzilla bug tracker
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
Martin Geisler
bugzilla: wrap docstrings at 70 characters
r9252 This hook extension adds comments on bugs in Bugzilla when changesets
Jim Hague
bugzilla: add XMLRPC interface....
r13801 that refer to bugs by Bugzilla ID are seen. The comment is formatted using
the Mercurial template mechanism.
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 The bug references can optionally include an update for Bugzilla of the
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 hours spent working on the bug. Bugs can also be marked fixed.
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 Four basic modes of access to Bugzilla are provided:
1. Access via the Bugzilla REST-API. Requires bugzilla 5.0 or later.
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 2. Access via the Bugzilla XMLRPC interface. Requires Bugzilla 3.4 or later.
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 3. Check data via the Bugzilla XMLRPC interface and submit bug change
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 via email to Bugzilla email interface. Requires Bugzilla 3.4 or later.
Martin Geisler
bugzilla: reformat list of configuration options
r9203
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 4. Writing directly to the Bugzilla database. Only Bugzilla installations
Jim Hague
bugzilla: add XMLRPC interface....
r13801 using MySQL are supported. Requires Python MySQLdb.
Martin Geisler
bugzilla: reformat list of configuration options
r9203
Jim Hague
bugzilla: add XMLRPC interface....
r13801 Writing directly to the database is susceptible to schema changes, and
relies on a Bugzilla contrib script to send out bug change
notification emails. This script runs as the user running Mercurial,
must be run on the host with the Bugzilla install, and requires
permission to read Bugzilla configuration details and the necessary
MySQL user and password to have full access rights to the Bugzilla
database. For these reasons this access mode is now considered
deprecated, and will not be updated for new Bugzilla versions going
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 forward. Only adding comments is supported in this access mode.
Martin Geisler
bugzilla: reformat list of configuration options
r9203
Jim Hague
bugzilla: add XMLRPC interface....
r13801 Access via XMLRPC needs a Bugzilla username and password to be specified
in the configuration. Comments are added under that username. Since the
configuration must be readable by all Mercurial users, it is recommended
that the rights of that user are restricted in Bugzilla to the minimum
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 necessary to add comments. Marking bugs fixed requires Bugzilla 4.0 and later.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Jim Hague
bugzilla: more documentation fixes...
r13871 Access via XMLRPC/email uses XMLRPC to query Bugzilla, but sends
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 email to the Bugzilla email interface to submit comments to bugs.
The From: address in the email is set to the email address of the Mercurial
user, so the comment appears to come from the Mercurial user. In the event
timeless@mozdev.org
en-us: recognized
r17534 that the Mercurial user email is not recognized by Bugzilla as a Bugzilla
Jim Hague
bugzilla: more documentation fixes...
r13871 user, the email associated with the Bugzilla username used to log into
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 Bugzilla is used instead as the source of the comment. Marking bugs fixed
works on all supported Bugzilla versions.
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 Access via the REST-API needs either a Bugzilla username and password
or an apikey specified in the configuration. Comments are made under
Wagner Bruna
bugzilla: fix typo in help text
r32602 the given username or the user associated with the apikey in Bugzilla.
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 Configuration items common to all access modes:
Martin Geisler
bugzilla: reformat list of configuration options
r9203
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.version
Bryan O'Sullivan
Merge spelling fixes
r17537 The access type to use. Values recognized are:
Jim Hague
bugzilla: more documentation fixes...
r13871
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 :``restapi``: Bugzilla REST-API, Bugzilla 5.0 and later.
Martin Geisler
bugzilla: fix reST error introduced in 22d200e49b10...
r13883 :``xmlrpc``: Bugzilla XMLRPC interface.
:``xmlrpc+email``: Bugzilla XMLRPC and email interfaces.
:``3.0``: MySQL access, Bugzilla 3.0 and later.
:``2.18``: MySQL access, Bugzilla 2.18 and up to but not
including 3.0.
:``2.16``: MySQL access, Bugzilla 2.16 and up to but not
including 2.18.
Martin Geisler
bugzilla: word-wrap help texts at 70 characters
r7985
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.regexp
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 Regular expression to match bug IDs for update in changeset commit message.
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 It must contain one "()" named group ``<ids>`` containing the bug
IDs separated by non-digit characters. It may also contain
a named group ``<hours>`` with a floating-point number giving the
hours worked on the bug. If no named groups are present, the first
"()" group is assumed to contain the bug IDs, and work time is not
updated. The default expression matches ``Bug 1234``, ``Bug no. 1234``,
``Bug number 1234``, ``Bugs 1234,5678``, ``Bug 1234 and 5678`` and
variations thereof, followed by an hours number prefixed by ``h`` or
``hours``, e.g. ``hours 1.5``. Matching is case insensitive.
Martin Geisler
bugzilla: reformat list of configuration options
r9203
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 bugzilla.fixregexp
Regular expression to match bug IDs for marking fixed in changeset
commit message. This must contain a "()" named group ``<ids>` containing
the bug IDs separated by non-digit characters. It may also contain
a named group ``<hours>`` with a floating-point number giving the
hours worked on the bug. If no named groups are present, the first
"()" group is assumed to contain the bug IDs, and work time is not
updated. The default expression matches ``Fixes 1234``, ``Fixes bug 1234``,
``Fixes bugs 1234,5678``, ``Fixes 1234 and 5678`` and
variations thereof, followed by an hours number prefixed by ``h`` or
``hours``, e.g. ``hours 1.5``. Matching is case insensitive.
bugzilla.fixstatus
The status to set a bug to when marking fixed. Default ``RESOLVED``.
bugzilla.fixresolution
The resolution to set a bug to when marking fixed. Default ``FIXED``.
Martin Geisler
bugzilla: reformat list of configuration options
r9203
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.style
Martin Geisler
bugzilla: reformat list of configuration options
r9203 The style file to use when formatting comments.
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.template
Martin Geisler
bugzilla: wrap docstrings at 70 characters
r9252 Template to use when formatting comments. Overrides style if
specified. In addition to the usual Mercurial keywords, the
Martin Geisler
bugzilla: convert a verbatim block to a field list
r13884 extension specifies:
Martin Geisler
bugzilla: reformat list of configuration options
r9203
Martin Geisler
bugzilla: convert a verbatim block to a field list
r13884 :``{bug}``: The Bugzilla bug ID.
:``{root}``: The full pathname of the Mercurial repository.
:``{webroot}``: Stripped pathname of the Mercurial repository.
:``{hgweb}``: Base URL for browsing Mercurial repositories.
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
Martin Geisler
bugzilla: fix bad reST markup...
r13842 Default ``changeset {node|short} in repo {root} refers to bug
{bug}.\\ndetails:\\n\\t{desc|tabindent}``
Martin Geisler
bugzilla: reformat list of configuration options
r9203
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.strip
Martin Geisler
bugzilla: markup literal text as such
r13841 The number of path separator characters to strip from the front of
the Mercurial repository path (``{root}`` in templates) to produce
``{webroot}``. For example, a repository with ``{root}``
``/var/local/my-project`` with a strip of 2 gives a value for
``{webroot}`` of ``my-project``. Default 0.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Martin Geisler
bugzilla: prefix each config option with section
r13833 web.baseurl
Jim Hague
bugzilla: add XMLRPC interface....
r13801 Base URL for browsing Mercurial repositories. Referenced from
Jim Hague
bugzilla: more documentation formatting fixups...
r13896 templates as ``{hgweb}``.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 Configuration items common to XMLRPC+email and MySQL access modes:
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.usermap
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 Path of file containing Mercurial committer email to Bugzilla user email
mappings. If specified, the file should contain one mapping per
Martin Geisler
bugzilla: show usermap syntax more clearly
r13835 line::
committer = Bugzilla user
Jim Hague
bugzilla: more documentation formatting fixups...
r13896 See also the ``[usermap]`` section.
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
Martin Geisler
bugzilla: markup section names as literal text
r13836 The ``[usermap]`` section is used to specify mappings of Mercurial
Martin Geisler
bugzilla: use standard section.name notation
r13834 committer email to Bugzilla user email. See also ``bugzilla.usermap``.
Martin Geisler
bugzilla: show usermap syntax more clearly
r13835 Contains entries of the form ``committer = Bugzilla user``.
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 XMLRPC and REST-API access mode configuration:
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.bzurl
Jim Hague
bugzilla: add XMLRPC interface....
r13801 The base URL for the Bugzilla installation.
Martin Geisler
bugzilla: markup literal text as such
r13841 Default ``http://localhost/bugzilla``.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.user
Martin Geisler
bugzilla: markup literal text as such
r13841 The username to use to log into Bugzilla via XMLRPC. Default
``bugs``.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.password
Jim Hague
bugzilla: add XMLRPC interface....
r13801 The password for Bugzilla login.
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 REST-API access mode uses the options listed above as well as:
bugzilla.apikey
An apikey generated on the Bugzilla instance for api access.
Using an apikey removes the need to store the user and password
options.
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 XMLRPC+email access mode uses the XMLRPC access mode configuration items,
and also:
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.bzemail
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 The Bugzilla email address.
In addition, the Mercurial email settings must be configured. See the
Martin Geisler
bugzilla: refer to hgrc(5) man page with normal notation
r13837 documentation in hgrc(5), sections ``[email]`` and ``[smtp]``.
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
Jim Hague
bugzilla: add XMLRPC interface....
r13801 MySQL access mode configuration:
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.host
Jim Hague
bugzilla: add XMLRPC interface....
r13801 Hostname of the MySQL server holding the Bugzilla database.
Martin Geisler
bugzilla: markup literal text as such
r13841 Default ``localhost``.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.db
Martin Geisler
bugzilla: markup literal text as such
r13841 Name of the Bugzilla database in MySQL. Default ``bugs``.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.user
Martin Geisler
bugzilla: markup literal text as such
r13841 Username to use to access MySQL server. Default ``bugs``.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.password
Jim Hague
bugzilla: add XMLRPC interface....
r13801 Password to use to access MySQL server.
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.timeout
Jim Hague
bugzilla: add XMLRPC interface....
r13801 Database connection timeout (seconds). Default 5.
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.bzuser
Jim Hague
bugzilla: add XMLRPC interface....
r13801 Fallback Bugzilla user name to record comments with, if changeset
committer cannot be found as a Bugzilla user.
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.bzdir
Jim Hague
bugzilla: add XMLRPC interface....
r13801 Bugzilla install directory. Used by default notify. Default
Martin Geisler
bugzilla: markup literal text as such
r13841 ``/var/www/html/bugzilla``.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Martin Geisler
bugzilla: prefix each config option with section
r13833 bugzilla.notify
Jim Hague
bugzilla: add XMLRPC interface....
r13801 The command to run to get Bugzilla to send bug change notification
Martin Geisler
bugzilla: markup literal text as such
r13841 emails. Substitutes from a map with 3 keys, ``bzdir``, ``id`` (bug
id) and ``user`` (committer bugzilla email). Default depends on
version; from 2.18 it is "cd %(bzdir)s && perl -T
contrib/sendbugmail.pl %(id)s %(user)s".
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
Martin Geisler
bugzilla: reformat list of configuration options
r9203 Activating the extension::
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
[extensions]
Martin Geisler
hgext: enable extensions without "hgext." prefix in help texts
r10112 bugzilla =
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
[hooks]
# run bugzilla hook on every change pulled or pushed in here
incoming.bugzilla = python:hgext.bugzilla.hook
Jim Hague
bugzilla: add XMLRPC interface....
r13801 Example configurations:
XMLRPC example configuration. This uses the Bugzilla at
Martin Geisler
bugzilla: markup literal text as such
r13841 ``http://my-project.org/bugzilla``, logging in as user
``bugmail@my-project.org`` with password ``plugh``. It is used with a
Jim Hague
bugzilla: correct sample configurations...
r13870 collection of Mercurial repositories in ``/var/local/hg/repos/``,
with a web interface at ``http://my-project.org/hg``. ::
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
Jim Hague
bugzilla: add XMLRPC interface....
r13801 [bugzilla]
bzurl=http://my-project.org/bugzilla
user=bugmail@my-project.org
password=plugh
version=xmlrpc
Jim Hague
bugzilla: correct sample configurations...
r13870 template=Changeset {node|short} in {root|basename}.
{hgweb}/{webroot}/rev/{node|short}\\n
{desc}\\n
strip=5
Jim Hague
bugzilla: add XMLRPC interface....
r13801
[web]
baseurl=http://my-project.org/hg
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 XMLRPC+email example configuration. This uses the Bugzilla at
Martin Geisler
bugzilla: markup literal text as such
r13841 ``http://my-project.org/bugzilla``, logging in as user
Wagner Bruna
bugzilla: fix typo in documentation
r14619 ``bugmail@my-project.org`` with password ``plugh``. It is used with a
Jim Hague
bugzilla: correct sample configurations...
r13870 collection of Mercurial repositories in ``/var/local/hg/repos/``,
with a web interface at ``http://my-project.org/hg``. Bug comments
are sent to the Bugzilla email address
Patrick Mezard
bugzilla: fix documentation typo
r13854 ``bugzilla@my-project.org``. ::
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
[bugzilla]
Jim Hague
bugzilla: correct sample configurations...
r13870 bzurl=http://my-project.org/bugzilla
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 user=bugmail@my-project.org
password=plugh
Jim Hague
bugzilla: correct config documentation error...
r21842 version=xmlrpc+email
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 bzemail=bugzilla@my-project.org
Jim Hague
bugzilla: correct sample configurations...
r13870 template=Changeset {node|short} in {root|basename}.
{hgweb}/{webroot}/rev/{node|short}\\n
{desc}\\n
strip=5
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
[web]
Jim Hague
bugzilla: correct sample configurations...
r13870 baseurl=http://my-project.org/hg
[usermap]
user@emaildomain.com=user.name@bugzilladomain.com
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
Jim Hague
bugzilla: correct sample configurations...
r13870 MySQL example configuration. This has a local Bugzilla 3.2 installation
in ``/opt/bugzilla-3.2``. The MySQL database is on ``localhost``,
the Bugzilla database name is ``bugs`` and MySQL is
accessed with MySQL username ``bugs`` password ``XYZZY``. It is used
with a collection of Mercurial repositories in ``/var/local/hg/repos/``,
with a web interface at ``http://my-project.org/hg``. ::
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
[bugzilla]
host=localhost
password=XYZZY
version=3.0
bzuser=unknown@domain.com
Jim Hague
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail....
r7618 bzdir=/opt/bugzilla-3.2
Martin Geisler
bugzilla: wrap example template line
r9204 template=Changeset {node|short} in {root|basename}.
{hgweb}/{webroot}/rev/{node|short}\\n
{desc}\\n
Jim Hague
Revise Bugzilla module comments into extension help....
r7504 strip=5
[web]
Jim Hague
bugzilla: correct sample configurations...
r13870 baseurl=http://my-project.org/hg
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
[usermap]
user@emaildomain.com=user.name@bugzilladomain.com
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 All the above add a comment to the Bugzilla bug record of the form::
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
Changeset 3b16791d6642 in repository-name.
Jim Hague
bugzilla: correct sample configurations...
r13870 http://my-project.org/hg/repository-name/rev/3b16791d6642
Jim Hague
Revise Bugzilla module comments into extension help....
r7504
Changeset commit comment. Bug 1234.
'''
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
Gregory Szorc
bugzilla: use absolute_import
r28091
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 import json
Gregory Szorc
bugzilla: use absolute_import
r28091 import re
import time
Matt Mackall
Simplify i18n imports
r3891 from mercurial.i18n import _
Joel Rosdahl
Expand import * to allow Pyflakes to find problems
r6211 from mercurial.node import short
Gregory Szorc
bugzilla: use absolute_import
r28091 from mercurial import (
error,
Yuya Nishihara
cmdutil: drop aliases for logcmdutil functions (API)...
r35906 logcmdutil,
Gregory Szorc
bugzilla: use absolute_import
r28091 mail,
Augie Fackler
py3: port test-bugzilla.t to Python 3...
r41379 pycompat,
Boris Feld
configitems: register the 'bugzilla.apikey' config
r33393 registrar,
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 url,
Gregory Szorc
bugzilla: use absolute_import
r28091 util,
)
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 from mercurial.utils import (
Yuya Nishihara
procutil: bulk-replace function calls to point to new module
r37138 procutil,
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 stringutil,
)
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
Pulkit Goyal
py3: conditionalize xmlrpclib import...
r29432 xmlrpclib = util.xmlrpclib
Pulkit Goyal
py3: conditionalize the urlparse import...
r29431
Augie Fackler
extensions: change magic "shipped with hg" string...
r29841 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
Augie Fackler
extensions: document that `testedwith = 'internal'` is special...
r25186 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
# leave the attribute unspecified.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 testedwith = b'ships-with-hg-core'
Augie Fackler
hgext: mark all first-party extensions as such
r16743
Boris Feld
configitems: register the 'bugzilla.apikey' config
r33393 configtable = {}
configitem = registrar.configitem(configtable)
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'apikey',
default=b'',
Boris Feld
configitems: register the 'bugzilla.apikey' config
r33393 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'bzdir',
default=b'/var/www/html/bugzilla',
Augie Fackler
formatting: blacken the codebase...
r43346 )
configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'bzemail',
default=None,
Boris Feld
configitems: register the 'bugzilla.bzdir' config
r33394 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'bzurl',
default=b'http://localhost/bugzilla/',
Boris Feld
configitems: register the 'bugzilla.bzemail' config
r33395 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'bzuser',
default=None,
Boris Feld
configitems: register the 'bugzilla.bzurl' config
r33396 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'db',
default=b'bugs',
Boris Feld
configitems: register the 'bugzilla.bzuser' config
r33397 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'bugzilla',
b'fixregexp',
Augie Fackler
formatting: blacken the codebase...
r43346 default=(
br'fix(?:es)?\s*(?:bugs?\s*)?,?\s*'
br'(?:nos?\.?|num(?:ber)?s?)?\s*'
br'(?P<ids>(?:#?\d+\s*(?:,?\s*(?:and)?)?\s*)+)'
br'\.?\s*(?:h(?:ours?)?\s*(?P<hours>\d*(?:\.\d+)?))?'
),
Boris Feld
configitems: register the 'bugzilla.fixregexp' config
r33399 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'fixresolution',
default=b'FIXED',
Boris Feld
configitems: register the 'bugzilla.fixresolution' config
r33400 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'fixstatus',
default=b'RESOLVED',
Boris Feld
configitems: register the 'bugzilla.fixstatus' config
r33401 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'host',
default=b'localhost',
Boris Feld
configitems: register the 'bugzilla.host' config
r33402 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'notify',
default=configitem.dynamicdefault,
Boris Feld
configitems: register the 'bugzilla.notify' config
r33524 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'password',
default=None,
Boris Feld
configitems: register the 'bugzilla.password' config
r33433 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'bugzilla',
b'regexp',
Augie Fackler
formatting: blacken the codebase...
r43346 default=(
br'bugs?\s*,?\s*(?:#|nos?\.?|num(?:ber)?s?)?\s*'
br'(?P<ids>(?:\d+\s*(?:,?\s*(?:and)?)?\s*)+)'
br'\.?\s*(?:h(?:ours?)?\s*(?P<hours>\d*(?:\.\d+)?))?'
),
Boris Feld
configitems: register the 'bugzilla.regexp' config...
r33462 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'strip',
default=0,
Boris Feld
configitems: register the 'bugzilla.strip' config
r33463 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'style',
default=None,
Boris Feld
configitems: register the 'bugzilla.style' config
r33464 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'template',
default=None,
Boris Feld
configitems: register the 'bugzilla.template' config
r33465 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'timeout',
default=5,
Boris Feld
configitems: register the 'bugzilla.timeout' config
r33466 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'user',
default=b'bugs',
Boris Feld
configitems: register the 'bugzilla.user' config
r33467 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'usermap',
default=None,
Boris Feld
configitems: register the 'bugzilla.usermap' config
r33468 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 b'bugzilla',
b'version',
default=None,
Boris Feld
configitems: register the 'bugzilla.version' config
r33469 )
Boris Feld
configitems: register the 'bugzilla.apikey' config
r33393
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class bzaccess:
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800 '''Base class for access to Bugzilla.'''
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
def __init__(self, ui):
self.ui = ui
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 usermap = self.ui.config(b'bugzilla', b'usermap')
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800 if usermap:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.readconfig(usermap, sections=[b'usermap'])
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800
def map_committer(self, user):
'''map name of committer to Bugzilla user name.'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for committer, bzuser in self.ui.configitems(b'usermap'):
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800 if committer.lower() == user.lower():
return bzuser
return user
# Methods to be implemented by access classes.
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 #
# 'bugs' is a dict keyed on bug id, where values are a dict holding
timeless@mozdev.org
en-us: recognized
r17534 # updates to bug state. Recognized dict keys are:
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 #
# 'hours': Value, float containing work hours to be updated.
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 # 'fix': If key present, bug is to be marked fixed. Value ignored.
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def filter_real_bug_ids(self, bugs):
'''remove bug IDs that do not exist in Bugzilla from bugs.'''
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def filter_cset_known_bug_ids(self, node, bugs):
'''remove bug IDs where node occurs in comment text from bugs.'''
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def updatebug(self, bugid, newstate, text, committer):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """update the specified bug. Add comment text and set new states.
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800
If possible add the comment as being from the committer of
the changeset. Otherwise use the default Bugzilla user.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def notify(self, bugs, committer):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Force sending of Bugzilla notification emails.
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221
Only required if the access method does not trigger notification
emails automatically.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800
Augie Fackler
formatting: blacken the codebase...
r43346
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800 # Bugzilla via direct access to MySQL database.
class bzmysql(bzaccess):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Support for direct MySQL access to Bugzilla.
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800
The earliest Bugzilla version this is tested with is version 2.16.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Jim Hague
bugzilla: correct comment typo
r16226 If your Bugzilla is version 3.4 or above, you are strongly
Jim Hague
bugzilla: add XMLRPC interface....
r13801 recommended to use the XMLRPC access method instead.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800
@staticmethod
def sql_buglist(ids):
'''return SQL-friendly list of bug ids'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'(' + b','.join(map(str, ids)) + b')'
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800
_MySQLdb = None
def __init__(self, ui):
try:
import MySQLdb as mysql
Augie Fackler
formatting: blacken the codebase...
r43346
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800 bzmysql._MySQLdb = mysql
Gregory Szorc
global: mass rewrite to use modern exception syntax...
r25660 except ImportError as err:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(
_(b'python mysql support not available: %s') % err
)
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800
bzaccess.__init__(self, ui)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 host = self.ui.config(b'bugzilla', b'host')
user = self.ui.config(b'bugzilla', b'user')
passwd = self.ui.config(b'bugzilla', b'password')
db = self.ui.config(b'bugzilla', b'db')
timeout = int(self.ui.config(b'bugzilla', b'timeout'))
Augie Fackler
formatting: blacken the codebase...
r43346 self.ui.note(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'connecting to %s:%s as %s, password %s\n')
% (host, db, user, b'*' * len(passwd))
Augie Fackler
formatting: blacken the codebase...
r43346 )
self.conn = bzmysql._MySQLdb.connect(
host=host, user=user, passwd=passwd, db=db, connect_timeout=timeout
)
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 self.cursor = self.conn.cursor()
Jim Hague
Add support for Bugzilla 3.0 series to bugzilla hook....
r7019 self.longdesc_id = self.get_longdesc_id()
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 self.user_ids = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.default_notify = b"cd %(bzdir)s && ./processmail %(id)s %(user)s"
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
def run(self, *args, **kwargs):
'''run a query.'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.note(_(b'query: %s %s\n') % (args, kwargs))
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 try:
self.cursor.execute(*args, **kwargs)
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800 except bzmysql._MySQLdb.MySQLError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.note(_(b'failed query: %s %s\n') % (args, kwargs))
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 raise
Jim Hague
Add support for Bugzilla 3.0 series to bugzilla hook....
r7019 def get_longdesc_id(self):
'''get identity of longdesc field'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.run(b'select fieldid from fielddefs where name = "longdesc"')
Jim Hague
Add support for Bugzilla 3.0 series to bugzilla hook....
r7019 ids = self.cursor.fetchall()
if len(ids) != 1:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'unknown database schema'))
Jim Hague
Add support for Bugzilla 3.0 series to bugzilla hook....
r7019 return ids[0][0]
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def filter_real_bug_ids(self, bugs):
'''filter not-existing bugs from set.'''
Augie Fackler
formatting: blacken the codebase...
r43346 self.run(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'select bug_id from bugs where bug_id in %s'
Augie Fackler
formatting: blacken the codebase...
r43346 % bzmysql.sql_buglist(bugs.keys())
)
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 existing = [id for (id,) in self.cursor.fetchall()]
for id in bugs.keys():
if id not in existing:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.status(_(b'bug %d does not exist\n') % id)
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 del bugs[id]
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def filter_cset_known_bug_ids(self, node, bugs):
Jim Hague
bugzilla: keep bug IDs in set....
r13799 '''filter bug ids that already refer to this changeset from set.'''
Augie Fackler
formatting: blacken the codebase...
r43346 self.run(
'''select bug_id from longdescs where
bug_id in %s and thetext like "%%%s%%"'''
% (bzmysql.sql_buglist(bugs.keys()), short(node))
)
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 for (id,) in self.cursor.fetchall():
Augie Fackler
formatting: blacken the codebase...
r43346 self.ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'bug %d already knows about changeset %s\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % (id, short(node))
)
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 del bugs[id]
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def notify(self, bugs, committer):
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 '''tell bugzilla to send mail.'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.status(_(b'telling bugzilla to send mail:\n'))
Jim Hague
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail....
r7618 (user, userid) = self.get_bugzilla_user(committer)
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 for id in bugs.keys():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.status(_(b' bug %s\n') % id)
cmdfmt = self.ui.config(b'bugzilla', b'notify', self.default_notify)
bzdir = self.ui.config(b'bugzilla', b'bzdir')
Jim Hague
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail....
r7618 try:
# Backwards-compatible with old notify string, which
# took one string. This will throw with a new format
# string.
cmd = cmdfmt % id
except TypeError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cmd = cmdfmt % {b'bzdir': bzdir, b'id': id, b'user': user}
self.ui.note(_(b'running notify command %s\n') % cmd)
fp = procutil.popen(b'(%s) 2>&1' % cmd, b'rb')
Yuya Nishihara
procutil: always popen() in binary mode...
r37476 out = util.fromnativeeol(fp.read())
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 ret = fp.close()
if ret:
self.ui.warn(out)
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'bugzilla notify command %s') % procutil.explainexit(ret)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.status(_(b'done\n'))
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
def get_user_id(self, user):
'''look up numeric bugzilla user id.'''
try:
return self.user_ids[user]
except KeyError:
try:
userid = int(user)
except ValueError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.note(_(b'looking up user %s\n') % user)
Augie Fackler
formatting: blacken the codebase...
r43346 self.run(
'''select userid from profiles
where login_name like %s''',
user,
)
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 all = self.cursor.fetchall()
if len(all) != 1:
raise KeyError(user)
userid = int(all[0][0])
self.user_ids[user] = userid
return userid
Jim Hague
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail....
r7618 def get_bugzilla_user(self, committer):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """See if committer is a registered bugzilla user. Return
Jim Hague
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail....
r7618 bugzilla username and userid if so. If not, return default
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 bugzilla username and userid."""
Vadim Gelfer
bugzilla: allow to map between committer email and bugzilla user name.
r2306 user = self.map_committer(committer)
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 try:
Vadim Gelfer
bugzilla: allow to map between committer email and bugzilla user name.
r2306 userid = self.get_user_id(user)
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 except KeyError:
try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 defaultuser = self.ui.config(b'bugzilla', b'bzuser')
Vadim Gelfer
bugzilla: allow to map between committer email and bugzilla user name.
r2306 if not defaultuser:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'cannot find bugzilla user id for %s') % user
Augie Fackler
formatting: blacken the codebase...
r43346 )
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 userid = self.get_user_id(defaultuser)
Jim Hague
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail....
r7618 user = defaultuser
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 except KeyError:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'cannot find bugzilla user id for %s or %s')
Augie Fackler
formatting: blacken the codebase...
r43346 % (user, defaultuser)
)
Jim Hague
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail....
r7618 return (user, userid)
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def updatebug(self, bugid, newstate, text, committer):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """update bug state with comment text.
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221
Try adding comment as committer of changeset, otherwise as
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 default bugzilla user."""
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 if len(newstate) > 0:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.warn(_(b"Bugzilla/MySQL cannot update bug state\n"))
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222
Jim Hague
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail....
r7618 (user, userid) = self.get_bugzilla_user(committer)
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 now = time.strftime('%Y-%m-%d %H:%M:%S')
Augie Fackler
formatting: blacken the codebase...
r43346 self.run(
'''insert into longdescs
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 (bug_id, who, bug_when, thetext)
values (%s, %s, %s, %s)''',
Augie Fackler
formatting: blacken the codebase...
r43346 (bugid, userid, now, text),
)
self.run(
'''insert into bugs_activity (bug_id, who, bug_when, fieldid)
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 values (%s, %s, %s, %s)''',
Augie Fackler
formatting: blacken the codebase...
r43346 (bugid, userid, now, self.longdesc_id),
)
Jim Hague
Fix Bugzilla integration to work with new Bugzilla 3.2....
r7493 self.conn.commit()
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
Augie Fackler
formatting: blacken the codebase...
r43346
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800 class bzmysql_2_18(bzmysql):
Jim Hague
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail....
r7618 '''support for bugzilla 2.18 series.'''
def __init__(self, ui):
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800 bzmysql.__init__(self, ui)
Augie Fackler
cleanup: use () to wrap long lines instead of \...
r41925 self.default_notify = (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"cd %(bzdir)s && perl -T contrib/sendbugmail.pl %(id)s %(user)s"
Augie Fackler
formatting: blacken the codebase...
r43346 )
Jim Hague
Bugzilla 2.18 and on use contrib/sendbugmail.pl, not processmail....
r7618
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800 class bzmysql_3_0(bzmysql_2_18):
Jim Hague
Add support for Bugzilla 3.0 series to bugzilla hook....
r7019 '''support for bugzilla 3.0 series.'''
def __init__(self, ui):
Jim Hague
bugzilla: localise all MySQL direct access inside access class....
r13800 bzmysql_2_18.__init__(self, ui)
Jim Hague
Add support for Bugzilla 3.0 series to bugzilla hook....
r7019
def get_longdesc_id(self):
'''get identity of longdesc field'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.run(b'select id from fielddefs where name = "longdesc"')
Jim Hague
Add support for Bugzilla 3.0 series to bugzilla hook....
r7019 ids = self.cursor.fetchall()
if len(ids) != 1:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'unknown database schema'))
Jim Hague
Add support for Bugzilla 3.0 series to bugzilla hook....
r7019 return ids[0][0]
Augie Fackler
formatting: blacken the codebase...
r43346
Mads Kiilerich
fix trivial spelling errors
r17424 # Bugzilla via XMLRPC interface.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class cookietransportrequest:
Jim Hague
bugzilla: make XMLRPC interface support http and https access...
r15870 """A Transport request method that retains cookies over its lifetime.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
The regular xmlrpclib transports ignore cookies. Which causes
a bit of a problem when you need a cookie-based login, as with
Jim Hague
bugzilla: support Bugzilla 4.4.3+ API login token authentication (issue4257)...
r21542 the Bugzilla XMLRPC interface prior to 4.4.3.
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Jim Hague
bugzilla: make XMLRPC interface support http and https access...
r15870 So this is a helper for defining a Transport which looks for
cookies being set in responses and saves them to add to all future
requests.
Jim Hague
bugzilla: add XMLRPC interface....
r13801 """
# Inspiration drawn from
# http://blog.godson.in/2010/09/how-to-make-python-xmlrpclib-client.html
# http://www.itkovian.net/base/transport-class-for-pythons-xml-rpc-lib/
cookies = []
Augie Fackler
formatting: blacken the codebase...
r43346
Jim Hague
bugzilla: add XMLRPC interface....
r13801 def send_cookies(self, connection):
if self.cookies:
for cookie in self.cookies:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 connection.putheader(b"Cookie", cookie)
Jim Hague
bugzilla: add XMLRPC interface....
r13801
def request(self, host, handler, request_body, verbose=0):
self.verbose = verbose
Jim Hague
bugzilla: stop XMLRPC requests from requesting gzipped responses...
r16193 self.accept_gzip_encoding = False
Jim Hague
bugzilla: add XMLRPC interface....
r13801
# issue XML-RPC request
h = self.make_connection(host)
if verbose:
h.set_debuglevel(1)
self.send_request(h, handler, request_body)
self.send_host(h, host)
self.send_cookies(h)
self.send_user_agent(h)
self.send_content(h, request_body)
Augie Fackler
bugzilla: stop mentioning Pythons older than 2.6...
r30478 # Deal with differences between Python 2.6 and 2.7.
Jim Hague
bugzilla: add XMLRPC interface....
r13801 # In the former h is a HTTP(S). In the latter it's a
Augie Fackler
bugzilla: stop mentioning Pythons older than 2.6...
r30478 # HTTP(S)Connection. Luckily, the 2.6 implementation of
Jim Hague
bugzilla: add XMLRPC interface....
r13801 # HTTP(S) has an underlying HTTP(S)Connection, so extract
# that and use it.
try:
response = h.getresponse()
except AttributeError:
response = h._conn.getresponse()
# Add any cookie definitions to our list.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for header in response.msg.getallmatchingheaders(b"Set-Cookie"):
val = header.split(b": ", 1)[1]
cookie = val.split(b";", 1)[0]
Jim Hague
bugzilla: add XMLRPC interface....
r13801 self.cookies.append(cookie)
if response.status != 200:
Augie Fackler
formatting: blacken the codebase...
r43346 raise xmlrpclib.ProtocolError(
host + handler,
response.status,
response.reason,
response.msg.headers,
)
Jim Hague
bugzilla: add XMLRPC interface....
r13801
payload = response.read()
parser, unmarshaller = self.getparser()
parser.feed(payload)
parser.close()
return unmarshaller.close()
Augie Fackler
formatting: blacken the codebase...
r43346
Jim Hague
bugzilla: make XMLRPC interface support http and https access...
r15870 # The explicit calls to the underlying xmlrpclib __init__() methods are
# necessary. The xmlrpclib.Transport classes are old-style classes, and
# it turns out their __init__() doesn't get called when doing multiple
# inheritance with a new-style class.
class cookietransport(cookietransportrequest, xmlrpclib.Transport):
def __init__(self, use_datetime=0):
Martin von Zweigbergk
py3: delete b'' prefix from safehasattr arguments...
r43385 if util.safehasattr(xmlrpclib.Transport, "__init__"):
Steven Stallion
bugzilla: fix transport initialization on python 2.4
r16649 xmlrpclib.Transport.__init__(self, use_datetime)
Jim Hague
bugzilla: make XMLRPC interface support http and https access...
r15870
Augie Fackler
formatting: blacken the codebase...
r43346
Jim Hague
bugzilla: make XMLRPC interface support http and https access...
r15870 class cookiesafetransport(cookietransportrequest, xmlrpclib.SafeTransport):
def __init__(self, use_datetime=0):
Martin von Zweigbergk
py3: delete b'' prefix from safehasattr arguments...
r43385 if util.safehasattr(xmlrpclib.Transport, "__init__"):
Steven Stallion
bugzilla: fix transport initialization on python 2.4
r16649 xmlrpclib.SafeTransport.__init__(self, use_datetime)
Jim Hague
bugzilla: make XMLRPC interface support http and https access...
r15870
Augie Fackler
formatting: blacken the codebase...
r43346
Jim Hague
bugzilla: add XMLRPC interface....
r13801 class bzxmlrpc(bzaccess):
"""Support for access to Bugzilla via the Bugzilla XMLRPC API.
Requires a minimum Bugzilla version 3.4.
"""
def __init__(self, ui):
bzaccess.__init__(self, ui)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 bzweb = self.ui.config(b'bugzilla', b'bzurl')
bzweb = bzweb.rstrip(b"/") + b"/xmlrpc.cgi"
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 user = self.ui.config(b'bugzilla', b'user')
passwd = self.ui.config(b'bugzilla', b'password')
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.fixstatus = self.ui.config(b'bugzilla', b'fixstatus')
self.fixresolution = self.ui.config(b'bugzilla', b'fixresolution')
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223
Mads Kiilerich
bugzilla: pass the url to xmlrpclib.ServerProxy as str
r46695 self.bzproxy = xmlrpclib.ServerProxy(
pycompat.strurl(bzweb), self.transport(bzweb)
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ver = self.bzproxy.Bugzilla.version()[b'version'].split(b'.')
Jim Hague
bugzilla: add xmlrpcemail submission for Bugzilla 3.6 email interface...
r16224 self.bzvermajor = int(ver[0])
self.bzverminor = int(ver[1])
Augie Fackler
formatting: blacken the codebase...
r43346 login = self.bzproxy.User.login(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 {b'login': user, b'password': passwd, b'restrict_login': True}
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.bztoken = login.get(b'token', b'')
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Jim Hague
bugzilla: make XMLRPC interface support http and https access...
r15870 def transport(self, uri):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if util.urlreq.urlparse(uri, b"http")[0] == b"https":
Jim Hague
bugzilla: make XMLRPC interface support http and https access...
r15870 return cookiesafetransport()
else:
return cookietransport()
Jim Hague
bugzilla: add XMLRPC interface....
r13801 def get_bug_comments(self, id):
"""Return a string with all comment text for a bug."""
Augie Fackler
formatting: blacken the codebase...
r43346 c = self.bzproxy.Bug.comments(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 {b'ids': [id], b'include_fields': [b'text'], b'token': self.bztoken}
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''.join(
[t[b'text'] for t in c[b'bugs'][b'%d' % id][b'comments']]
)
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def filter_real_bug_ids(self, bugs):
Augie Fackler
formatting: blacken the codebase...
r43346 probe = self.bzproxy.Bug.get(
{
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'ids': sorted(bugs.keys()),
b'include_fields': [],
b'permissive': True,
b'token': self.bztoken,
Augie Fackler
formatting: blacken the codebase...
r43346 }
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for badbug in probe[b'faults']:
id = badbug[b'id']
self.ui.status(_(b'bug %d does not exist\n') % id)
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 del bugs[id]
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def filter_cset_known_bug_ids(self, node, bugs):
for id in sorted(bugs.keys()):
Jim Hague
bugzilla: add XMLRPC interface....
r13801 if self.get_bug_comments(id).find(short(node)) != -1:
Augie Fackler
formatting: blacken the codebase...
r43346 self.ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'bug %d already knows about changeset %s\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % (id, short(node))
)
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 del bugs[id]
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def updatebug(self, bugid, newstate, text, committer):
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 args = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'hours' in newstate:
args[b'work_time'] = newstate[b'hours']
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 if self.bzvermajor >= 4:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 args[b'ids'] = [bugid]
args[b'comment'] = {b'body': text}
if b'fix' in newstate:
args[b'status'] = self.fixstatus
args[b'resolution'] = self.fixresolution
args[b'token'] = self.bztoken
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 self.bzproxy.Bug.update(args)
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'fix' in newstate:
Augie Fackler
formatting: blacken the codebase...
r43346 self.ui.warn(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"Bugzilla/XMLRPC needs Bugzilla 4.0 or later "
b"to mark bugs fixed\n"
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 args[b'id'] = bugid
args[b'comment'] = text
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 self.bzproxy.Bug.add_comment(args)
Jim Hague
bugzilla: add XMLRPC interface....
r13801
Augie Fackler
formatting: blacken the codebase...
r43346
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 class bzxmlrpcemail(bzxmlrpc):
"""Read data from Bugzilla via XMLRPC, send updates via email.
Advantages of sending updates via email:
1. Comments can be added as any user, not just logged in user.
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 2. Bug statuses or other fields not accessible via XMLRPC can
potentially be updated.
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 There is no XMLRPC function to change bug status before Bugzilla
4.0, so bugs cannot be marked fixed via XMLRPC before Bugzilla 4.0.
But bugs can be marked fixed via email from 3.4 onwards.
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 """
Jim Hague
bugzilla: add xmlrpcemail submission for Bugzilla 3.6 email interface...
r16224 # The email interface changes subtly between 3.4 and 3.6. In 3.4,
# in-email fields are specified as '@<fieldname> = <value>'. In
# 3.6 this becomes '@<fieldname> <value>'. And fieldname @bug_id
# in 3.4 becomes @id in 3.6. 3.6 and 4.0 both maintain backwards
# compatibility, but rather than rely on this use the new format for
# 4.0 onwards.
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 def __init__(self, ui):
bzxmlrpc.__init__(self, ui)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.bzemail = self.ui.config(b'bugzilla', b'bzemail')
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 if not self.bzemail:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b"configuration 'bzemail' missing"))
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 mail.validateconfig(self.ui)
Jim Hague
bugzilla: add xmlrpcemail submission for Bugzilla 3.6 email interface...
r16224 def makecommandline(self, fieldname, value):
if self.bzvermajor >= 4:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b"@%s %s" % (fieldname, pycompat.bytestr(value))
Jim Hague
bugzilla: add xmlrpcemail submission for Bugzilla 3.6 email interface...
r16224 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if fieldname == b"id":
fieldname = b"bug_id"
return b"@%s = %s" % (fieldname, pycompat.bytestr(value))
Jim Hague
bugzilla: add xmlrpcemail submission for Bugzilla 3.6 email interface...
r16224
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 def send_bug_modify_email(self, bugid, commands, comment, committer):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """send modification message to Bugzilla bug via email.
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
The message format is documented in the Bugzilla email_in.pl
specification. commands is a list of command lines, comment is the
comment text.
To stop users from crafting commit comments with
Bugzilla commands, specify the bug ID via the message body, rather
than the subject line, and leave a blank line after it.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 user = self.map_committer(committer)
Augie Fackler
formatting: blacken the codebase...
r43346 matches = self.bzproxy.User.get(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 {b'match': [user], b'token': self.bztoken}
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not matches[b'users']:
user = self.ui.config(b'bugzilla', b'user')
Augie Fackler
formatting: blacken the codebase...
r43346 matches = self.bzproxy.User.get(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 {b'match': [user], b'token': self.bztoken}
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not matches[b'users']:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"default bugzilla user %s email not found") % user
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 user = matches[b'users'][0][b'email']
commands.append(self.makecommandline(b"id", bugid))
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 text = b"\n".join(commands) + b"\n\n" + comment
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
_charsets = mail._charsets(self.ui)
user = mail.addressencode(self.ui, user, _charsets)
bzemail = mail.addressencode(self.ui, self.bzemail, _charsets)
msg = mail.mimeencode(self.ui, text, _charsets)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg[b'From'] = user
msg[b'To'] = bzemail
msg[b'Subject'] = mail.headencode(
self.ui, b"Bug modification", _charsets
)
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802 sendmail = mail.connect(self.ui)
sendmail(user, bzemail, msg.as_string())
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def updatebug(self, bugid, newstate, text, committer):
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 cmds = []
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'hours' in newstate:
cmds.append(self.makecommandline(b"work_time", newstate[b'hours']))
if b'fix' in newstate:
cmds.append(self.makecommandline(b"bug_status", self.fixstatus))
cmds.append(self.makecommandline(b"resolution", self.fixresolution))
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 self.send_bug_modify_email(bugid, cmds, text, committer)
Jim Hague
bugzilla: add modified XMLRPC mode that uses email to send bug comments....
r13802
Augie Fackler
formatting: blacken the codebase...
r43346
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 class NotFound(LookupError):
pass
Augie Fackler
formatting: blacken the codebase...
r43346
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 class bzrestapi(bzaccess):
"""Read and write bugzilla data using the REST API available since
Bugzilla 5.0.
"""
Augie Fackler
formatting: blacken the codebase...
r43346
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 def __init__(self, ui):
bzaccess.__init__(self, ui)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 bz = self.ui.config(b'bugzilla', b'bzurl')
self.bzroot = b'/'.join([bz, b'rest'])
self.apikey = self.ui.config(b'bugzilla', b'apikey')
self.user = self.ui.config(b'bugzilla', b'user')
self.passwd = self.ui.config(b'bugzilla', b'password')
self.fixstatus = self.ui.config(b'bugzilla', b'fixstatus')
self.fixresolution = self.ui.config(b'bugzilla', b'fixresolution')
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923
def apiurl(self, targets, include_fields=None):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 url = b'/'.join([self.bzroot] + [pycompat.bytestr(t) for t in targets])
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 qv = {}
if self.apikey:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 qv[b'api_key'] = self.apikey
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 elif self.user and self.passwd:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 qv[b'login'] = self.user
qv[b'password'] = self.passwd
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 if include_fields:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 qv[b'include_fields'] = include_fields
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 if qv:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 url = b'%s?%s' % (url, util.urlreq.urlencode(qv))
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 return url
def _fetch(self, burl):
try:
resp = url.open(self.ui, burl)
Gregory Szorc
py3: define and use json.loads polyfill...
r43697 return pycompat.json_loads(resp.read())
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 except util.urlerr.httperror as inst:
if inst.code == 401:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'authorization failed'))
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 if inst.code == 404:
raise NotFound()
else:
raise
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 def _submit(self, burl, data, method=b'POST'):
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 data = json.dumps(data)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if method == b'PUT':
Augie Fackler
formatting: blacken the codebase...
r43346
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 class putrequest(util.urlreq.request):
def get_method(self):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'PUT'
Augie Fackler
formatting: blacken the codebase...
r43346
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 request_type = putrequest
else:
request_type = util.urlreq.request
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 req = request_type(burl, data, {b'Content-Type': b'application/json'})
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 try:
resp = url.opener(self.ui).open(req)
Gregory Szorc
py3: define and use json.loads polyfill...
r43697 return pycompat.json_loads(resp.read())
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 except util.urlerr.httperror as inst:
if inst.code == 401:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'authorization failed'))
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 if inst.code == 404:
raise NotFound()
else:
raise
def filter_real_bug_ids(self, bugs):
'''remove bug IDs that do not exist in Bugzilla from bugs.'''
badbugs = set()
for bugid in bugs:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 burl = self.apiurl((b'bug', bugid), include_fields=b'status')
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 try:
self._fetch(burl)
except NotFound:
badbugs.add(bugid)
for bugid in badbugs:
del bugs[bugid]
def filter_cset_known_bug_ids(self, node, bugs):
'''remove bug IDs where node occurs in comment text from bugs.'''
sn = short(node)
for bugid in bugs.keys():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 burl = self.apiurl(
(b'bug', bugid, b'comment'), include_fields=b'text'
)
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 result = self._fetch(burl)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 comments = result[b'bugs'][pycompat.bytestr(bugid)][b'comments']
if any(sn in c[b'text'] for c in comments):
Augie Fackler
formatting: blacken the codebase...
r43346 self.ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'bug %d already knows about changeset %s\n')
% (bugid, sn)
Augie Fackler
formatting: blacken the codebase...
r43346 )
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 del bugs[bugid]
def updatebug(self, bugid, newstate, text, committer):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """update the specified bug. Add comment text and set new states.
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923
If possible add the comment as being from the committer of
the changeset. Otherwise use the default Bugzilla user.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 bugmod = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'hours' in newstate:
bugmod[b'work_time'] = newstate[b'hours']
if b'fix' in newstate:
bugmod[b'status'] = self.fixstatus
bugmod[b'resolution'] = self.fixresolution
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 if bugmod:
# if we have to change the bugs state do it here
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 bugmod[b'comment'] = {
b'comment': text,
b'is_private': False,
b'is_markdown': False,
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 }
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 burl = self.apiurl((b'bug', bugid))
self._submit(burl, bugmod, method=b'PUT')
self.ui.debug(b'updated bug %s\n' % bugid)
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 burl = self.apiurl((b'bug', bugid, b'comment'))
Augie Fackler
formatting: blacken the codebase...
r43346 self._submit(
burl,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 {
b'comment': text,
b'is_private': False,
b'is_markdown': False,
},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.debug(b'added comment to bug %s\n' % bugid)
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923
def notify(self, bugs, committer):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Force sending of Bugzilla notification emails.
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923
Only required if the access method does not trigger notification
emails automatically.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
John Mulligan
bugzilla: add a rest api backend (usable with bugzilla 5.0+)...
r30923 pass
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class bugzilla:
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 # supported versions of bugzilla. different versions have
# different schemas.
_versions = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'2.16': bzmysql,
b'2.18': bzmysql_2_18,
b'3.0': bzmysql_3_0,
b'xmlrpc': bzxmlrpc,
b'xmlrpc+email': bzxmlrpcemail,
b'restapi': bzrestapi,
Augie Fackler
formatting: blacken the codebase...
r43346 }
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
def __init__(self, ui, repo):
self.ui = ui
self.repo = repo
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 bzversion = self.ui.config(b'bugzilla', b'version')
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855 try:
bzclass = bugzilla._versions[bzversion]
except KeyError:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'bugzilla version %s not supported') % bzversion
Augie Fackler
formatting: blacken the codebase...
r43346 )
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855 self.bzdriver = bzclass(self.ui)
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855 self.bug_re = re.compile(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.config(b'bugzilla', b'regexp'), re.IGNORECASE
Augie Fackler
formatting: blacken the codebase...
r43346 )
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855 self.fix_re = re.compile(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.config(b'bugzilla', b'fixregexp'), re.IGNORECASE
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
py3: port test-bugzilla.t to Python 3...
r41379 self.split_re = re.compile(br'\D+')
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def find_bugs(self, ctx):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """return bugs dictionary created from commit comment.
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 Extract bug info from changeset comments. Filter out any that are
Jim Hague
bugzilla: keep bug IDs in set....
r13799 not known to Bugzilla, and any that already have a reference to
the given changeset in their comments.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 start = 0
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 bugs = {}
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855 bugmatch = self.bug_re.search(ctx.description(), start)
fixmatch = self.fix_re.search(ctx.description(), start)
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 while True:
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 bugattribs = {}
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 if not bugmatch and not fixmatch:
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 break
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 if not bugmatch:
m = fixmatch
elif not fixmatch:
m = bugmatch
else:
if bugmatch.start() < fixmatch.start():
m = bugmatch
else:
m = fixmatch
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 start = m.end()
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 if m is bugmatch:
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855 bugmatch = self.bug_re.search(ctx.description(), start)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'fix' in bugattribs:
del bugattribs[b'fix']
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223 else:
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855 fixmatch = self.fix_re.search(ctx.description(), start)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 bugattribs[b'fix'] = None
Jim Hague
bugzilla: allow change comment to mark bugs fixed...
r16223
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ids = m.group(b'ids')
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 except IndexError:
ids = m.group(1)
try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 hours = float(m.group(b'hours'))
bugattribs[b'hours'] = hours
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 except IndexError:
pass
except TypeError:
pass
except ValueError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.ui.status(_(b"%s: invalid hours\n") % m.group(b'hours'))
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855 for id in self.split_re.split(ids):
Matt Mackall
many, many trivial check-code fixups
r10282 if not id:
continue
Jim Hague
bugzilla: extract optional hours from commit message and update bug time...
r16222 bugs[int(id)] = bugattribs
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 if bugs:
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855 self.bzdriver.filter_real_bug_ids(bugs)
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 if bugs:
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855 self.bzdriver.filter_cset_known_bug_ids(ctx.node(), bugs)
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 return bugs
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 def update(self, bugid, newstate, ctx):
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 '''update bugzilla bug with reference to changeset.'''
def webroot(root):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """strip leading prefix of repo root and turn into
url-safe path."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 count = int(self.ui.config(b'bugzilla', b'strip'))
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 root = util.pconvert(root)
while count > 0:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 c = root.find(b'/')
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 if c == -1:
break
Augie Fackler
formatting: blacken the codebase...
r43346 root = root[c + 1 :]
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 count -= 1
return root
Yuya Nishihara
bugzilla: do not load style file if template is specified (BC)...
r28950 mapfile = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 tmpl = self.ui.config(b'bugzilla', b'template')
Yuya Nishihara
bugzilla: do not load style file if template is specified (BC)...
r28950 if not tmpl:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mapfile = self.ui.config(b'bugzilla', b'style')
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 if not mapfile and not tmpl:
Augie Fackler
formatting: blacken the codebase...
r43346 tmpl = _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'changeset {node|short} in repo {root} refers '
b'to bug {bug}.\ndetails:\n\t{desc|tabindent}'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Yuya Nishihara
cmdutil: drop aliases for logcmdutil functions (API)...
r35906 spec = logcmdutil.templatespec(tmpl, mapfile)
Yuya Nishihara
logcmdutil: drop default arguments from changesetdisplayer/templater() calls
r35972 t = logcmdutil.changesettemplater(self.ui, self.repo, spec)
Matt Mackall
update bugzilla extension to use ui buffers
r3741 self.ui.pushbuffer()
Augie Fackler
formatting: blacken the codebase...
r43346 t.show(
ctx,
changes=ctx.changeset(),
bug=pycompat.bytestr(bugid),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 hgweb=self.ui.config(b'web', b'baseurl'),
Augie Fackler
formatting: blacken the codebase...
r43346 root=self.repo.root,
webroot=webroot(self.repo.root),
)
Matt Mackall
update bugzilla extension to use ui buffers
r3741 data = self.ui.popbuffer()
Augie Fackler
formatting: blacken the codebase...
r43346 self.bzdriver.updatebug(
bugid, newstate, data, stringutil.email(ctx.user())
)
Jim Hague
bugzilla: stop trying to cache setup across hook invocation...
r21855
def notify(self, bugs, committer):
'''ensure Bugzilla users are notified of bug change.'''
self.bzdriver.notify(bugs, committer)
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192
Augie Fackler
formatting: blacken the codebase...
r43346
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 def hook(ui, repo, hooktype, node=None, **kwargs):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """add comment to bugzilla for each changeset that refers to a
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 bugzilla bug id. only add a comment once per bug, so same change
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 seen multiple times does not fill bug with duplicate data."""
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 if node is None:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'hook type %s does not pass a changeset id') % hooktype
Augie Fackler
formatting: blacken the codebase...
r43346 )
Vadim Gelfer
add bugzilla integration hook. example of writing hook in python....
r2192 try:
bz = bugzilla(ui, repo)
Matt Mackall
use repo[changeid] to get a changectx
r6747 ctx = repo[node]
Jim Hague
bugzilla: modify access interface to include new bug states...
r16221 bugs = bz.find_bugs(ctx)
if bugs:
for bug in bugs:
bz.update(bug, bugs[bug], ctx)
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 bz.notify(bugs, stringutil.email(ctx.user()))
Gregory Szorc
global: mass rewrite to use modern exception syntax...
r25660 except Exception as e:
Mads Kiilerich
bugzilla: fix reporting of exceptions with py3
r46694 raise error.Abort(_(b'Bugzilla error: %s') % stringutil.forcebytestr(e))