cJHdZddlZddlZddlZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZddlmZmZejZdZiZe jeZedd d edd d eddd eddd eddd eddd eddd eddd eddd eddd eddej eddd eddd edd d edd!d edd"d edd#d$ edd%d edd&d edd'd Gd(d)ZGd*d+eZGd,d-eZGd.d/eZGd0d1ZGd2d3eejZGd4d5eejZ Gd6d7eZ!Gd8d9e!Z"Gd:d;e#Z$Gd<d=eZ%Gd>d?Z&dAd@Z'dS)Ba)hooks for integrating with the Bugzilla bug tracker This hook extension adds comments on bugs in Bugzilla when changesets that refer to bugs by Bugzilla ID are seen. The comment is formatted using the Mercurial template mechanism. The bug references can optionally include an update for Bugzilla of the hours spent working on the bug. Bugs can also be marked fixed. Four basic modes of access to Bugzilla are provided: 1. Access via the Bugzilla REST-API. Requires bugzilla 5.0 or later. 2. Access via the Bugzilla XMLRPC interface. Requires Bugzilla 3.4 or later. 3. Check data via the Bugzilla XMLRPC interface and submit bug change via email to Bugzilla email interface. Requires Bugzilla 3.4 or later. 4. Writing directly to the Bugzilla database. Only Bugzilla installations using MySQL are supported. Requires Python MySQLdb. 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 forward. Only adding comments is supported in this access mode. 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 necessary to add comments. Marking bugs fixed requires Bugzilla 4.0 and later. Access via XMLRPC/email uses XMLRPC to query Bugzilla, but sends 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 that the Mercurial user email is not recognized by Bugzilla as a Bugzilla user, the email associated with the Bugzilla username used to log into Bugzilla is used instead as the source of the comment. Marking bugs fixed works on all supported Bugzilla versions. Access via the REST-API needs either a Bugzilla username and password or an apikey specified in the configuration. Comments are made under the given username or the user associated with the apikey in Bugzilla. Configuration items common to all access modes: bugzilla.version The access type to use. Values recognized are: :``restapi``: Bugzilla REST-API, Bugzilla 5.0 and later. :``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. bugzilla.regexp Regular expression to match bug IDs for update in changeset commit message. It must contain one "()" named group ```` containing the bug IDs separated by non-digit characters. It may also contain a named group ```` 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. bugzilla.fixregexp Regular expression to match bug IDs for marking fixed in changeset commit message. This must contain a "()" named group ``` containing the bug IDs separated by non-digit characters. It may also contain a named group ```` 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``. bugzilla.style The style file to use when formatting comments. bugzilla.template Template to use when formatting comments. Overrides style if specified. In addition to the usual Mercurial keywords, the extension specifies: :``{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. Default ``changeset {node|short} in repo {root} refers to bug {bug}.\ndetails:\n\t{desc|tabindent}`` bugzilla.strip 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. web.baseurl Base URL for browsing Mercurial repositories. Referenced from templates as ``{hgweb}``. Configuration items common to XMLRPC+email and MySQL access modes: bugzilla.usermap Path of file containing Mercurial committer email to Bugzilla user email mappings. If specified, the file should contain one mapping per line:: committer = Bugzilla user See also the ``[usermap]`` section. The ``[usermap]`` section is used to specify mappings of Mercurial committer email to Bugzilla user email. See also ``bugzilla.usermap``. Contains entries of the form ``committer = Bugzilla user``. XMLRPC and REST-API access mode configuration: bugzilla.bzurl The base URL for the Bugzilla installation. Default ``http://localhost/bugzilla``. bugzilla.user The username to use to log into Bugzilla via XMLRPC. Default ``bugs``. bugzilla.password The password for Bugzilla login. 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. XMLRPC+email access mode uses the XMLRPC access mode configuration items, and also: bugzilla.bzemail The Bugzilla email address. In addition, the Mercurial email settings must be configured. See the documentation in hgrc(5), sections ``[email]`` and ``[smtp]``. MySQL access mode configuration: bugzilla.host Hostname of the MySQL server holding the Bugzilla database. Default ``localhost``. bugzilla.db Name of the Bugzilla database in MySQL. Default ``bugs``. bugzilla.user Username to use to access MySQL server. Default ``bugs``. bugzilla.password Password to use to access MySQL server. bugzilla.timeout Database connection timeout (seconds). Default 5. bugzilla.bzuser Fallback Bugzilla user name to record comments with, if changeset committer cannot be found as a Bugzilla user. bugzilla.bzdir Bugzilla install directory. Used by default notify. Default ``/var/www/html/bugzilla``. bugzilla.notify The command to run to get Bugzilla to send bug change notification 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". Activating the extension:: [extensions] bugzilla = [hooks] # run bugzilla hook on every change pulled or pushed in here incoming.bugzilla = python:hgext.bugzilla.hook Example configurations: XMLRPC example configuration. This uses the Bugzilla at ``http://my-project.org/bugzilla``, logging in as user ``bugmail@my-project.org`` with password ``plugh``. It is used with a collection of Mercurial repositories in ``/var/local/hg/repos/``, with a web interface at ``http://my-project.org/hg``. :: [bugzilla] bzurl=http://my-project.org/bugzilla user=bugmail@my-project.org password=plugh version=xmlrpc template=Changeset {node|short} in {root|basename}. {hgweb}/{webroot}/rev/{node|short}\n {desc}\n strip=5 [web] baseurl=http://my-project.org/hg XMLRPC+email example configuration. This uses the Bugzilla at ``http://my-project.org/bugzilla``, logging in as user ``bugmail@my-project.org`` with password ``plugh``. It is used with a 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 ``bugzilla@my-project.org``. :: [bugzilla] bzurl=http://my-project.org/bugzilla user=bugmail@my-project.org password=plugh version=xmlrpc+email bzemail=bugzilla@my-project.org template=Changeset {node|short} in {root|basename}. {hgweb}/{webroot}/rev/{node|short}\n {desc}\n strip=5 [web] baseurl=http://my-project.org/hg [usermap] user@emaildomain.com=user.name@bugzilladomain.com 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``. :: [bugzilla] host=localhost password=XYZZY version=3.0 bzuser=unknown@domain.com bzdir=/opt/bugzilla-3.2 template=Changeset {node|short} in {root|basename}. {hgweb}/{webroot}/rev/{node|short}\n {desc}\n strip=5 [web] baseurl=http://my-project.org/hg [usermap] user@emaildomain.com=user.name@bugzilladomain.com All the above add a comment to the Bugzilla bug record of the form:: Changeset 3b16791d6642 in repository-name. http://my-project.org/hg/repository-name/rev/3b16791d6642 Changeset commit comment. Bug 1234. N)_)short)error logcmdutilmailpycompat registrarurlutil)procutil stringutilsships-with-hg-corebugzillaapikey)defaultbzdirs/var/www/html/bugzillabzemailbzurlshttp://localhost/bugzilla/bzuserdbbugs fixregexpsfix(?:es)?\s*(?:bugs?\s*)?,?\s*(?:nos?\.?|num(?:ber)?s?)?\s*(?P(?:#?\d+\s*(?:,?\s*(?:and)?)?\s*)+)\.?\s*(?:h(?:ours?)?\s*(?P\d*(?:\.\d+)?))? fixresolutionsFIXED fixstatussRESOLVEDhosts localhostnotifypasswordregexpsbugs?\s*,?\s*(?:#|nos?\.?|num(?:ber)?s?)?\s*(?P(?:\d+\s*(?:,?\s*(?:and)?)?\s*)+)\.?\s*(?:h(?:ours?)?\s*(?P\d*(?:\.\d+)?))?stripstyletemplatetimeoutuserusermapversionc6eZdZdZdZdZdZdZdZdZ dS) bzaccessz"Base class for access to Bugzilla.c||_|jdd}|r|j|dgdSdS)Nrr%)sections)uiconfig readconfig)selfr+usermaps 0/usr/lib/python3/dist-packages/hgext/bugzilla.py__init__zbzaccess.__init__sS'..j99  ? G  w*  > > > > > ? ?rc|jdD]3\}}||kr|cS4|S)z,map name of committer to Bugzilla user name.r%)r+ configitemslower)r.user committerbzusers r0 map_committerzbzaccess.map_committersV!%!4!4Z!@!@   Iv  DJJLL00 1 rcdS)7remove bug IDs that do not exist in Bugzilla from bugs.N)r.bugss r0filter_real_bug_idszbzaccess.filter_real_bug_idsrcdS);remove bug IDs where node occurs in comment text from bugs.Nr;)r.noder<s r0filter_cset_known_bug_idsz"bzaccess.filter_cset_known_bug_idsr>rcdS)update the specified bug. Add comment text and set new states. If possible add the comment as being from the committer of the changeset. Otherwise use the default Bugzilla user. Nr;)r.bugidnewstatetextr6s r0 updatebugzbzaccess.updatebugr>rcdSzForce sending of Bugzilla notification emails. Only required if the access method does not trigger notification emails automatically. Nr;r.r<r6s r0notifyzbzaccess.notifyr>rN) __name__ __module__ __qualname____doc__r1r8r=rBrHrLr;rr0r(r(sz,,??? FFFJJJ        rr(cbeZdZdZedZdZdZdZdZ dZ dZ d Z d Z d Zd ZdS) bzmysqlzSupport for direct MySQL access to Bugzilla. The earliest Bugzilla version this is tested with is version 2.16. If your Bugzilla is version 3.4 or above, you are strongly recommended to use the XMLRPC access method instead. c^ddtt|zdzS)z#return SQL-friendly list of bug ids(,))joinmapstr)idss r0 sql_buglistzbzmysql.sql_buglists(diiC ...55rNc r ddl}|t_nI#t$r<}t jt d|zt ddzzd}~wwxYwt|||j dd}|j dd}|j dd}|j dd }t|j dd }|j t d |||d t|zfztj||||| |_|j|_||_i|_d|_dS)Nrs&python mysql support not available: %ss (try installing the %s package)spython3-mysqldbrrr$rrr"s'connecting to %s:%s as %s, password %s *)hostr5passwddbconnect_timeouts-cd %(bzdir)s && ./processmail %(id)s %(user)s)MySQLdbrR_MySQLdb ImportErrorrAbortrr(r1r+r,intnotelenconnectconncursorget_longdesc_id longdesc_iduser_idsdefault_notify) r.r+mysqlerrr^r5r_r`timeouts r0r1zbzmysql.__init__s  # # # #$G     +;<>  9 : :Rtc&kk12 3   $,,DB-   i&&(( //11 Ns A7AAc|jtd||fz |jj|i|dS#t jj$r.|jtd||fzwxYw)z run a query.s query: %s %s sfailed query: %s %s N)r+rgrrkexecuterRrc MySQLError)r.argskwargss r0runz bzmysql.runs  Q())T6N:;;;  DK  0 0 0 0 0 0*    GLL344f~E F F F  s AABc|d|j}t|dkr!t jt d|ddS)get identity of longdesc fields5select fieldid from fielddefs where name = "longdesc"unknown database schemarrxrkfetchallrhrrerr.rZs r0rlzbzmysql.get_longdesc_ids^ IJJJk""$$ s88q==+a :;;<< <1vayrc`|dt|zd|jD}|D]3}||vr-|jtd|z||=4dS)z"filter not-existing bugs from set.s*select bug_id from bugs where bug_id in %scg|]\}|Sr;r;).0ids r0 z/bzmysql.filter_real_bug_ids..(s;;;5BB;;;rbug %d does not exist N) rxrRr[keysrkr~r+statusr)r.r<existingrs r0r=zbzmysql.filter_real_bug_ids"s  9!!$))++.. /   <;DK$8$8$:$:;;;))++  B!!q!;<   [))++  ER GNN>??uT{{#$   R   rc|jtd||\}}|D]W}|jtd|z|jdd|j}|jdd} ||z}n#t$r ||||dz}YnwxYw|jtd|ztj d|zd } tj | } | } | rP|j| t!jtd tj| zY|jtd d S) ztell bugzilla to send mail.stelling bugzilla to send mail: s bug %s rrr)ridr$srunning notify command %s s (%s) 2>&1srbsbugzilla notify command %ssdone N)r+rrget_bugzilla_userrr,ro TypeErrorrgr popenr fromnativeeolreadclosewarnrre explainexit) r.r<r6r5useridrcmdfmtbzdircmdfpoutrets r0rLzbzmysql.notify<s q<==>>>// ::v))++  B GNN1]++b0 1 1 1W^^KDCCCc |j|S#t$r t|}n#t$r|jt d|z|d||j }t|dkrt|t|dd}YnwxYw||j|<|cYSwxYw)z!look up numeric bugzilla user id.slooking up user %s zPselect userid from profiles where login_name like %sr{r) rnKeyErrorrf ValueErrorr+rgrrxrkr~rh)r.r5ralls r0 get_user_idzbzmysql.get_user_idVs =& &    (T ( ( ( Q677$>???8 k**,,s88q=="4..(SVAY (#)DM$ MMM s0  C*CB C  C C  CCc||} ||}n#t$r |jdd}|s$t jtd|z||}|}n4#t$r't jtd||fzwxYwYnwxYw||fS)zSee if committer is a registered bugzilla user. Return bugzilla username and userid if so. If not, return default bugzilla username and userid.rrs#cannot find bugzilla user id for %ss)cannot find bugzilla user id for %s or %s)r8rrr+r,rrer)r.r6r5r defaultusers r0rzbzmysql.get_bugzilla_userks !!),, %%d++FF    "gnn[)DD "+@AADH))+66"   kBCC[)*  f~s'- CABC1CCCcvt|dkr'|jtd||\}}t jd}|d||||f|d||||jf|j dS)zupdate bug state with comment text. Try adding comment as committer of changeset, otherwise as default bugzilla user.rs'Bugzilla/MySQL cannot update bug state z%Y-%m-%d %H:%M:%Szvinsert into longdescs (bug_id, who, bug_when, thetext) values (%s, %s, %s, %s)zfinsert into bugs_activity (bug_id, who, bug_when, fieldid) values (%s, %s, %s, %s)N) rhr+rrrtimestrftimerxrmrjcommit)r.rErFrGr6r5rnows r0rHzbzmysql.updatebugs x==1   GLLFGG H H H// ::vm/00  /FC &     / FC!1 2   r)rMrNrOrP staticmethodr[rcr1rxrlr=rBrLrrrHr;rr0rRrRs66\6HOOO<      %%%4*.rrRceZdZdZdZdS) bzmysql_2_18z!support for bugzilla 2.18 series.cJt||d|_dS)Ns>cd %(bzdir)s && perl -T contrib/sendbugmail.pl %(id)s %(user)s)rRr1ror.r+s r0r1zbzmysql_2_18.__init__s)r""" M rN)rMrNrOrPr1r;rr0rrs)++     rrceZdZdZdZdZdS) bzmysql_3_0z support for bugzilla 3.0 series.c<t||dSN)rr1rs r0r1zbzmysql_3_0.__init__sdB'''''rc|d|j}t|dkr!t jt d|ddS)rzs0select id from fielddefs where name = "longdesc"r{r|rr}rs r0rlzbzmysql_3_0.get_longdesc_ids^ DEEEk""$$ s88q==+a :;;<< <1vayrN)rMrNrOrPr1rlr;rr0rrs8**(((rrc$eZdZdZgZdZddZdS)cookietransportrequestaA Transport request method that retains cookies over its lifetime. The regular xmlrpclib transports ignore cookies. Which causes a bit of a problem when you need a cookie-based login, as with the Bugzilla XMLRPC interface prior to 4.4.3. 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. cX|jr |jD]}|d|dSdS)NsCookie)cookies putheader)r. connectioncookies r0 send_cookiesz#cookietransportrequest.send_cookiessJ < 8, 8 8$$Y7777 8 8 8 8rrc||_d|_||}|r|d|||||||||||||| | }n)#t$r|j }YnwxYw|j dD]T}|ddd}|ddd} |j| U|jdkr4t$||z|j|j|j j|} |\} } | | | | S)NFr{s Set-Cookies: ;r)verboseaccept_gzip_encodingmake_connectionset_debuglevel send_request send_hostrsend_user_agent send_content getresponseAttributeError_connmsggetallmatchingheaderssplitrappendr xmlrpclib ProtocolErrorreasonheadersr getparserfeedr) r.r^handler request_bodyrhresponseheadervalrpayloadparser unmarshallers r0requestzcookietransportrequest.requests $)!   & &   Q    !Wl333 q$ ! Q !\*** -}}HH - - -w**,,HHH -l88GG ( (F,,ua((+CYYtQ''*F L   ' ' ' ' ?c ! !))w $  --//#~~//  G !!###s)B>>#C$#C$Nr)rMrNrOrPrrrr;rr0rrsH  G888 ,$,$,$,$,$,$rrceZdZddZdS)cookietransportrctjtjdr"tj||dSdSNr1)r safehasattrr Transportr1r. use_datetimes r0r1zcookietransport.__init__sC  I/ < < =   ( (| < < < < < = =rNrrMrNrOr1r;rr0rrs(======rrceZdZddZdS)cookiesafetransportrctjtjdr"tj||dSdSr)r rrr SafeTransportr1rs r0r1zcookiesafetransport.__init__sF  I/ < < A  # , ,T< @ @ @ @ @ A ArNrrr;rr0rrs.AAAAAArrc6eZdZdZdZdZdZdZdZdZ dS) bzxmlrpcznSupport for access to Bugzilla via the Bugzilla XMLRPC API. Requires a minimum Bugzilla version 3.4. cjt|||jdd}|ddz}|jdd}|jdd}|jdd|_|jdd|_ttj || ||_ |j j d d }t!|d |_t!|d |_|j j||d d}|dd|_dS)Nrr/s /xmlrpc.cgir$rrrr&.rr{T)loginrsrestrict_logintokenr)r(r1r+r,rstrip fixstatus fixresolutionr ServerProxyrstrurl transportbzproxyBugzillaversionrrf bzvermajor bzverminorUserlogingetbztoken)r.r+bzwebr5r_verrs r0r1zbzxmlrpc.__init__s^$###{H55 T""^3w~~k733 [99 \BB!W^^K9IJJ ,, OE " "DNN5$9$9   l#++--j9??EEc!f++c!f++ !''&T J J  yy3// rctj|dddkrtSt S)Nshttprshttps)r urlrequrlparserr)r.uris r0rzbzxmlrpc.transport)s< ;  W - -a 0H < <&(( ("$$ $rc|jj|gdg|jd}dd|dd|zdDS)z0Return a string with all comment text for a bug.text)idsinclude_fieldsrrcg|] }|d S)rr;rts r0rz-bzxmlrpc.get_bug_comments..5s E E EAQwZ E E Errs%dcomments)rBugcommentsrrW)r.rcs r0get_bug_commentszbzxmlrpc.get_bug_comments/sj L  % %Twi4< P P  xx E E7EBJ!7 !D E E E   rc|jjt|gd|jd}|dD]7}|d}|jtd|z||=8dS)NT)r r s permissiversfaultsrr) rrrsortedrrr+rr)r.r<probebadbugrs r0r=zbzxmlrpc.filter_real_bug_ids8s  $$tyy{{++#%#,     I&  FB GNN17882= > > >R  rc8t|D]w}||t |dkr<|jtd|t |fz||=xdS)Nr)rrrfindrr+rrrs r0rBz"bzxmlrpc.filter_cset_known_bug_idsFs%%  B$$R((--eDkk::b@@BCC5;;'(H   rci}d|vr |d|d<|jdkrP|g|d<d|i|d<d|vr|j|d<|j|d <|j|d <|jj|dSd|vr'|jtd ||d <||d<|jj |dS) Nhours work_timer sbodycommentfixstatus resolutionrs?Bugzilla/XMLRPC needs Bugzilla 4.0 or later to mark bugs fixed r) rrrrrrupdater+rr add_comment)r.rErFrGr6rvs r0rHzbzxmlrpc.updatebugOs x  !)(!3D  ?a  !7DL 'D !!"&.Y&*&8]#!\DN L  # #D ) ) ) ) )!! 0  DK#D  L  ( ( . . . . .rN) rMrNrOrPr1rrr=rBrHr;rr0rr sx 000.%%%       /////rrc*eZdZdZdZdZdZdZdS) bzxmlrpcemailaRead 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. 2. Bug statuses or other fields not accessible via XMLRPC can potentially be updated. 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. ct|||jdd|_|js!t jtdtj |jdS)Nrrsconfiguration 'bzemail' missing) rr1r+r,bzemailrrerrvalidateconfigrs r0r1zbzxmlrpcemail.__init__}sl$###w~~k:>> | E+a BCCDD D DG$$$$$rc|jdkrd|tj|fzS|dkrd}d|tj|fzS)Nrs@%s %srsbug_ids@%s = %s)rrbytestr)r. fieldnamevalues r0makecommandlinezbzxmlrpcemail.makecommandlinesU ?a   8+;E+B+BCC CE!!% )X-=e-D-D!EE Erc||}|jj|g|jd}|dso|jdd}|jj|g|jd}|ds$tjtd|z|ddd}| | d|d |d z|z}tj|j}tj|j||}tj|j|j|} tj|j||} || d <| | d <tj|jd || d<tj|j} | || | dS)asend modification message to Bugzilla bug via email. 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. )smatchrsusersrr$s(default bugzilla user %s email not foundrsemailr s sFromsTosBug modificationsSubjectN)r8rrrrr+r,rrerrr-rWr _charsets addressencoder' mimeencode headencoderi as_string) r.rEcommandscommentr6r5matchesrGr0r'rsendmails r0send_bug_modify_emailz#bzxmlrpcemail.send_bug_modify_emails!!),,,#''v 6 6  x  7>>+w77Dl'++ 6T\::G8$ kABBTIx #H-,,UE::;;;zz(##g-7N47++ !$'4;;$TWdlIFFodgtY77G E / G()  J<((w 00000rc`g}d|vr/||d|dd|vr\||d|j||d|j|||||dS)Nrrrs bug_statusr!)rr-rrr9)r.rErFrGr6cmdss r0rHzbzxmlrpcemail.updatebugs x   KK,,\8H;MNN O O O X   KK,,]DNKK L L L KK,,]D>  \BB!W^^K9IJJrNcd|jgd|Dz}i}|jr |j|d<n"|jr|jr|j|d<|j|d<|r||d<|r$d|t j|fz}|S)Nrc6g|]}tj|Sr;)rr*r s r0rz$bzrestapi.apiurl..s#(N(N(N)9!)<)<(N(N(Nrsapi_keyrrr s%s?%s)rWrArBr5r_r r urlencode)r.targetsinclude_fieldsr qvs r0apiurlzbzrestapi.apiurlsii (N(Ng(N(N(NNOO  ; *![BzNN Y *4; *9BxL"kB{O  3$2B !  >c4;#8#8#<#<==C rcH tj|j|}tj|S#t jj$rK}|j dkr!tj td|j dkrtd}~wwxYw)Nauthorization failed)r openr+r json_loadsrr urlerr httperrorcoderrerr=)r.burlrespinsts r0_fetchzbzrestapi._fetchs 8DGT**D&tyy{{33 3{$   yCk!$;"<"<===yCjj   s?AB!ABB!POSTc tj|}|dkr Gddtjj}|}ntjj}|||ddi} t j|j|}tj | S#tj j $rK}|jdkr!tjt#d|jdkrt%d}~wwxYw) NPUTceZdZdZdS)%bzrestapi._submit..putrequestcdS)NrZr;)r.s r0 get_methodz0bzrestapi._submit..putrequest.get_methods!6rN)rMrNrOr^r;rr0 putrequestr\s#"""""rr_s Content-Typesapplication/jsonrLrMrN)jsondumpsr rrr openerr+rOrrPrrQrRrSrrerr=) r.rTdatamethodr_ request_typereqrUrVs r0_submitzbzrestapi._submitsz$ V   " " " " "T[0 " " "&LL;.Ll49L'MNN :dg&&++C00D&tyy{{33 3{$   yCk!$;"<"<===yCjj   sAB..D ADD ct}|D]V}|d|fd} ||2#t$r||YSwxYw|D]}||=dS)r:bugr rHN)setrJrWr=add)r.r<badbugsrErTs r0r=zbzrestapi.filter_real_bug_idss%% # #E;;y;IID # D!!!! # # # E""""" #  EU   sAA%$A%ct||D]}|d|dfd}||}|dt j|d}t fd|Dr/|jtd|fz||=d S) r@rirrrjrrc3,K|]}|dvVdS)rNr;)rrsns r0 z6bzrestapi.filter_cset_known_bug_ids..s,6627#666666rrN) rrrJrWrr*anyr+rr)r.rAr<rErTresultrrps @r0rBz#bzrestapi.filter_cset_known_bug_idss 4[[YY[[ E;; +GD[[&&Fgx'7'>'>? LH6666X66666 BCCbk"K rci}d|vr |d|d<d|vr|j|d<|j|d<|rW|ddd|d<|d |f}|||d |jd |zdS|d |df}|||ddd|jd |zdS)rDrrrr r!F)rs is_privates is_markdownrrirZ)rdsupdated bug %s sadded comment to bug %s N)rrrJrgr+debug)r.rErFrGr6bugmodrTs r0rHzbzrestapi.updatebug s!  x  #+H#5F< X   $F9 $($6F= !  @!$ %""F:  ;;//D LLvfL 5 5 5 GMM-5 6 6 6 6 6;;z:;;D LL $#($)    GMM6> ? ? ? ? ?rcdSrJr;rKs r0rLzbzrestapi.notifyBs rr)rX) rMrNrOrPr1rJrWrgr=rBrHrLr;rr0r?r?sKKK       .      @ @ @D     rr?c8eZdZeeeeeedZ dZ dZ dZ dZ dS)bugzilla)s2.16s2.18s3.0sxmlrpcs xmlrpc+emailsrestapic4||_||_|jdd} tj|}n2#t $r%t jtd|zwxYw||j|_ tj |jddtj |_ tj |jddtj |_tj d|_dS)Nrr&s!bugzilla version %s not supportedrrs\D+)r+repor,ry _versionsrrrerbzdriverrecompile IGNORECASEbug_refix_resplit_re)r.r+r{ bzversionbzclasss r0r1zbugzilla.__init__Ws GNN; ;;  (3GG   +677)C   (( j GNN; 2 2BM   j GNN; 5 5r}    7++ s >/A-cd}i}|j||}|j||} i}|s|sn|s|}n4|s|}n/||kr|}n|}|}||ur5|j||}d|vr|d=n2|j||}d|d< |d}n%#t$r|d}YnwxYw t|d} | |d<nc#t$rYnWt$rYnLt$r@|j td|dzYnwxYw|j|D]} | s||t!| <|r|j||r-|j|||S) zreturn bugs dictionary created from commit comment. Extract bug info from changeset comments. Filter out any that are not known to Bugzilla, and any that already have a reference to the given changeset in their comments. rTrNr r{rs%s: invalid hours )rsearch descriptionrstartendgroup IndexErrorfloatrrr+rrrrrfr}r=rBrA) r.ctxrr<bugmatchfixmatch bugattribsmrZhoursrs r0 find_bugszbugzilla.find_bugsls;%%coo&7&7??;%%coo&7&7??' +J H  ! !>>##hnn&6&666 AA AEEGGEH}};--coo.?.?GGZ''"6*;--coo.?.?GG%) 6" !ggfoo ! ! !ggajj ! Naggh//00', 8$$       N N Nq!7881778;L;LLMMMMM Nm))#.. + + *SWW O' +P  4 M - -d 3 3 3  F M 3 3CHHJJ E E E s1!D77EE'F G% G%AG%$G%c fd}d}jdd}|sjdd}|s|std}tj||}tjjj|}j||| tj |jddjj |jj  j } j||| t!j|dS) z0update bugzilla bug with reference to changeset.ctjdd}tj|}|dkr4|d}|dkrn||dzd}|dz}|dk4|S)zJstrip leading prefix of repo root and turn into url-safe path.rrrrrr{N)rfr+r,r pconvertr)rootcountrr.s r0webrootz bugzilla.update..webroots{H==>>E=&&D!))IIdOO77AEGG}  !)) KrNrr!r sUchangeset {node|short} in repo {root} refers to bug {bug}. details: {desc|tabindent}swebsbaseurl)changesbughgwebrr)r+r,rr templatespecchangesettemplaterr{ pushbuffershow changesetrr*r popbufferr}rHr emailr5) r.rErFrrmapfiletmplspecr rcs ` r0r"zbugzilla.updateso     w~~k;77 <gnn[(;;G t ?D&tW55  )$'49d C C   MMOO '''..44GDIN++    w  ""  8T:#3CHHJJ#?#?     rc<|j||dS)z1ensure Bugzilla users are notified of bug change.N)r}rLrKs r0rLzbugzilla.notifys  T9-----rN)rMrNrOrRrrrr%r?r|r1rr"rLr;rr0ryryKsr& I,,,*777r' ' ' R.....rryc |$tjtd|z t||}||}||}|r^|D]}||||| ||tj| dSdS#t$r;} tjtdtj | zd} ~ wwxYw)zadd comment to bugzilla for each changeset that refers to a bugzilla bug id. only add a comment once per bug, so same change seen multiple times does not fill bug with duplicate data.Ns)hook type %s does not pass a changeset idsBugzilla error: %s) rrerryrr"rLr rr5 Exception forcebytestr) r+r{hooktyperArwrCrr<res r0hookrs |k : ; ;h F    Q b$  4j||C    : / / #tCy#.... IIdJ,SXXZZ88 9 9 9 9 9 : : QQQk!122Z5LQ5O5OOPPPQsB B77 C<6C77C<r)(rPr`r~rmercurial.i18nrmercurial.noder mercurialrrrrr r r mercurial.utilsr r r testedwith configtable configitemdynamicdefaultr(rRrrrrrrrrr% LookupErrorr=r?ryrr;rr0rs:[[|   N #  !Y !+ . .     %      )         >                %       >                     * * * * * * * * \ttttthtttn     7        ,   $C$C$C$C$C$C$C$C$T=====,i.A=== AAAAA0)2IAAA Z/Z/Z/Z/Z/xZ/Z/Z/zTATATATATAHTATATAn     {   D D D D D D D D NE.E.E.E.E.E.E.E.PQQQQQQr