a —+«b;¦ã@s|dZddlmZddlZddlZddlZddlmZddlm Z ddl m Z m Z m Z mZmZmZmZddlmZmZejZdZiZe e¡Zed d d d ed d dd ed ddd ed ddd ed ddd ed ddd ed ddd ed ddd ed ddd ed ddd ed dejd ed ddd ed dd d ed d!dd ed d"dd ed d#dd ed d$d%d ed d&dd ed d'dd ed d(dd Gd)d*„d*eƒZGd+d,„d,eƒZGd-d.„d.eƒZGd/d0„d0eƒZGd1d2„d2eƒZGd3d4„d4eej ƒZ!Gd5d6„d6eej"ƒZ#Gd7d8„d8eƒZ$Gd9d:„d:e$ƒZ%Gd;d<„d„d>eƒZ(Gd?d@„d@eƒZ)dCdAdB„Z*dS)Da†)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. é)Úabsolute_importN)Ú_)Úshort)ÚerrorÚ logcmdutilÚmailÚpycompatÚ registrarÚurlÚutil)ÚprocutilÚ stringutilsships-with-hg-coreóbugzillaóapikeyó)Údefaultóbzdirs/var/www/html/bugzillaóbzemailóbzurlshttp://localhost/bugzilla/óbzuseródbóbugsó fixregexps˜fix(?:es)?\s*(?:bugs?\s*)?,?\s*(?:nos?\.?|num(?:ber)?s?)?\s*(?P(?:#?\d+\s*(?:,?\s*(?:and)?)?\s*)+)\.?\s*(?:h(?:ours?)?\s*(?P\d*(?:\.\d+)?))?ó fixresolutionsFIXEDó fixstatussRESOLVEDóhosts localhostónotifyópasswordóregexps†bugs?\s*,?\s*(?:#|nos?\.?|num(?:ber)?s?)?\s*(?P(?:\d+\s*(?:,?\s*(?:and)?)?\s*)+)\.?\s*(?:h(?:ours?)?\s*(?P\d*(?:\.\d+)?))?óstripóstyleótemplateótimeoutéóuseróusermapóversionc@s@eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dS)Úbzaccessz"Base class for access to Bugzilla.cCs.||_|j dd¡}|r*|jj|dgddS)Nrr%)Zsections)ÚuiÚconfigZ readconfig)Úselfr(Zusermap©r+ú4/usr/lib64/python3.9/site-packages/hgext/bugzilla.pyÚ__init__¹szbzaccess.__init__cCs2|j d¡D] \}}| ¡| ¡kr |Sq |S)z,map name of committer to Bugzilla user name.r%)r(Z configitemsÚlower)r*ÚuserÚ committerZbzuserr+r+r,Ú map_committer¿s zbzaccess.map_committercCsdS)ú7remove bug IDs that do not exist in Bugzilla from bugs.Nr+)r*Úbugsr+r+r,Úfilter_real_bug_idsÎszbzaccess.filter_real_bug_idscCsdS)ú;remove bug IDs where node occurs in comment text from bugs.Nr+)r*Únoder3r+r+r,Úfilter_cset_known_bug_idsÑsz"bzaccess.filter_cset_known_bug_idscCsdS)úË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*ÚbugidÚnewstateÚtextr0r+r+r,Ú updatebugÔszbzaccess.updatebugcCsdS©zŸForce sending of Bugzilla notification emails. Only required if the access method does not trigger notification emails automatically. Nr+©r*r3r0r+r+r,ÚnotifyÛszbzaccess.notifyN) Ú__name__Ú __module__Ú __qualname__Ú__doc__r-r1r4r7r<r?r+r+r+r,r'¶sr'c@sheZdZdZedd„ƒZdZdd„Zdd„Zd d „Z d d „Z d d„Z dd„Z dd„Z dd„Zdd„ZdS)ÚbzmysqlzòSupport 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. cCsdd tt|ƒ¡dS)z#return SQL-friendly list of bug idsó(ó,ó))ÚjoinÚmapÚstr)Úidsr+r+r,Ú sql_buglistíszbzmysql.sql_buglistNc Cszddl}|t_Wn6tyH}zt tdƒ|¡‚WYd}~n d}~00t ||¡|j   dd¡}|j   dd¡}|j   dd¡}|j   dd¡}t |j   dd¡ƒ}|j   td ƒ|||d t |ƒf¡tjj|||||d |_|j ¡|_| ¡|_i|_d |_dS) Nrs&python mysql support not available: %srrr$rrr"s'connecting to %s:%s as %s, password %s ó*)Úhostr/ÚpasswdÚdbZconnect_timeouts-cd %(bzdir)s && ./processmail %(id)s %(user)s)ZMySQLdbrDÚ_MySQLdbÚ ImportErrorrÚAbortrr'r-r(r)ÚintÚnoteÚlenÚconnectÚconnÚcursorÚget_longdesc_idÚ longdesc_idÚuser_idsÚdefault_notify) r*r(ZmysqlÚerrrNr/rOrPÚtimeoutr+r+r,r-ôs2  ÿ ÿÿ ÿ  zbzmysql.__init__cOsd|j tdƒ||f¡z|jj|i|¤ŽWn0tjjy^|j tdƒ||f¡‚Yn0dS)z run a query.s query: %s %s sfailed query: %s %s N)r(rUrrYZexecuterDrQZ MySQLError)r*ÚargsÚkwargsr+r+r,Úruns z bzmysql.runcCs:| d¡|j ¡}t|ƒdkr.t tdƒ¡‚|ddS)úget identity of longdesc fields5select fieldid from fielddefs where name = "longdesc"éóunknown database schemar©rbrYÚfetchallrVrrSr©r*rKr+r+r,rZs    zbzmysql.get_longdesc_idcCs`| dt | ¡¡¡dd„|j ¡Dƒ}| ¡D]&}||vr4|j tdƒ|¡||=q4dS)z"filter not-existing bugs from set.s*select bug_id from bugs where bug_id in %scSsg|] \}|‘qSr+r+)Ú.0Úidr+r+r,Ú (rz/bzmysql.filter_real_bug_ids..óbug %d does not exist N) rbrDrLÚkeysrYrgr(Ústatusr)r*r3Úexistingrjr+r+r,r4"s ÿÿ zbzmysql.filter_real_bug_idscCsX| dt | ¡¡t|ƒf¡|j ¡D](\}|j t dƒ|t|ƒf¡||=q*dS)z=filter bug ids that already refer to this changeset from set.z]select bug_id from longdescs where bug_id in %s and thetext like "%%%s%%"ó(bug %d already knows about changeset %s N) rbrDrLrmrrYrgr(rnr©r*r6r3rjr+r+r,r7.sþÿ ÿÿz!bzmysql.filter_cset_known_bug_idsc Cs|j tdƒ¡| |¡\}}| ¡D]Ê}|j tdƒ|¡|j dd|j¡}|j dd¡}z ||}Wn"tyŒ||||dœ}Yn0|j tdƒ|¡t   d|d ¡} t   |   ¡¡} |  ¡} | r&|j | ¡t td ƒt  | ¡¡‚q&|j td ƒ¡d S) ztell bugzilla to send mail.stelling bugzilla to send mail: s bug %s rrr)róidr$srunning notify command %s s (%s) 2>&1srbsbugzilla notify command %ssdone N)r(rnrÚget_bugzilla_userrmr)r]Ú TypeErrorrUr Úpopenr Z fromnativeeolÚreadÚcloseÚwarnrrSZ explainexit) r*r3r0r/ÚuseridrjZcmdfmtZbzdirÚcmdÚfpÚoutÚretr+r+r,r?<s(    ÿzbzmysql.notifyc Cs z |j|WStyšz t|ƒ}Wn`ty†|j tdƒ|¡| d|¡|j  ¡}t |ƒdkrrt|ƒ‚t|ddƒ}Yn0||j|<|YS0dS)z!look up numeric bugzilla user id.slooking up user %s zPselect userid from profiles where login_name like %srdrN) r\ÚKeyErrorrTÚ ValueErrorr(rUrrbrYrgrV)r*r/ryÚallr+r+r,Ú get_user_idVs"    ý   zbzmysql.get_user_idc Cs”| |¡}z| |¡}WnrtyŠz6|j dd¡}|sLt tdƒ|¡‚| |¡}|}Wn(ty„t tdƒ||f¡‚Yn0Yn0||fS)zŸSee 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)r1rr~r(r)rrSr)r*r0r/ryZ defaultuserr+r+r,rsks&   ÿ  ÿÿzbzmysql.get_bugzilla_usercCslt|ƒdkr|j tdƒ¡| |¡\}}t d¡}| d||||f¡| d||||jf¡|j   ¡dS)z†update 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) rVr(rxrrsÚtimeÚstrftimerbr[rXZcommit)r*r9r:r;r0r/ryZnowr+r+r,r<‚s   ü ýzbzmysql.updatebug)r@rArBrCÚ staticmethodrLrQr-rbrZr4r7r?rrsr<r+r+r+r,rDäs   rDc@seZdZdZdd„ZdS)Ú bzmysql_2_18z!support for bugzilla 2.18 series.cCst ||¡d|_dS)Ns>cd %(bzdir)s && perl -T contrib/sendbugmail.pl %(id)s %(user)s)rDr-r]©r*r(r+r+r,r-s ÿzbzmysql_2_18.__init__N)r@rArBrCr-r+r+r+r,r…šsr…c@s eZdZdZdd„Zdd„ZdS)Ú bzmysql_3_0z support for bugzilla 3.0 series.cCst ||¡dS)N)r…r-r†r+r+r,r-§szbzmysql_3_0.__init__cCs:| d¡|j ¡}t|ƒdkr.t tdƒ¡‚|ddS)rcs0select id from fielddefs where name = "longdesc"rdrerrfrhr+r+r,rZªs    zbzmysql_3_0.get_longdesc_idN)r@rArBrCr-rZr+r+r+r,r‡¤sr‡c@s&eZdZdZgZdd„Zddd„ZdS) Úcookietransportrequesta–A 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. cCs"|jr|jD]}| d|¡q dS)NsCookie)ÚcookiesZ putheader)r*Z connectionÚcookier+r+r,Ú send_cookiesÈs z#cookietransportrequest.send_cookiesrc Cs||_d|_| |¡}|r$| d¡| |||¡| ||¡| |¡| |¡| ||¡z |  ¡}Wnt y†|j   ¡}Yn0|j   d¡D]0}| dd¡d}| dd¡d} |j | ¡q”|jdkrìt |||j|j|j j¡‚| ¡} | ¡\} } |  | ¡|  ¡|  ¡S)NFrds Set-Cookies: ó;réÈ)ÚverboseZaccept_gzip_encodingZmake_connectionZset_debuglevelZ send_requestZ send_hostr‹Zsend_user_agentZ send_contentZ getresponseÚAttributeErrorZ_connÚmsgZgetallmatchingheadersÚsplitr‰ÚappendrnÚ xmlrpclibZ ProtocolErrorÚreasonZheadersrvZ getparserZfeedrw) r*rNZhandlerZ request_bodyrŽÚhZresponseÚheaderÚvalrŠZpayloadÚparserZ unmarshallerr+r+r,ÚrequestÍs<         ü  zcookietransportrequest.requestN)r)r@rArBrCr‰r‹r™r+r+r+r,rˆ¶srˆc@seZdZddd„ZdS)ÚcookietransportrcCs t tjd¡rtj ||¡dS©Nr-)r Ú safehasattrr“Ú Transportr-©r*Z use_datetimer+r+r,r-szcookietransport.__init__N)r©r@rArBr-r+r+r+r,ršsršc@seZdZddd„ZdS)ÚcookiesafetransportrcCs t tjd¡rtj ||¡dSr›)r rœr“rÚ SafeTransportr-ržr+r+r,r-szcookiesafetransport.__init__N)rrŸr+r+r+r,r sr c@s@eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dS)ÚbzxmlrpcznSupport for access to Bugzilla via the Bugzilla XMLRPC API. Requires a minimum Bugzilla version 3.4. cCsØt ||¡|j dd¡}| d¡d}|j dd¡}|j dd¡}|j dd¡|_|j dd¡|_t t   |¡|  |¡¡|_ |j j  ¡d  d ¡}t|d ƒ|_t|d ƒ|_|j j ||d dœ¡}| dd¡|_dS)Nrró/s /xmlrpc.cgir$rrrr&ó.rrdT)óloginrsrestrict_loginótokenr)r'r-r(r)ÚrstripÚ fixstatusÚ fixresolutionr“Z ServerProxyrZstrurlÚ transportÚbzproxyZBugzillaÚversionr‘rTÚ bzvermajorZ bzverminorÚUserÚloginÚgetÚbztoken)r*r(Zbzwebr/rOZverr¯r+r+r,r-s" ÿ ÿzbzxmlrpc.__init__cCs&tj |d¡ddkrtƒStƒSdS)Nshttprshttps)r ÚurlreqÚurlparser rš)r*Zurir+r+r,rª)szbzxmlrpc.transportcCs@|jj |gdg|jdœ¡}d dd„|dd|dDƒ¡S) z0Return a string with all comment text for a bug.ótext)óidsóinclude_fieldsr¦rcSsg|] }|d‘qS)r´r+©riÚtr+r+r,rk5rz-bzxmlrpc.get_bug_comments..rs%dócomments)r«ÚBugÚcommentsr±rH)r*rjÚcr+r+r,Úget_bug_comments/s ÿÿzbzxmlrpc.get_bug_commentscCsV|jj t| ¡ƒgd|jdœ¡}|dD]&}|d}|j tdƒ|¡||=q*dS)NT)rµr¶s permissiver¦sfaultsrrrl) r«rºr°Úsortedrmr±r(rnr)r*r3ZprobeZbadbugrjr+r+r,r48s üÿ zbzxmlrpc.filter_real_bug_idscCsPt| ¡ƒD]>}| |¡ t|ƒ¡dkr |j tdƒ|t|ƒf¡||=q dS)Néÿÿÿÿrp)r¾rmr½Úfindrr(rnrrqr+r+r,r7Fs ÿÿz"bzxmlrpc.filter_cset_known_bug_idscCs¨i}d|vr|d|d<|jdkrn|g|d<d|i|d<d|vrT|j|d<|j|d <|j|d <|jj |¡n6d|vr†|j t d ƒ¡||d <||d<|jj  |¡dS) Nóhoursó work_timeérµsbodyócommentófixóstatusó resolutionr¦s?Bugzilla/XMLRPC needs Bugzilla 4.0 or later to mark bugs fixed rr) r­r¨r©r±r«rºÚupdater(rxrZ add_comment)r*r9r:r;r0r`r+r+r,r<Os(       ÿÿzbzxmlrpc.updatebugN) r@rArBrCr-rªr½r4r7r<r+r+r+r,r¢ s  r¢c@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) Ú bzxmlrpcemailaã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. 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. cCs@t ||¡|j dd¡|_|js0t tdƒ¡‚t  |j¡dS)Nrrsconfiguration 'bzemail' missing) r¢r-r(r)ÚbzemailrrSrrZvalidateconfigr†r+r+r,r-}s  zbzxmlrpcemail.__init__cCs>|jdkrd|t |¡fS|dkr(d}d|t |¡fSdS)NrÃs@%s %srrsbug_ids@%s = %s)r­rÚbytestr)r*Z fieldnameÚvaluer+r+r,Úmakecommandline…s  zbzxmlrpcemail.makecommandlinec Cs | |¡}|jj |g|jdœ¡}|dsj|j dd¡}|jj |g|jdœ¡}|dsjt t dƒ|¡‚|ddd}|  |  d|¡¡d   |¡d |}t  |j¡}t  |j||¡}t  |j|j|¡} t  |j||¡} || d <| | d <t  |jd |¡| d<t  |j¡} | || |  ¡ƒdS)a©send 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. )smatchr¦susersrr$s(default bugzilla user %s email not foundrsemailrró s sFromsTosBug modificationsSubjectN)r1r«r®r°r±r(r)rrSrr’rÍrHrÚ _charsetsZ addressencoderÊZ mimeencodeZ headencoderWZ as_string) r*r9ZcommandsZcommentr0r/Úmatchesr;rÏrÊrZsendmailr+r+r,Úsend_bug_modify_emails6  ÿ ÿ ÿ ÿ z#bzxmlrpcemail.send_bug_modify_emailcCsfg}d|vr"| | d|d¡¡d|vrR| | d|j¡¡| | d|j¡¡| ||||¡dS)NrÁrÂrÅs bug_statusrÇ)r’rÍr¨r©rÑ)r*r9r:r;r0Zcmdsr+r+r,r<¶szbzxmlrpcemail.updatebugN)r@rArBrCr-rÍrÑr<r+r+r+r,rÉis )rÉc@s eZdZdS)ÚNotFoundN)r@rArBr+r+r+r,rÒÀsrÒc@sTeZdZdZdd„Zddd„Zdd„Zdd d „Zd d „Zdd„Z dd„Z dd„Z dS)Ú bzrestapizVRead and write bugzilla data using the REST API available since Bugzilla 5.0. cCs~t ||¡|j dd¡}d |dg¡|_|j dd¡|_|j dd¡|_|j dd¡|_|j dd¡|_ |j dd ¡|_ dS) Nrrr£srestrr$rrr) r'r-r(r)rHÚbzrootÚapikeyr/rOr¨r©)r*r(Úbzr+r+r,r-És zbzrestapi.__init__NcCszd |jgdd„|Dƒ¡}i}|jr2|j|d<n |jrR|jrR|j|d<|j|d<|r^||d<|rvd|tj |¡f}|S) Nr£cSsg|]}t |¡‘qSr+)rrËr·r+r+r,rkÔrz$bzrestapi.apiurl..sapi_keyr¥rr¶s%s?%s)rHrÔrÕr/rOr r²Ú urlencode)r*ÚtargetsÚinclude_fieldsr Zqvr+r+r,ÚapiurlÓs    zbzrestapi.apiurlc Csxzt |j|¡}t | ¡¡WStjjyr}z8|j dkrJt   t dƒ¡‚|j dkr\t ƒ‚n‚WYd}~n d}~00dS)Né‘óauthorization failedé”)r Úopenr(rÚ json_loadsrvr ÚurlerrÚ httperrorÚcoderrSrrÒ)r*ÚburlÚrespÚinstr+r+r,Ú_fetchás  zbzrestapi._fetchóPOSTc CsÀt |¡}|dkr,Gdd„dtjjƒ}|}ntjj}|||ddiƒ}z"t |j¡ |¡}t   |  ¡¡WStj j yº}z8|jdkr’t tdƒ¡‚|jdkr¤tƒ‚n‚WYd}~n d}~00dS) NóPUTc@seZdZdd„ZdS)z%bzrestapi._submit..putrequestcSsdS)Nrèr+©r*r+r+r,Ú get_methodòsz0bzrestapi._submit..putrequest.get_methodN)r@rArBrêr+r+r+r,Ú putrequestñsrës Content-Typesapplication/jsonrÛrÜrÝ)ÚjsonÚdumpsr r²r™r Úopenerr(rÞrrßrvràrárârrSrrÒ) r*rãÚdataÚmethodrëZ request_typeZreqrärår+r+r,Ú_submitís   zbzrestapi._submitc Csbtƒ}|D]B}|jd|fdd}z| |¡Wq tyJ| |¡Yq 0q |D] }||=qRdS)r2óbugrÆ©rÙN)ÚsetrÚrærÒÚadd)r*r3Zbadbugsr9rãr+r+r,r4s zbzrestapi.filter_real_bug_idscs‚t|ƒ‰| ¡D]l}|jd|dfdd}| |¡}|dt |¡d}t‡fdd„|Dƒƒr|j t d ƒ|ˆf¡||=qd S) r5ròrÄr´rórr¹c3s|]}ˆ|dvVqdS)r´Nr+)rir¼©Zsnr+r,Ú rz6bzrestapi.filter_cset_known_bug_ids..rpN) rrmrÚrærrËÚanyr(rnr)r*r6r3r9rãÚresultr»r+rör,r7s  ÿ ÿÿz#bzrestapi.filter_cset_known_bug_idscCs°i}d|vr|d|d<d|vr4|j|d<|j|d<|rx|dddœ|d<| d |f¡}|j||d d |j d |¡n4| d |df¡}| ||dddœ¡|j d |¡dS)r8rÁrÂrÅrÆrÇF)rÄs is_privates is_markdownrÄròrè)rðsupdated bug %s sadded comment to bug %s N)r¨r©rÚrñr(Údebug)r*r9r:r;r0Zbugmodrãr+r+r,r< s.   ý ýþzbzrestapi.updatebugcCsdSr=r+r>r+r+r,r?Bszbzrestapi.notify)N)rç) r@rArBrCr-rÚrærñr4r7r<r?r+r+r+r,rÓÄs   "rÓc@s>eZdZeeeeeedœZ dd„Z dd„Z dd„Z dd „Z d S) Úbugzilla)s2.16s2.18s3.0sxmlrpcs xmlrpc+emailsrestapicCsž||_||_|j dd¡}ztj|}Wn$tyLt tdƒ|¡‚Yn0||jƒ|_ t   |j dd¡t j ¡|_ t   |j dd¡t j ¡|_t   d¡|_dS)Nrr&s!bugzilla version %s not supportedrrs\D+)r(Úrepor)rûÚ _versionsr~rrSrÚbzdriverÚreÚcompileÚ IGNORECASEÚbug_reÚfix_reÚsplit_re)r*r(rüZ bzversionZbzclassr+r+r,r-Ws"  ÿ  ÿÿzbugzilla.__init__c Csªd}i}|j | ¡|¡}|j | ¡|¡}i}|s<|s<q||sF|}n$|sP|}n| ¡| ¡krf|}n|}| ¡}||urœ|j | ¡|¡}d|vr¶|d=n|j | ¡|¡}d|d<z| d¡}Wntyà| d¡}Yn0zt| d¡ƒ} | |d<WnRtyYn@t y"Yn.t yN|j   t dƒ| d¡¡Yn0|j |¡D]} | sjq\||t| ƒ<q\q,|rŽ|j |¡|r¦|j | ¡|¡|S)zþreturn 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. rrÅNrµrdrÁs%s: invalid hours )rÚsearchÚ descriptionrÚstartÚendÚgroupÚ IndexErrorÚfloatrtrr(rnrrr‘rTrþr4r7r6) r*Úctxrr3ZbugmatchZfixmatchZ bugattribsÚmrKZhoursrjr+r+r,Ú find_bugslsV    zbugzilla.find_bugsc sȇfdd„}d}ˆj dd¡}|s0ˆj dd¡}|s@|s@tdƒ}t ||¡}t ˆjˆj|¡}ˆj ¡|j||  ¡t   |¡ˆj dd ¡ˆjj |ˆjj ƒd ˆj  ¡} ˆj ||| t | ¡¡¡dS) z0update bugzilla bug with reference to changeset.csVtˆj dd¡ƒ}t |¡}|dkrR| d¡}|dkr8qR||dd…}|d8}q|S)zJstrip leading prefix of repo root and turn into url-safe path.rrrr£r¿rdN)rTr(r)r ZpconvertrÀ)ÚrootÚcountr¼rér+r,Úwebroot¨s   z bugzilla.update..webrootNrr!r sUchangeset {node|short} in repo {root} refers to bug {bug}. details: {desc|tabindent}swebsbaseurl)ZchangesÚbugZhgwebrr)r(r)rrZ templatespecZchangesettemplaterrüZ pushbufferZshowZ changesetrrËrZ popbufferrþr<r Úemailr/) r*r9r:r rZmapfileZtmplÚspecr¸rïr+rér,rÈ¥s0 ÿ    ú ÿzbugzilla.updatecCs|j ||¡dS)z1ensure Bugzilla users are notified of bug change.N)rþr?r>r+r+r,r?Îszbugzilla.notifyN)r@rArBrDr…r‡r¢rÉrÓrýr-rrÈr?r+r+r+r,rûKsú 9)rûc Ks²|durt tdƒ|¡‚zVt||ƒ}||}| |¡}|rn|D]}| ||||¡q@| |t |  ¡¡¡Wn<t y¬} z$t tdƒt  | ¡¡‚WYd} ~ n d} ~ 00dS)z¿add 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) rrSrrûrrÈr?r rr/Ú ExceptionZ forcebytestr) r(rüZhooktyper6rarÖr r3rÚer+r+r,ÚhookÓs ÿ  r)N)+rCZ __future__rrìrÿr‚Zmercurial.i18nrZmercurial.noderZ mercurialrrrrr r r Zmercurial.utilsr r r“Z testedwithZ configtableZ configitemZdynamicdefaultÚobjectr'rDr…r‡rˆrršr¡r r¢rÉÚ LookupErrorrÒrÓrûrr+r+r+r,Ú s   $  ýýýýýýü ýýýýýü ýýýýýýý.7 J]W