
    ~j%0                        d Z ddlmZ ddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ed         Ze G d	 d
                      Ze G d de                      Z G d de          Ze G d d                      Ze G d de                      Ze G d de                      Ze G d de                      Ze G d de                      ZdedefdZdS )a  
Data structures to interact with Discussions and Pull Requests on the Hub.

See [the Discussions and Pull Requests guide](https://huggingface.co/docs/hub/repositories-pull-requests-discussions)
for more information on Pull Requests, Discussions, and the community tab.
    )	dataclass)datetime)Literal	TypedDict   )	constants)parse_datetime)openclosedmergeddraftc                       e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   eed<   e	ed	<   eed
<   e
dedz  fd            Ze
defd            ZdS )
Discussiona  
    A Discussion or Pull Request on the Hub.

    This dataclass is not intended to be instantiated directly.

    Attributes:
        title (`str`):
            The title of the Discussion / Pull Request
        status (`str`):
            The status of the Discussion / Pull Request.
            It must be one of:
                * `"open"`
                * `"closed"`
                * `"merged"` (only for Pull Requests )
                * `"draft"` (only for Pull Requests )
        num (`int`):
            The number of the Discussion / Pull Request.
        repo_id (`str`):
            The id (`"{namespace}/{repo_name}"`) of the repo on which
            the Discussion / Pull Request was open.
        repo_type (`str`):
            The type of the repo on which the Discussion / Pull Request was open.
            Possible values are: `"model"`, `"dataset"`, `"space"`.
        author (`str`):
            The username of the Discussion / Pull Request author.
            Can be `"deleted"` if the user has been deleted since.
        is_pull_request (`bool`):
            Whether or not this is a Pull Request.
        created_at (`datetime`):
            The `datetime` of creation of the Discussion / Pull Request.
        endpoint (`str`):
            Endpoint of the Hub. Default is https://huggingface.co.
        git_reference (`str`, *optional*):
            (property) Git reference to which changes can be pushed if this is a Pull Request, `None` otherwise.
        url (`str`):
            (property) URL of the discussion on the Hub.
    titlestatusnumrepo_id	repo_typeauthoris_pull_request
created_atendpointreturnNc                 (    | j         r
d| j         S dS )z
        If this is a Pull Request , returns the git reference to which changes can be pushed.
        Returns `None` otherwise.
        zrefs/pr/N)r   r   selfs    i/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/huggingface_hub/community.pygit_referencezDiscussion.git_referenceE   s$      	)(dh(((t    c                     | j         | j         t          j        k    r| j         d| j         d| j         S | j         d| j          d| j         d| j         S )z-Returns the URL of the discussion on the Hub.N/z/discussions/zs/)r   r   REPO_TYPE_MODELr   r   r   r   s    r   urlzDiscussion.urlO   si     >!T^y7P%P%PmKKdlKKKKK-YY$.YYDLYYtxYYYr   )__name__
__module____qualname____doc__str__annotations__DiscussionStatusintboolr   propertyr   r#    r   r   r   r      s         $ $L JJJ	HHHLLLNNNKKKMMMsTz    X ZS Z Z Z XZ Z Zr   r   c                   |    e Zd ZU dZed         ed<   ee         ez  dz  ed<   edz  ed<   edz  ed<   edz  ed<   dS )	DiscussionWithDetailsa7	  
    Subclass of [`Discussion`].

    Attributes:
        title (`str`):
            The title of the Discussion / Pull Request
        status (`str`):
            The status of the Discussion / Pull Request.
            It can be one of:
                * `"open"`
                * `"closed"`
                * `"merged"` (only for Pull Requests )
                * `"draft"` (only for Pull Requests )
        num (`int`):
            The number of the Discussion / Pull Request.
        repo_id (`str`):
            The id (`"{namespace}/{repo_name}"`) of the repo on which
            the Discussion / Pull Request was open.
        repo_type (`str`):
            The type of the repo on which the Discussion / Pull Request was open.
            Possible values are: `"model"`, `"dataset"`, `"space"`.
        author (`str`):
            The username of the Discussion / Pull Request author.
            Can be `"deleted"` if the user has been deleted since.
        is_pull_request (`bool`):
            Whether or not this is a Pull Request.
        created_at (`datetime`):
            The `datetime` of creation of the Discussion / Pull Request.
        events (`list` of [`DiscussionEvent`])
            The list of [`DiscussionEvents`] in this Discussion or Pull Request.
        conflicting_files (`Union[list[str], bool, None]`, *optional*):
            A list of conflicting files if this is a Pull Request.
            `None` if `self.is_pull_request` is `False`.
            `True` if there are conflicting files but the list can't be retrieved.
        target_branch (`str`, *optional*):
            The branch into which changes are to be merged if this is a
            Pull Request . `None`  if `self.is_pull_request` is `False`.
        merge_commit_oid (`str`, *optional*):
            If this is a merged Pull Request , this is set to the OID / SHA of
            the merge commit, `None` otherwise.
        diff (`str`, *optional*):
            The git diff if this is a Pull Request , `None` otherwise.
        endpoint (`str`):
            Endpoint of the Hub. Default is https://huggingface.co.
        git_reference (`str`, *optional*):
            (property) Git reference to which changes can be pushed if this is a Pull Request, `None` otherwise.
        url (`str`):
            (property) URL of the discussion on the Hub.
    DiscussionEventeventsNconflicting_filestarget_branchmerge_commit_oiddiff)r$   r%   r&   r'   listr)   r(   r,   r.   r   r   r0   r0   W   s{         0 0d "####Cy4'$....:Dj   
