
    ,OfZq                        d dl mZ d dlmZmZ d dlZd dlZd dlZd dl	Zd dlm
Z
 d dlmZmZmZmZmZmZmZmZ er*d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dl	mZ d dlmZ  G d de      Zy)    )annotations)TYPE_CHECKINGAnyN)Consts)	AttributeNonCompletableGithubObjectNotSetOpt
is_definedis_optionalis_optional_listis_undefined)BranchProtection)Commit)	NamedUser)PaginatedList)RequiredPullRequestReviews)RequiredStatusChecks)Teamc                     e Zd ZdZd%dZed&d       Zed%d       Zed'd       Zed%d       Z	d(dZ
d)dZd*d	Zeeeeeeeeeeeeeeeeeeeeeeef	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+d
Zd(dZd,dZeef	 	 	 	 	 d-dZd(dZd.dZeeeeeeef	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d/dZd(dZd'dZd(dZd(dZd0dZd1dZd2dZd2dZd2dZd3dZd3dZd3dZ d(dZ!d'dZ"d(dZ#d(d Z$d'd!Z%d(d"Z&d(d#Z'y$)4Branchz
    This class represents Branches.

    The reference can be found here
    https://docs.github.com/en/rest/reference/repos#branches

    c                P    | j                  d| j                  j                  i      S )Nname)get__repr___namevalueselfs    -lib/python3.12/site-packages/github/Branch.py__repr__zBranch.__repr__Z   s"    )9)9 :;;    c                .    | j                   j                  S N)_commitr   r   s    r   commitzBranch.commit]   s    ||!!!r!   c                .    | j                   j                  S r#   )r   r   r   s    r   r   zBranch.namea   s    zzr!   c                .    | j                   j                  S r#   )
_protectedr   r   s    r   	protectedzBranch.protectede   s    $$$r!   c                .    | j                   j                  S r#   )_protection_urlr   r   s    r   protection_urlzBranch.protection_urli   s    ##)))r!   c                    t         j                  j                  | _        t         j                  j                  | _        t         j                  j                  | _        t         j                  j                  | _        y r#   )githubGithubObjectr	   r$   r   r+   r(   r   s    r   _initAttributeszBranch._initAttributesm   sO    *0*=*=*D*D%+%8%8%?%?
/5/B/B/I/I+1+>+>+E+Er!   c                    d|v r2| j                  t        j                  j                  |d         | _        d|v r| j	                  |d         | _        d|v r| j	                  |d         | _        d|v r| j                  |d         | _        y y )Nr%   r   r,   r)   )	_makeClassAttributer.   r   r$   _makeStringAttributer   r+   _makeBoolAttributer(   )r   
attributess     r   _useAttributeszBranch._useAttributess   s    z!33FMM4H4H*U]J^_DLZ22:f3EFDJz)#'#<#<ZHX=Y#ZD *$"55j6MNDO %r!   c                    | j                   j                  d| j                  dt        j                  i      \  }}t
        j                  j                  | j                   ||d      S )z
        :calls: `GET /repos/{owner}/{repo}/branches/{branch}/protection <https://docs.github.com/en/rest/reference/repos#branches>`_
        GETAcceptheadersT	completed)
_requesterrequestJsonAndCheckr,   r   (mediaTypeRequireMultipleApprovingReviewsr.   r   r   r;   datas      r   get_protectionzBranch.get_protection}   sc     ;;vNNO < 

 &&77RVbf7ggr!   c                F	   t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |	t              sJ |	       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       i }t        |      st        |      r#t        |      rd}t        |      rg }||d|d<   nd|d<   t        |      r||d<   nd|d<   t        |      sct        |      sXt        |      sMt        |      sBt        |      s7t        |	      s,t        |      s!t        |      st        |      st        |      ri |d<   t        |      r||d   d<   t        |      r||d   d<   t        |	      r|	|d   d	<   t        |      r||d   d
<   i }t        |      r||d<   t        |      r||d<   t        |      r||d<   |r||d   d<   i }t        |      r||d<   t        |      r||d<   t        |      r||d<   |r||d   d<   nd|d<   t        |
      st        |      st        |      r1t        |
      rg }
