https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/tracopt/ticket/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/tracopt/ticket/__pycache__/commit_updater.cpython-310.pyc
o

�k�`�4�@sddlZddlZddlmZmZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZdd
lmZmZddlmZddlmZdd
lmZmZddlmZm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&Gdd�de�Z'Gdd�de&�Z(dS)�N)�
BoolOption�Option)�	Component�
implements)�NotificationSystem)�PermissionCache)�Resource)�Ticket)�TicketChangeEvent)�as_int)�datetime_now�utc)�tag)�exception_to_unicode)�_�	cleandoc_)�IRepositoryChangeListener�RepositoryManager)�ChangesetModule)�format_to_html)�
WikiMacroBasec@s�eZdZdZee�edddd�Zedddd�Zedd	d
d�Z	e
ddd
d�Ze
ddd
d�ZdZ
e
dZdeefZedd��Ze�e
d�ZdZdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Z dS).�CommitTicketUpdatera�Update tickets based on commit messages.

    This component hooks into changeset notifications and searches commit
    messages for text in the form of:
    {{{
    command #1
    command #1, #2
    command #1 & #2
    command #1 and #2
    }}}

    Instead of the short-hand syntax "#1", "ticket:1" can be used as well,
    e.g.:
    {{{
    command ticket:1
    command ticket:1, ticket:2
    command ticket:1 & ticket:2
    command ticket:1 and ticket:2
    }}}

    Using the long-form syntax allows a comment to be included in the
    reference, e.g.:
    {{{
    command ticket:1#comment:1
    command ticket:1#comment:description
    }}}

    In addition, the ':' character can be omitted and issue or bug can be used
    instead of ticket.

    You can have more than one command in a message. The following commands
    are supported. There is more than one spelling for each command, to make
    this as user-friendly as possible.

      close, closed, closes, fix, fixed, fixes::
        The specified tickets are closed, and the commit message is added to
        them as a comment.

      references, refs, addresses, re, see::
        The specified tickets are left in their current status, and the commit
        message is added to them as a comment.

    A fairly complicated example of what you can do is with a commit message
    of:

        Changed blah and foo to do this or that. Fixes #10 and #12,
        and refs #12.

    This will close #10 and #12, and add a note to #12.
    �ticket�commit_ticket_update_envelope�z�Require commands to be enclosed in an envelope.

        Must be empty or contain two characters. For example, if set to `[]`,
        then commands must be in the form of `[closes #4]`.z#commit_ticket_update_commands.closez#close closed closes fix fixed fixesz7Commands that close tickets, as a space-separated list.z"commit_ticket_update_commands.refsz addresses re references refs seez�Commands that add a reference, as a space-separated list.

        If set to the special value `<ALL>`, all tickets referenced by the
        message will get a reference to the changeset.� commit_ticket_update_check_perms�truez�Check that the committer has permission to perform the requested
        operations on the referenced tickets.

        This requires that the user names be the same for Trac and repository
        operations.�commit_ticket_update_notifyz7Send ticket change notification when updating a ticket.z(?:#|(?:ticket|issue|bug)[: ]?)z([0-9]+(?:#comment:([0-9]+|description))?zH(?P<action>[A-Za-z]*)\s*.?\s*(?P<ticket>%s(?:(?:[, &]*|[ ]?and[ ]?)%s)*)cCs>t�|jdd��t�|jdd��}}t�||j|�S)Nr��)�re�escape�envelope�compile�ticket_command)�self�begin�end�r(�?/usr/lib/python3/dist-packages/tracopt/ticket/commit_updater.py�
command_re�s�zCommitTicketUpdater.command_rez([0-9]+)NcCs>|�|�rdS|�|j�}|�||�}|�|||tt��dS�N)�
_is_duplicate�_parse_message�message�make_ticket_comment�_update_ticketsrr
)r%�repos�	changeset�tickets�commentr(r(r)�changeset_added�s

z#CommitTicketUpdater.changeset_addedcsp|�|�rdS|�|j�}i�|dur|�|j��t�fdd�|��D��}|�||�}|�|||tt��dS)Nc3s �|]}|d�vr|VqdS)rNr()�.0�each��old_ticketsr(r)�	<genexpr>�s���z9CommitTicketUpdater.changeset_modified.<locals>.<genexpr>)	r,r-r.�dict�itemsr/r0rr
)r%r1r2�
old_changesetr3r4r(r8r)�changeset_modified�s
z&CommitTicketUpdater.changeset_modifiedcCs,|j|j|j|jf}||jkr||_dSdS)NFT)�revr.�author�date�
_last_cset_id)r%r2�cset_idr(r(r)r,�s�
z!CommitTicketUpdater._is_duplicatec
Cs�|j�|�}|��}i}|D]3}|�dd�\}}|�|���}|s+|j��dkr+|j}|rA|j	�
|�D]
}	|�t|	�g��
|�q3q|S)z:Parse the commit message and return the ticket references.�actionrz<ALL>)r*�finditer�_get_functions�group�get�lower�
commands_refs�strip�cmd_refs�	ticket_re�findall�
setdefault�int�append)
r%r.�
cmd_groups�	functionsr3�m�cmd�tkts�func�tkt_idr(r(r)r-�s�z"CommitTicketUpdater._parse_messagecCs^|j}t|�}t|�|��}|jr|d|j7}|d|j7}t�d�|||j||j��fS)z2Create the ticket comment from the changeset data.�/z�            In [changeset:"%s" %s]:
            {{{#!CommitTicketReference repository="%s" revision="%s"
            %s
            }}})r?�str�display_rev�reponame�textwrap�dedentr.rK)r%r1r2r?�	revstring�drevr(r(r)r/�s
��z'CommitTicketUpdater.make_ticket_commentcCs�|�|�}t|j|�}|��D]m\}}|j�d|�d}	zD|jj�+t|j|�}
||
j�}|D]}||
||�dur;d}	q/|	rE|
�	|||�Wd�n1sOwY|	r_|�
|
||j|�Wqty|}
z|j�
d|t|
��WYd}
~
qd}
~
wwdS)z*Update the tickets with the given comment.zUpdating ticket #%dFTNz0Unexpected error while processing ticket #%s: %s)�	_authnamer�envr<�log�debug�db_transactionr	�resource�save_changes�_notifyr@�	Exception�errorr)r%r3r2r4rA�authname�permrX�cmds�saver�ticket_permrU�er(r(r)r0�s6