*r   r0   c                   B    e Zd ZU eed<   eed<   eed<   eed<   eed<   dS )DiscussionEventArgsidtyper   r   _eventN)r$   r%   r&   r(   r)   r   dictr.   r   r   r9   r9      s@         GGG
IIIKKKLLLLLr   r9   c                   F    e Zd ZU dZeed<   eed<   eed<   eed<   eed<   dS )r1   a  
    An event in a Discussion or Pull Request.

    Use concrete classes:
        * [`DiscussionComment`]
        * [`DiscussionStatusChange`]
        * [`DiscussionCommit`]
        * [`DiscussionTitleChange`]

    Attributes:
        id (`str`):
            The ID of the event. An hexadecimal string.
        type (`str`):
            The type of the event.
        created_at (`datetime`):
            A [`datetime`](https://docs.python.org/3/library/datetime.html?highlight=datetime#datetime.datetime)
            object holding the creation timestamp for the event.
        author (`str`):
            The username of the Discussion / Pull Request author.
            Can be `"deleted"` if the user has been deleted since.
    r:   r;   r   r   r<   N)r$   r%   r&   r'   r(   r)   r   r=   r.   r   r   r1   r1      sN          , 	GGG
IIIKKKLLLMMr   r1   c                       e Zd ZU dZeed<   eed<   eed<   edefd            Zede	fd            Z
edefd            Zedee         fd	            Zedefd
            ZdS )DiscussionCommentaz  A comment in a Discussion / Pull Request.

    Subclass of [`DiscussionEvent`].


    Attributes:
        id (`str`):
            The ID of the event. An hexadecimal string.
        type (`str`):
            The type of the event.
        created_at (`datetime`):
            A [`datetime`](https://docs.python.org/3/library/datetime.html?highlight=datetime#datetime.datetime)
            object holding the creation timestamp for the event.
        author (`str`):
            The username of the Discussion / Pull Request author.
            Can be `"deleted"` if the user has been deleted since.
        content (`str`):
            The raw markdown content of the comment. Mentions, links and images are not rendered.
        edited (`bool`):
            Whether or not this comment has been edited.
        hidden (`bool`):
            Whether or not this comment has been hidden.
    contenteditedhiddenr   c                 4    | j         d         d         d         S )z&The rendered comment, as a HTML stringdatalatesthtmlr<   r   s    r   renderedzDiscussionComment.rendered   s     {6"8,V44r   c                 N    t          | j        d         d         d                   S )+The last edit time, as a `datetime` object.rE   rF   	updatedAt)r	   r<   r   s    r   last_edited_atz DiscussionComment.last_edited_at   s#     dk&1(;KHIIIr   c                 x    | j         d         d                             di                               dd          S )rK   rE   rF   r   namedeleted)r<   getr   s    r   last_edited_byz DiscussionComment.last_edited_by   s6     {6"8,002>>BB69UUUr   c                 (    | j         d         d         S )zThe edit history of the commentrE   historyrH   r   s    r   edit_historyzDiscussionComment.edit_history   s     {6"9--r   c                 *    t          | j                  S )N)lenrU   r   s    r   number_of_editsz!DiscussionComment.number_of_edits   s    4$%%%r   N)r$   r%   r&   r'   r(   r)   r,   r-   rI   r   rM   rR   r7   r=   rU   r+   rX   r.   r   r   r@   r@      s         0 LLLLLLLLL5# 5 5 5 X5 J J J J XJ V V V V XV .d4j . . . X. & & & & X& & &r   r@   c                       e Zd ZU dZeed<   dS )DiscussionStatusChangeaV  A change of status in a Discussion / Pull Request.

    Subclass of [`DiscussionEvent`].

    Attributes:
        id (`str`):
            The ID of the event. An hexadecimal string.
        type (`str`):
            The type of the event.
        created_at (`datetime`):
            A [`datetime`](https://docs.python.org/3/library/datetime.html?highlight=datetime#datetime.datetime)
            object holding the creation timestamp for the event.
        author (`str`):
            The username of the Discussion / Pull Request author.
            Can be `"deleted"` if the user has been deleted since.
        new_status (`str`):
            The status of the Discussion / Pull Request after the change.
            It can be one of:
                * `"open"`
                * `"closed"`
                * `"merged"` (only for Pull Requests )
    
new_statusNr$   r%   r&   r'   r(   r)   r.   r   r   rZ   rZ      s%          . OOOOOr   rZ   c                   (    e Zd ZU dZeed<   eed<   dS )DiscussionCommita  A commit in a Pull Request.

    Subclass of [`DiscussionEvent`].

    Attributes:
        id (`str`):
            The ID of the event. An hexadecimal string.
        type (`str`):
            The type of the event.
        created_at (`datetime`):
            A [`datetime`](https://docs.python.org/3/library/datetime.html?highlight=datetime#datetime.datetime)
            object holding the creation timestamp for the event.
        author (`str`):
            The username of the Discussion / Pull Request author.
            Can be `"deleted"` if the user has been deleted since.
        summary (`str`):
            The summary of the commit.
        oid (`str`):
            The OID / SHA of the commit, as a hexadecimal string.
    summaryoidNr\   r.   r   r   r^   r^     s.          * LLL	HHHHHr   r^   c                   (    e Zd ZU dZeed<   eed<   dS )DiscussionTitleChangea  A rename event in a Discussion / Pull Request.

    Subclass of [`DiscussionEvent`].

    Attributes:
        id (`str`):
            The ID of the event. An hexadecimal string.
        type (`str`):
            The type of the event.
        created_at (`datetime`):
            A [`datetime`](https://docs.python.org/3/library/datetime.html?highlight=datetime#datetime.datetime)
            object holding the creation timestamp for the event.
        author (`str`):
            The username of the Discussion / Pull Request author.
            Can be `"deleted"` if the user has been deleted since.
        old_title (`str`):
            The previous title for the Discussion / Pull Request.
        new_title (`str`):
            The new title.
    	old_title	new_titleNr\   r.   r   r   rb   rb   )  s.          * NNNNNNNNr   rb   eventr   c                 H   | d         }| d         }t          | d                   }||||                     di                               dd          | d}|dk    r<t          di || d	         d
         | d	         d         | d	         d         d         dS |dk    rt          di |d| d	         d         iS |dk    r)t	          di || d	         d         | d	         d         dS |dk    r)t          di || d	         d         | d	         d         dS t          di |S )z.Instantiates a [`DiscussionEvent`] from a dictr:   r;   	createdAtr   rO   rP   )r:   r;   r   r   r<   commentrE   rB   rC   rF   raw)rB   rC   rA   zstatus-changer[   r   commitsubjectr`   )r_   r`   ztitle-changefromto)rc   rd   r.   )r	   rQ   r@   rZ   r^   rb   r1   )re   event_id
event_typer   common_argss        r   deserialize_eventrq   D  s   $KHFmJk 233J  ))Hb))--fi@@( (K Y  
 

=*=*&M(+E2	
 
 
 
 	
 _$$% 
 

 
V}X.
 
 
 	
 X 
 

&M),fe$
 
 
 
 	

 ^##$ 
 

FmF+FmD)
 
 
 
 	
 ))[)))r   N)r'   dataclassesr   r   typingr   r    r   utilsr	   r*   r   r0   r9   r1   r@   rZ   r^   rb   r=   rq   r.   r   r   <module>rv      sg    " ! ! ! ! !       % % % % % % % %       ! ! ! ! ! ! >?  @Z @Z @Z @Z @Z @Z @Z @ZF 7 7 7 7 7J 7 7 7t    )    N N N N N N N N@ 3& 3& 3& 3& 3& 3& 3& 3&l     _   6        4     O   4'*T '*o '* '* '* '* '* '*r   