t        |      rg }t        |      rg }|
||d|d<   nd|d<   t        |      r||d<   nd|d<   t        |      r||d<   nd|d<   t        |      r||d<   nd|d<   t        |      r||d<   nd|d<   t        |      r||d<   nd|d<   t        |      r||d<   nd|d<   t        |      r||d<   nd|d<   | j                  j                  d| j                  dt        j                  i|      \  }}t        j                  j                  | j                  ||d      S )ay  
        :calls: `PUT /repos/{owner}/{repo}/branches/{branch}/protection <https://docs.github.com/en/rest/reference/repos#get-branch-protection>`_

        NOTE: The GitHub API groups strict and contexts together, both must
        be submitted. Take care to pass both as arguments even if only one is
        changing. Use edit_required_status_checks() to avoid this.
        Fstrictcontextsrequired_status_checksNenforce_adminsrequired_pull_request_reviewsdismiss_stale_reviewsrequire_code_owner_reviewsrequired_approving_review_countrequire_last_push_approvalusersteamsappsdismissal_restrictionsbypass_pull_request_allowancesrO   rP   rQ   restrictionsrequired_linear_historyallow_force_pushes required_conversation_resolutionlock_branchallow_fork_syncingblock_creationsallow_deletionsPUTr9   r;   inputTr<   )r   boolr   strintr   r   r>   r?   r,   r   r@   r.   r   )r   rF   rG   rI   dismissal_usersdismissal_teamsdismissal_appsrK   rL   rM   user_push_restrictionsteam_push_restrictionsapp_push_restrictionsrV   rW   rX   rY   rZ   $users_bypass_pull_request_allowances$teams_bypass_pull_request_allowances#apps_bypass_pull_request_allowancesr[   rN   r\   post_parametersrR   rS   r;   rB   s                                r   edit_protectionzBranch.edit_protection   s[   B 64(0&0(#.88.>40@.@05FF55FF54DnD40$7N9NN75t<X>XX<:C@aBaa@2D9R;RR9-t4H6HH4;TBdDddB;-:{:--t4H6HH4 DcJpLppJ DcJpLppJ CSInKnnI5t<X>XX<?D1B?B1*,fH!5F#H% $9O45
 9=O45n%0>O,-04O,- '/*.)/0459:>?>?=>45?AO;</0\q ?@AXY45 /   ?@0 9: 4   ?@5 45 /   ?@0 &("/*2A&w//*2A&w/.)1?&v.%]s ?@AYZ-/*>?:^.w7>?:^.w7=>9\.v6- 3   ?@4 @DO;<-.01/023)+&23)+&12(*%//-/ON+ /3ON+-.9PO569=O56()4FO0148O0167BbO>?BFO>?k"-8OM*-1OM*()4FO0148O01o&1@O-.15O-.o&1@O-.15O-.;;vNNO!	 < 
 &&77RVbf7ggr!   c                V    | j                   j                  d| j                        \  }}y)z
        :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection <https://docs.github.com/en/rest/reference/repos#branches>`_
        DELETENr>   r?   r,   rA   s      r   remove_protectionzBranch.remove_protection<  s(     ;;
r!   c                    | j                   j                  d| j                   d      \  }}t        j                  j	                  | j                   ||d      S )z
        :calls: `GET /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks <https://docs.github.com/en/rest/reference/repos#branches>`_
        :rtype: :class:`github.RequiredStatusChecks.RequiredStatusChecks`
        r8   /required_status_checksTr<   )r>   r?   r,   r.   r   rA   s      r   get_required_status_checksz!Branch.get_required_status_checksE  sT    
 ;;EdFYFYEZZqCrs**??QXZ^jn?oor!   c                D   t        |t              sJ |       t        |t              sJ |       t	        j
                  ||d      }| j                  j                  d| j                   d|      \  }}t        j                  j                  | j                  ||d      S )z
        :calls: `PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks <https://docs.github.com/en/rest/reference/repos#branches>`_
        rE   PATCHrs   r_   Tr<   )r   r`   r   ra   r	   remove_unset_itemsr>   r?   r,   r.   r   )r   rF   rG   rl   r;   rB   s         r   edit_required_status_checksz"Branch.edit_required_status_checksM  s     64(0&0(#.88.*0*C*CvckDl*m;;""##:;! < 
 **??QXZ^jn?oor!   c                \    | j                   j                  d| j                   d      \  }}y)z
        :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks <https://docs.github.com/en/rest/reference/repos#branches>`_
        ro   rs   Nrp   rA   s      r   remove_required_status_checksz$Branch.remove_required_status_checksa  s1     ;;""##:;