��������z#CommitTicketUpdater._update_ticketsc
Csn|jsdStd||||�}zt|j��|�WdSty6}z|j�d|jt|��WYd}~dSd}~ww)z"Send a ticket update notification.N�changedz8Failure sending notification on change to ticket #%s: %s)	�notifyr
rrbrircrj�idr)r%rrAr@r4�eventrpr(r(r)rh�s���zCommitTicketUpdater._notifycCsVi}t|�D]"}|�d�sqt||�}t|d|dd�d���D]}|||<q!q|S)z4Create a mapping from commands to command functions.�cmd_�	commands_�Nr)�dir�
startswith�getattr�split)r%rSr7rWrUr(r(r)rF�s

 
�z"CommitTicketUpdater._get_functionscCs |jj�dd�r
|j��S|jS)ziReturns the author of the changeset, normalizing the casing if
        [trac] ignore_author_case is true.�trac�ignore_auth_case)rb�config�getboolr@rI)r%r2r(r(r)ras��zCommitTicketUpdater._authnamecCsV|�|�}|jrd|vr|j�d||j�dSd|d<d|d<|ds)||d<dSdS)	N�
TICKET_MODIFYz0%s doesn't have TICKET_MODIFY permission for #%dF�closed�status�fixed�
resolution�owner)ra�check_permsrc�infors)r%rr2rlrkr(r(r)�	cmd_closes
��zCommitTicketUpdater.cmd_closecCs2|jrd|vr|j�d|�|�|j�dSdSdS)N�
TICKET_APPENDz0%s doesn't have TICKET_APPEND permission for #%dF)r�rcr�rars)r%rr2rlr(r(r)rLs��zCommitTicketUpdater.cmd_refs)!�__name__�
__module__�__qualname__�__doc__rrrr"�commands_closerJrr�rr�
ticket_prefix�ticket_referencer$�propertyr*r r#rMrBr5r>r,r-r/r0rhrFrar�rLr(r(r(r)r;sV3�������
	
rc@s(eZdZdZed�ZejZddd�ZdS)�CommitTicketReferenceMacro�messagesayInsert a changeset message into the output.

    This macro must be called using wiki processor syntax as follows:
    {{{
    {{{
    #!CommitTicketReference repository="reponame" revision="rev"
    }}}
    }}}
    where the arguments are the following:
     - `repository`: the repository containing the changeset
     - `revision`: the revision of the desired changeset
    Ncs|pi}|�d�p
d}|�d�}t|j��|�}z|�|�}Wnty/|}	td|�}
Yn
w|j}	|j}|j	}
|j
j	jdkrat|j
j	j
���rXt�fdd�|j�|	�D��satjtd�dd	�St|j�jr|tjt|j|j
jd
||
d�|	dd
�dd	�Stj|	dd	�S)N�
repositoryr�revisionrc3s�|]	}t|��kVqdSr+)rP)r6rX��resource_idr(r)r:Es��z:CommitTicketReferenceMacro.expand_macro.<locals>.<genexpr>z5(The changeset message doesn't reference this ticket)�hint)�class_r2)�parentT)�escape_newlinesr.)rHrrb�get_repository�
get_changesetrirr.r?rf�context�realmrrs�anyrMrNr�prr�wiki_format_messages�divr�child�pre)r%�	formatter�name�content�argsr\r?r1r2r.rfr(r�r)�expand_macro5s:
�
�
�
��z'CommitTicketReferenceMacro.expand_macror+)	r�r�r��_domainr�_descriptionrrMr�r(r(r(r)r�#s�r�))r r]�trac.configrr�	trac.corerr�trac.notification.apir�	trac.permr�
trac.resourcer�trac.ticketr	�trac.ticket.notificationr
�	trac.utilr�trac.util.datefmtrr
�trac.util.htmlr�trac.util.textr�trac.util.translationrr�trac.versioncontrolrr�$trac.versioncontrol.web_ui.changesetr�trac.wiki.formatterr�trac.wiki.macrosrrr�r(r(r(r)�<module>s*%i

https://t.me/RX1948 - 2025