r!   c                    | j                   j                  d| j                   ddt        j                  i      \  }}t
        j                  j                  | j                   ||d      S )z
        :calls: `GET /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews <https://docs.github.com/en/rest/reference/repos#branches>`_
        r8   /required_pull_request_reviewsr9   r:   Tr<   )r>   r?   r,   r   r@   r.   r   rA   s      r   !get_required_pull_request_reviewsz(Branch.get_required_pull_request_reviewsj  sr     ;;""##ABvNNO < 

 00KKOOWdd L 
 	
r!   c                b   t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        |t              sJ |       t        j                  ||||d      }t        j                  |||d      }	|	r|	|d<   | j                  j                  d| j                   ddt        j                  i|      \  }
}t        j                  j                  | j                  |
|d	      S )
z
        :calls: `PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews <https://docs.github.com/en/rest/reference/repos#branches>`_
        )rK   rL   rM   rN   rT   rR   rv   r}   r9   r^   Tr<   )r   ra   r   r`   rb   r	   rx   r>   r?   r,   r   r@   r.   r   )r   rc   rd   re   rK   rL   rM   rN   rl   rR   r;   rB   s               r   "edit_required_pull_request_reviewsz)Branch.edit_required_pull_request_reviewsw  sD     5FF55FF50$7N9NN75t<X>XX<:C@aBaa@5t<X>XX<*0*C*C)>.H3R.H	+
 281J1J%X2
 "8NO45;;""##ABvNNO!	 < 
 **??QXZ^jn?oor!   c                \    | j                   j                  d| j                   d      \  }}y)z
        :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews <https://docs.github.com/en/rest/reference/repos#branches>`_
        ro   r}   Nrp   rA   s      r   $remove_required_pull_request_reviewsz+Branch.remove_required_pull_request_reviews  s1     ;;""##AB
r!   c                d    | j                   j                  d| j                   d      \  }}|d   S )z
        :calls: `GET /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins <https://docs.github.com/en/rest/reference/repos#branches>`_
        r8   /enforce_adminsenabledrp   rA   s      r   get_admin_enforcementzBranch.get_admin_enforcement  s7     ;;EdFYFYEZZiCjkIr!   c                \    | j                   j                  d| j                   d      \  }}y)z
        :calls: `POST /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins <https://docs.github.com/en/rest/reference/repos#branches>`_
        POSTr   Nrp   rA   s      r   set_admin_enforcementzBranch.set_admin_enforcement  s-     ;;FtGZGZF[[jDklr!   c                \    | j                   j                  d| j                   d      \  }}y)z
        :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins <https://docs.github.com/en/rest/reference/repos#branches>`_
        ro   r   Nrp   rA   s      r   remove_admin_enforcementzBranch.remove_admin_enforcement  s-     ;;HI\I\H]]lFmnr!   c                    t         j                  j                  t         j                  j                  | j                  | j                   dd      S )z
        :calls: `GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users <https://docs.github.com/en/rest/reference/repos#branches>`_
        /restrictions/usersN)r.   r   r   r>   r,   r   s    r   get_user_push_restrictionsz!Branch.get_user_push_restrictions  sH     ##11&&OO""##67	
 	
r!   c                    t         j                  j                  t         j                  j                  | j                  | j                   dd      S )z
        :calls: `GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams <https://docs.github.com/en/rest/reference/repos#branches>`_
        /restrictions/teamsN)r.   r   r   r>   r,   r   s    r   get_team_push_restrictionsz!Branch.get_team_push_restrictions  sF     ##11KKOO""##67	
 	
r!   c                    t        d |D              sJ |       | j                  j                  d| j                   d|      \  }}y)z
        :calls: `POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users <https://docs.github.com/en/rest/reference/repos#branches>`_
        :users: list of strings (user names)
        c              3  <   K   | ]  }t        |t                y wr#   
isinstancera   .0elements     r   	<genexpr>z4Branch.add_user_push_restrictions.<locals>.<genexpr>       A:gs+A   r   r   rw   Nallr>   r?   r,   r   rO   r;   rB   s       r   add_user_push_restrictionsz!Branch.add_user_push_restrictions  P    
 A5AAH5HA;;t**++>?u < 
r!   c                    t        d |D              sJ |       | j                  j                  d| j                   d|      \  }}y)z
        :calls: `PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users <https://docs.github.com/en/rest/reference/repos#branches>`_
        :users: list of strings (user names)
        c              3  <   K   | ]  }t        |t                y wr#   r   r   s     r   r   z8Branch.replace_user_push_restrictions.<locals>.<genexpr>  r   r   r]   r   rw   Nr   r   s       r   replace_user_push_restrictionsz%Branch.replace_user_push_restrictions  P    
 A5AAH5HA;;d))**=>e < 
r!   c                    t        d |D              sJ |       | j                  j                  d| j                   d|      \  }}y)z
        :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users <https://docs.github.com/en/rest/reference/repos#branches>`_
        :users: list of strings (user names)
        c              3  <   K   | ]  }t        |t                y wr#   r   r   s     r   r   z7Branch.remove_user_push_restrictions.<locals>.<genexpr>  r   r   ro   r   rw   Nr   r   s       r   remove_user_push_restrictionsz$Branch.remove_user_push_restrictions  P    
 A5AAH5HA;;,,--@A < 
r!   c                    t        d |D              sJ |       | j                  j                  d| j                   d|      \  }}y)z
        :calls: `POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams <https://docs.github.com/en/rest/reference/repos#branches>`_
        :teams: list of strings (team slugs)
        c              3  <   K   | ]  }t        |t                y wr#   r   r   s     r   r   z4Branch.add_team_push_restrictions.<locals>.<genexpr>  r   r   r   r   rw   Nr   r   rP   r;   rB   s       r   add_team_push_restrictionsz!Branch.add_team_push_restrictions  r   r!   c                    t        d |D              sJ |       | j                  j                  d| j                   d|      \  }}y)z
        :calls: `PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams <https://docs.github.com/en/rest/reference/repos#branches>`_
        :teams: list of strings (team slugs)
        c              3  <   K   | ]  }t        |t                y wr#   r   r   s     r   r   z8Branch.replace_team_push_restrictions.<locals>.<genexpr>  r   r   r]   r   rw   Nr   r   s       r   replace_team_push_restrictionsz%Branch.replace_team_push_restrictions  r   r!   c                    t        d |D              sJ |       | j                  j                  d| j                   d|      \  }}y)z
        :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams <https://docs.github.com/en/rest/reference/repos#branches>`_
        :teams: list of strings (team slugs)
        c              3  <   K   | ]  }t        |t                y wr#   r   r   s     r   r   z7Branch.remove_team_push_restrictions.<locals>.<genexpr>  r   r   ro   r   rw   Nr   r   s       r   remove_team_push_restrictionsz$Branch.remove_team_push_restrictions  r   r!   c                \    | j                   j                  d| j                   d      \  }}y)z
        :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions <https://docs.github.com/en/rest/reference/repos#branches>`_
        ro   z/restrictionsNrp   rA   s      r   remove_push_restrictionszBranch.remove_push_restrictions  s-     ;;HI\I\H]]jFklr!   c                    | j                   j                  d| j                   ddt        j                  i      \  }}|d   S )z
        :calls: `GET /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures <https://docs.github.com/en/rest/reference/repos#branches>`_
        r8   /required_signaturesr9   r:   r   r>   r?   r,   r   "signaturesProtectedBranchesPreviewrA   s      r   get_required_signatureszBranch.get_required_signatures  sP     ;;""##78vHHI < 

 Ir!   c                    | j                   j                  d| j                   ddt        j                  i      \  }}y)z
        :calls: `POST /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures <https://docs.github.com/en/rest/reference/repos#branches>`_
        r   r   r9   r:   Nr   rA   s      r   add_required_signatureszBranch.add_required_signatures)  sD     ;;""##78vHHI < 
r!   c                    | j                   j                  d| j                   ddt        j                  i      \  }}y)z
        :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures <https://docs.github.com/en/rest/reference/repos#branches>`_
        ro   r   r9   r:   Nr   rA   s      r   remove_required_signaturesz!Branch.remove_required_signatures3  sD     ;;""##78vHHI < 
r!   c                d    | j                   j                  d| j                   d      \  }}|d   S )z
        :calls: `GET /repos/{owner}/{repo}/branches/{branch}/protection/allow_deletions <https://docs.github.com/en/rest/reference/repos#branches>`_
        r8   /allow_deletionsr   rp   rA   s      r   get_allow_deletionszBranch.get_allow_deletions=  s7     ;;EdFYFYEZZjCklIr!   c                \    | j                   j                  d| j                   d      \  }}y)z
        :calls: `POST /repos/{owner}/{repo}/branches/{branch}/protection/allow_deletions <https://docs.github.com/en/rest/reference/repos#branches>`_
        r   r   Nrp   rA   s      r   set_allow_deletionszBranch.set_allow_deletionsD  s-     ;;FtGZGZF[[kDlmr!   c                \    | j                   j                  d| j                   d      \  }}y)z
        :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/allow_deletions <https://docs.github.com/en/rest/reference/repos#branches>`_
        ro   r   Nrp   rA   s      r   remove_allow_deletionszBranch.remove_allow_deletionsJ  s-     ;;HI\I\H]]mFnor!   N)returnra   )r   r   )r   r`   )r   None)r5   zdict[str, Any]r   r   )r   r   )0rF   	Opt[bool]rG   Opt[list[str]]rI   r   rc   r   rd   r   re   r   rK   r   rL   r   rM   Opt[int]rf   r   rg   r   rh   r   rV   r   rW   r   rX   r   rY   r   rZ   r   ri   r   rj   r   rk   r   r[   r   rN   r   r\   r   r   r   )r   r   )rF   r   rG   r   r   r   )r   r   )rc   r   rd   r   re   r   rK   r   rL   r   rM   r   rN   r   r   r   )r   zPaginatedList[NamedUser])r   zPaginatedList[Team])rO   ra   r   r   )rP   ra   r   r   )(__name__
__module____qualname____doc__r    propertyr%   r   r)   r,   r0   r6   rC   r	   rm   rq   rt   ry   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r   r   r   Q   s   < " "     % % * *FO	h ##)$**0*0)/+1064:171706-3(.6<!'(.?E?E>D%+06%+1rhrh !rh "	rh
 (rh (rh 'rh  )rh %.rh *2rh !/rh !/rh  .rh "+rh &rh  +4!rh" #rh$ &%rh& /='rh( /=)rh* .<+rh, #-rh. %./rh0 #1rh2 
3rhh
p ##)pp !p 
	p(

 +1*0)/+1064:06+p'+p (+p '	+p
  )+p %.+p *2+p %.+p 
+pZ
mo	
	
	
	
	
	
	
	
m	

npr!   r   )
__future__r   typingr   r   github.BranchProtectionr.   github.Commit!github.RequiredPullRequestReviewsgithub.RequiredStatusChecksr   github.GithubObjectr   r   r	   r
   r   r   r   r   r   r   github.NamedUserr   github.PaginatedListr   r   r   github.Teamr   r   r   r!   r   <module>r      sW   f # %   ( " 	 	 	 8$*2L@ }p' }pr!   