
    _Og9                     J   S r SSKrSSKJr  SSKJr  SSKJr  \R                  (       a  SSKJr	  SS	KJ
r  SS
KJr   " S S\R                  5      r " S S\5      r " S S\5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S \R                  5      r " S! S"\R                  5      rg)#z+Implementation of a branch on a repository.    N   )commit   )
decorators)modelsappsusersorgsc                      \ rS rSrSrSS0rSrS rS rSS jr	\
R                  SS j5       r\
R                      SS\R                  \R                  \\R"                  4      S\R                  \   S\R                  \R                  \\R"                  4      S\R                  \R                  \\R&                  \   4      S\R                  \   S\R                  \   S\R                  \   S\R                  \   S	S
4S jj5       r\
R                  S	\R                  \\4   4S j5       r\
R                  S	\4S j5       rSrg)_Branch   zA representation of a branch on a repository.

See also https://developer.github.com/v3/repos/branches/

This object has the following attributes:
Acceptz(application/vnd.github.loki-preview+jsonRepository Branchc                     [         R                  " US   U 5      U l         US   U l        U R                   R                  R	                  SS5      S   nU R                  SU R                  US9U l        g )Nr   namez/commitr   r   branchesbase_url)r   
MiniCommitr   urlsplit
_build_url_api)selfbranchbases      Y/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/github3/repos/branch.py_update_attributes_Branch._update_attributes   s_    ''x(8$?6N	{{$$Y215OOJ		DOI	    c                 <    SU R                    SU R                   S3$ )N<z [z]>)
class_namer   r   s    r    _repr_Branch._repr"   s     4??#2dii[33r#   c                     SSU S3S.nU R                   R                  SS5      S   nU R                  SU R                  US9nU R	                  XBS	9nU R                  US
S5      (       a  UR                  $ g)zCheck if SHA-1 is the same as the remote branch.

See: https://git.io/vaqIw

:param str differs_from:
    (optional), sha to compare against
:returns:
    string of the SHA or None
:rtype:
    str on Python 3
zapplication/vnd.github.v3.sha")r   zIf-None-Match	/branchesr   r   commitsr   )headers   i0  N)r   r   r   r   _get_booleantext)r   differs_fromr.   r   r   resps         r    
latest_sha_Branch.latest_sha%   s}     6 a0
 yy{A.q1ooiToByyy.==sC((99r#   returnBranchProtectionc                     U R                  SU R                  S9nU R                  U5      nU R                  US5      n[	        X05      $ )zRetrieve the protections enabled for this branch.

See:
https://developer.github.com/v3/repos/branches/#get-branch-protection

:returns:
    The protections enabled for this branch.
:rtype:
    :class:`~github3.repos.branch.BranchProtection`

protectionr   r/   )r   r   r0   _jsonr8   )r   r   r4   jsons       r    r:   _Branch.protection=   sB     oolTYYo?yy~zz$$++r#   Nrequired_status_checksenforce_adminsrequired_pull_request_reviewsrestrictionsrequired_linear_historyallow_force_pushesallow_deletions required_conversation_resolutionc	                     UUUUS.n	Ub  XYS'   Ub  XiS'   Ub  XyS'   Ub  UU	S'   U R                  SU R                  S9n
U R                  XS9nU R                  US	5      n[	        X5      $ )
al	  Enable force push protection and configure status check enforcement.

See also:
https://docs.github.com/en/rest/reference/repos#update-branch-protection

.. versionchanged:: 3.0.0

    The GitHub API changed since the last release this was updated in.
    As such the parameters have to change here.

:param requireed_status_checks:
    Required. Require status checks to pass before merging. Set to null
    to disable.
:param enforce_admins:
    Required. Enforce all configured restrictions for administrators.
    Set to true to enforce required status checks for repository
    administrators. Set to null to disable.
:param required_pull_request_reviews:
    Required. Require at least one approving review on a pull request,
    before merging. Set to null to disable.
:param restrictions:
    Required. Restrict who can push to the protected branch. User,
    app, and team restrictions are only available for
    organization-owned repositories. Set to null to disable.
:param required_linear_history:
    Enforces a linear commit Git history, which prevents anyone from
    pushing merge commits to a branch. Set to true to enforce a linear
    commit history. Set to false to disable a linear commit Git
    history. Your repository must allow squash merging or rebase
    merging before you can enable a linear commit history. Default:
    false. For more information, see "Requiring a linear commit
    history" in the GitHub Help documentation.
:param allow_force_pushes:
    Permits force pushes to the protected branch by anyone with write
    access to the repository. Set to true to allow force pushes. Set
    to false or null to block force pushes. Default: false. For more
    information, see "Enabling force pushes to a protected branch" in
    the GitHub Help documentation."
:param allow_deletions:
    Allows deletion of the protected branch by anyone with write
    access to the repository. Set to false to prevent deletion of the
    protected branch. Default: false. For more information, see
    "Enabling force pushes to a protected branch" in the GitHub Help
    documentation.
:param required_conversation_resolution:
    Requires all conversations on code to be resolved before a pull
    request can be merged into a branch that matches this rule. Set to
    false to disable. Default: false.
:returns:
    BranchProtection if successful
:rtype:
    :class:`BranchProtection`
)r>   r?   r@   rA   rB   rC   rD   rE   r:   r   r<   r/   )r   r   _putr;   r8   )r   r>   r?   r@   rA   rB   rC   rD   rE   editr   r4   r<   s                r    protect_Branch.protectN   s    D '=,-J(	
 #..E*+));%&&&5"#+7 1 2 oolTYYo?yyy(zz$$++r#   c                     U R                   R                  SS5      S   nU R                  SUS9nU R                  U R	                  U5      S5      nU$ )a  Synchronize this branch with the upstream.

.. warning::

    This API endpoint is still in Beta per gitHub

.. versionadded:: 3.0.0

Sync a branch of a forked repository to keep it up-to-date with the
upstream repository.

See also:
https://docs.github.com/en/rest/reference/repos#sync-a-fork-branch-with-the-upstream-repository

:returns:
    The dictionary described in the documentation
:rtype:
    dict
r,   r   r   zmerge-upstreamr   r/   )r   r   r   r;   _post)r   r   r   r<   s       r    sync_with_upstream_Branch.sync_with_upstream   sM    * yy{A.q1oo.o>zz$**S/3/r#   c           	      v    U R                  U R                  U R                  SU R                  S95      SS5      $ )z#Disable protections on this branch.r:   r   r/   i  )r1   _deleter   r   r'   s    r    	unprotect_Branch.unprotect   s8     }}LL		JK
 	
r#   )r   r   r   ) )r7   r8   NNNN)__name__
__module____qualname____firstlineno____doc__PREVIEW_HEADERSr&   r!   r(   r5   r   requires_authr:   tOptionalMappingstrAnyboolSequencerJ   rN   rR   __static_attributes__ r#   r    r   r      s     !KLO$JJ40 , ,   59/3,0=AS, !

199S!%%Z+@ AS, 

4(S, ()zz!))CJ2G'H	S,
 jj3

3+?!@AS, "#D!1S, JJt,S, D)S, +,**T*:S, 
S, S,j AIIc3h$7  2 
4 
 
r#   r   c                   0   ^  \ rS rSrSrSrU 4S jrSrU =r$ )Branchr/   a  The representation of a branch returned in a collection.

GitHub's API returns different amounts of information about repositories
based upon how that information is retrieved. This object exists to
represent the limited amount of information returned for a specific
branch in a collection. For example, you would receive this class when
calling :meth:`~github3.repos.repo.Repository.branches`. To provide a
clear distinction between the types of branches, github3.py uses different
classes with different sets of attributes.

This object has the same attributes as a
:class:`~github3.repos.branch.ShortBranch` as well as the following:

.. attribute:: links

    The dictionary of URLs returned by the API as ``_links``.

.. attribute:: protected

    A boolean attribute that describes whether this branch is protected or
    not.

.. attribute:: original_protection

    .. versionchanged:: 1.1.0

        To support a richer branch protection API, this is the new name
        for the information formerly stored under the attribute
        ``protection``.

    A dictionary with details about the protection configuration of this
    branch.

.. attribute:: protection_url

    The URL to access and manage details about this branch's protection.
r   c                    > [         TU ]  U5        [        R                  " US   U 5      U l        US   U l        US   U l        US   U l        US   U l        U R                  (       a&  SU R                  ;   a  U R                  S   U l        g g g )Nr   _links	protectedr:   protection_urlr   )	superr!   r   ShortCommitlinksrj   original_protectionrk   r   )r   r   	__class__s     r    r!   Branch._update_attributes   s    "6*(()94@H%
,#),#7 $%56::&DJJ.

6*DI /:r#   )r   r   rn   ro   rj   rk   )	rV   rW   rX   rY   rZ   r&   r!   rd   __classcell__)rp   s   @r    rg   rg      s    $L %J
+ 
+r#   rg   c                   T    \ rS rSrSrSr\r\R                  S	S\
S\4S jj5       rSrg)
ShortBranch   a  The representation of a branch returned in a collection.

GitHub's API returns different amounts of information about repositories
based upon how that information is retrieved. This object exists to
represent the limited amount of information returned for a specific
branch in a collection. For example, you would receive this class when
calling :meth:`~github3.repos.repo.Repository.branches`. To provide a
clear distinction between the types of branches, github3.py uses different
classes with different sets of attributes.

This object has the following attributes:

.. attribute:: commit

    A :class:`~github3.repos.commit.MiniCommit` representation of the
    newest commit on this branch with the associated repository metadata.

.. attribute:: name

    The name of this branch.
zShort Repository Branchconditionalr7   c                     g Nre   )r   rv   s     r    refreshShortBranch.refresh  s    r#   re   N)F)rV   rW   rX   rY   rZ   r&   rg   _refresh_tor]   overloadrb   ry   rd   re   r#   r    rt   rt      s7    , +JKZZ4 F  r#   rt   c                       \ rS rSrSrS r\R                      SS j5       r\R                  S\	4S j5       r
\R                  S\	4S j5       r\R                  S\	4S	 j5       r\R                  S\	4S
 j5       rSrg)r8   i  aR  The representation of a branch's protection.

.. seealso::

    `Branch protection API documentation`_
        GitHub's documentation of branch protection

.. versionchanged:: 3.0.0

    Added ``required_linear_history``, ``allow_force_pushes``,
    ``allow_deletions``, and ``required_conversation_resolution``.

This object has the following attributes:

.. attribute:: enforce_admins

    A :class:`~github3.repos.branch.ProtectionEnforceAdmins` instance
    representing whether required status checks are required for admins.

.. attribute:: restrictions

    A :class:`~github3.repos.branch.ProtectionRestrictions` representing
    who can push to this branch. Team and user restrictions are only
    available for organization-owned repositories.

.. attribute:: required_pull_request_reviews

    A :class:`~github3.repos.branch.ProtectionRequiredPullRequestReviews`
    representing the protection provided by requiring pull request
    reviews.

.. attribute:: required_status_checks

    A :class:`~github3.repos.branch.ProtectionRequiredStatusChecks`
    representing the protection provided by requiring status checks.

.. attribute:: required_linear_history

    .. versionadded:: 3.0.0

    A :class:`~github3.repos.branch.ProtectionRequiredLinearHistory`
    representing the information returned by the API about this
    protection.

.. attribute:: allow_force_pushes

    .. versionadded:: 3.0.0

    A :class:`~github3.repos.branch.ProtectionAllowForcePushes`
    representing the information returned by the API about this
    protection.

.. attribute:: allow_deletions

    .. versionadded:: 3.0.0

    A :class:`~github3.repos.branch.ProtectionAllowDeletions`
    representing the information returned by the API about this
    protection.

.. attribute:: required_conversation_resolution

    .. versionadded:: 3.0.0

    A
    :class:`~github3.repos.branch.ProtectionRequiredConversationResolution`
    representing the information returned by the API about this
    protection.

.. links
.. _Branch protection API documentation:
    https://developer.github.com/v3/repos/branches/#get-branch-protection
c                    ^ ^ TS   T l         UU 4S jnU" S[        5        U" S[        5        U" S[        5        U" S[        5        U" S[
        5        U" S[        5        U" S	[        5        U" S
[        5        g )Nr   c                    > TR                  U 5      n[        TX5        [        TU 5      (       a  [        TX" UT5      5        g g rx   )getsetattrgetattr)r   clsvaluer:   r   s      r    _set_conditional_attrBBranchProtection._update_attributes.<locals>._set_conditional_attrk  s@    NN4(ED$&tT""dCt$45 #r#   r?   rA   r@   r>   rB   rC   allow_deleteionsrE   )	r   ProtectionEnforceAdminsProtectionRestrictions$ProtectionRequiredPullRequestReviewsProtectionRequiredStatusChecksProtectionRequiredLinearHistoryProtectionAllowForcePushesProtectionAllowDeletions(ProtectionRequiredConversationResolution)r   r:   r   s   `` r    r!   #BranchProtection._update_attributesh  s    u%		6 	.0GHn.DE+0	
 	$&D	
 	%'F	
 	 "<	
 	02JK.4	
r#   Nc                    [        U R                  SS5      U R                  b  U R                  R                  5       OSU R                  b  U R                  R                  5       OSU R
                  b  U R
                  R                  5       OSS.nSUb  UOUS   Ub  UOUS   Ub  UOUS   Ub  UOUS	   S
.nU R                  U R                  U R                  US9S5      nU R                  U5        U $ )a  Enable force push protection and configure status check enforcement.

See: http://git.io/v4Gvu

:param str enforce_admins:
    (optional), Specifies the enforcement level of the status checks.
    Must be one of 'off', 'non_admins', or 'everyone'. Use `None` or
    omit to use the already associated value.
:param list required_status_checks:
    (optional), A list of strings naming status checks that must pass
    before merging. Use `None` or omit to use the already associated
    value.
:param obj required_pull_request_reviews:
    (optional), Object representing the configuration of Request Pull
    Request Reviews settings. Use `None` or omit to use the already
    associated value.
:param obj restrictions:
    (optional), Object representing the configuration of Restrictions.
    Use `None` or omit to use the already associated value.
:returns:
    Updated branch protection
:rtype:
    :class:`~github3.repos.branch.BranchProtection`
enabledFN)r?   r>   r@   rA   Tr?   r>   r@   rA   )r   r?   r>   r@   rA   rG   r/   )
r   r?   r>   as_dictr@   rA   r;   rH   r   r!   )r   r?   r>   r@   rA   current_statusrI   r<   s           r    updateBranchProtection.update  s&   B &d&9&99eL ..: ++335 55A 22::< $$0 !!))+
&  "- #$45 *5 '#$<= 1< .#$CD  + #N3)
0 zz$))DIID)93?%r#   r7   c                 ^    U R                  U R                  5      nU R                  USS5      $ )z^Remove branch protection.

:returns:
    True if successful, False otherwise
:rtype:
    bool
     rQ   r   r1   r   r4   s     r    deleteBranchProtection.delete  )     ||DII&}}T3,,r#   c                     U R                  SU R                  S9nU R                  U5      nUR                  S:X  a  UR	                  5       S   $ g)ztCheck if commit signatures are presently required.

:returns:
    True if enabled, False otherwise
:rtype:
    bool
required_signaturesr   r/   r   F)r   r   r0   status_coder<   r   r   r4   s      r    requires_signatures$BranchProtection.requires_signatures  sJ     oo3diioHyy~s"99;y))r#   c                 ~    U R                  SU R                  S9nU R                  U5      nU R                  USS5      $ )zzRequire commit signatures for commits to this branch.

:returns:
    True if successful, False otherwise
:rtype:
    bool
r   r   r/   r   )r   r   rM   r1   r   s      r    require_signatures#BranchProtection.require_signatures  s;     oo3diioHzz#}}T3,,r#   c                 ~    U R                  SU R                  S9nU R                  U5      nU R                  USS5      $ )zStop requiring commit signatures for commits to this branch.

:returns:
    True if successful, False otherwise
:rtype:
    bool
r   r   r/   r   )r   r   rQ   r1   r   s      r    delete_signature_requirements.BranchProtection.delete_signature_requirements  s<     oo3diioH||C }}T3,,r#   )r   rU   )rV   rW   rX   rY   rZ   r!   r   r\   r   rb   r   r   r   r   rd   re   r#   r    r8   r8     s    HT
<  #&*K KZ 	- 	- 	- T   
-D 
- 
- 
-t 
- 
-r#   r8   c                   f    \ rS rSrSrS r\R                  S 5       r\R                  S 5       r	Sr
g)r   i
  a  The representation of a sub-portion of branch protection.

.. seealso::

    `Branch protection API documentation`_
        GitHub's documentation of branch protection
    `Admin enforcement of protected branch`_
        GitHub's documentation of protecting a branch with admins

This object has the following attributes:

.. attribute:: enabled

    A boolean attribute indicating whether the ``enforce_admins``
    protection is enabled or disabled.

.. links
.. _Branch protection API documentation:
    https://developer.github.com/v3/repos/branches/#get-branch-protection
.. _Admin enforcement of protected branch:
    https://developer.github.com/v3/repos/branches/#get-admin-enforcement-of-protected-branch
c                 ,    US   U l         US   U l        g )Nr   r   r   r   r   r:   s     r    r!   *ProtectionEnforceAdmins._update_attributes"  s    u%	!),r#   c                 ^    U R                  U R                  5      nU R                  USS5      $ )z.Enable Admin enforcement for protected branch.r/   r   )rM   r   r1   r   s     r    enableProtectionEnforceAdmins.enable&  s)     zz$))$}}T3,,r#   c                 ^    U R                  U R                  5      nU R                  USS5      $ )z/Disable Admin enforcement for protected branch.r   r   r   r   s     r    disableProtectionEnforceAdmins.disable,  s)     ||DII&}}T3,,r#   r   N)rV   rW   rX   rY   rZ   r!   r   r\   r   r   rd   re   r#   r    r   r   
  s@    .- - -
 - -r#   r   c                      \ rS rSrSrS r\R                  S\R                  \
   S\R                  S   4S j5       r\R                  S\R                  \
   S\R                  S	   4S
 j5       r\R                  SS\S\R                  S   4S jj5       r\R                  S\R                  \R                   S\
4      S\R"                  S   4S j5       r\R                  S\R                  \R                   S\
4      S\R"                  S   4S j5       r\R                  S\R                  \R                   S\
4      S\R"                  S   4S j5       r\R                  S\4S j5       r\R                  S\R                  \
   S\R                  S   4S j5       r\R                  S\R                  \
   S\R                  S	   4S j5       r\R                  S\R                  \
   S\R                  S   4S j5       r\R                  S\R                  \
   S\R                  S	   4S j5       r SS\S\R                  S   4S jjr SS\S\R                  S   4S jjrSrg)r   i3  a)  The representation of a sub-portion of branch protection.

.. seealso::

    `Branch protection API documentation`_
        GitHub's documentation of branch protection

    `Branch restriction documentation`_
        GitHub's description of branch restriction

This object has the following attributes:

.. attribute:: original_teams

    List of :class:`~github3.orgs.ShortTeam` objects representing
    the teams allowed to push to the protected branch.

.. attribute:: original_users

    List of :class:`~github3.users.ShortUser` objects representing
    the users allowed to push to the protected branch.

.. attribute:: teams_url

    The URL to retrieve the list of teams allowed to push to the
    protected branch.

.. attribute:: users_url

    The URL to retrieve the list of users allowed to push to the
    protected branch.


.. links
.. _Branch protection API documentation:
    https://developer.github.com/v3/repos/branches/#get-branch-protection
.. _Branch restriction documentation:
    https://help.github.com/articles/about-branch-restrictions
c                 |   SSK JnJnJn  US   U l        US   U l        US   U l        UR                  S5      U l        US   U l	        U R                  (       a0  U R                   Vs/ s H  oTR                  XP5      PM     snU l	        US   U l        U R                  (       a1  U R                   Vs/ s H  ocR                  " X`5      PM     snU l        UR                  S	5      U l        U R                  (       a1  U R                   Vs/ s H  orR                  Xp5      PM     snU l        g g s  snf s  snf s  snf )
Nr   )r	   r   r   r   	users_url	teams_urlapps_urlr   teamsr	   )rT   r	   r   r   r   r   r   r   r   original_users	ShortUseroriginal_teams	ShortTeamoriginal_appsApp)r   r:   r	   r   r   userteamapps           r    r!   )ProtectionRestrictions._update_attributes\  s   ((u%	#K0#K0"z2(18<8K8K#8K+8K#D )17;7J7J#7Jtt*7J#D (^^F3/3/A/A"/A#/A"D ##"s   (D/3D4D9r   r7   orgs.ShortTeamc                     SSK Jn  U R                  U R                  US9nU R	                  US5      nU(       a"  U Vs/ s H  oRR
                  " XP5      PM     sn$ / $ s  snf )a  Add teams to the protected branch.

See:
https://developer.github.com/v3/repos/branches/#add-team-restrictions-of-protected-branch

.. warning::

    This will not update the object to replace the ``original_teams``
    attribute.

:param list teams:
    The list of the team names to have access to interact with
    protected branch.
:returns:
    List of added teams
:rtype:
    List[github3.orgs.ShortTeam]
r   r   datar/   )rT   r   rM   r   r;   r   r   r   r   r4   r<   r   s         r    	add_teams ProtectionRestrictions.add_teamsu  sS    , 	zz$..uz5zz$$@Dt<ttt*t<L"L<   Ar   tusers.ShortUserc                     SSK Jn  U R                  U R                  U R                  US9S5      nU(       a!  U Vs/ s H  oBR                  X@5      PM     sn$ / $ s  snf )a  Add users to protected branch.

See
https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch

.. warning::

    This will not update the object to replace the ``original_users``
    attribute.

:param list users:
    The list of the user logins to have access to interact with
    protected branch.
:returns:
    List of added users
:rtype:
    List[github3.users.ShortUser]
r   r
   r   r/   )rT   r   r;   rM   r   r   )r   r   _usersr<   r   s        r    	add_users ProtectionRestrictions.add_users  sP    , 	'zz$**T^^%*@#FBF>  ,>NBN>s   Anumber)	tapps.AppNNc                 n    SSK Jn  U R                  [        U5      U R                  UR
                  5      $ )a  Retrieve current list of apps with access to the protected branch.

See
https://docs.github.com/en/rest/reference/repos#get-apps-with-access-to-the-protected-branch

.. warning::

    This will not update the object to replace the ``original_apps``
    attribute.

:param int number:
    Limit the number of apps returned
:returns:
    An iterator of apps
:rtype:
    :class:`~github3.apps.App`
r   r   )rT   r	   _iterintr   r   )r   r   r	   s      r    r	   ProtectionRestrictions.apps  s&    & 	zz#f+t}}dhh??r#   r	   r   c                     SSK Jn  U Vs/ s H  n[        USU5      PM     nnU R                  U R	                  U R
                  US9S5      nU Vs/ s H  o2R                  X05      PM     sn$ s  snf s  snf )a  Grant app push access to the current branch.

See
https://docs.github.com/en/rest/reference/repos#add-app-access-restrictions

Per GitHub's documentation above:

    Grants the specified apps push access for this branch. Only
    installed GitHub Apps with write access to the contents permission
    can be added as authorized actors on a protected branch.

:param list apps:
    List of slugs of apps to grant push access to the protected
    branch. If you pass a list of :class:`~github3.apps.App` then the
    library will retrieve the slug for you.
:returns:
    List of apps with push access to the protected branch
:rtype:
    List[:class:`~github3.apps.App`]
r   r   slugr   r/   )rT   r	   r   r;   rM   r   r   r   r	   _appsar<   s        r    add_app_restrictions+ProtectionRestrictions.add_app_restrictions  si    0 	%/34t!61%t4zz$**T]]*>D,01Dq		!"D11 51   A/A4c                     SSK Jn  U Vs/ s H  n[        USU5      PM     nnU R                  U R	                  U R
                  US9S5      nU Vs/ s H  o2R                  X05      PM     sn$ s  snf s  snf )a"  Replace existing app push access with only those specified.

See
https://docs.github.com/en/rest/reference/repos#set-app-access-restrictions

Per GitHub's documentation above:

    Replaces the list of apps that have push access to this branch.
    This removes all apps that previously had push access and grants
    push access to the new list of apps. Only installed GitHub Apps
    with write access to the contents permission can be added as
    authorized actors on a protected branch.

:param list apps:
    List of slugs of apps to grant push access to the protected
    branch. If you pass a list of :class:`~github3.apps.App` then the
    library will retrieve the slug for you.
:returns:
    List of apps with push access to the protected branch
:rtype:
    List[:class:`~github3.apps.App`]
r   r   r   r   r/   )rT   r	   r   r;   rH   r   r   r   s        r    replace_app_restrictions/ProtectionRestrictions.replace_app_restrictions  si    4 	%/34t!61%t4zz$))DMM)=sC,01Dq		!"D11 51r   c                     SSK Jn  U Vs/ s H  n[        USU5      PM     nnU R                  U R	                  U R
                  US9S5      nU Vs/ s H  o2R                  X05      PM     sn$ s  snf s  snf )a  Remove the apps' push access to the protected branch.

See
https://docs.github.com/en/rest/reference/repos#remove-app-access-restrictions

:param list apps:
    List of slugs of apps to revoke push access to the protected
    branch. If you pass a list of :class:`~github3.apps.App` then the
    library will retrieve the slug for you.
:returns:
    List of apps that still have push access
:rtype:
    List[:class:`~github3.apps.App`]
r   r   r   r   r/   )rT   r	   r   r;   rQ   r   r   r   s        r    remove_app_restrictions.ProtectionRestrictions.remove_app_restrictions  si    $ 	%/34t!61%t4zz$,,t}}4,@#F,01Dq		!"D11 51r   c                 ^    U R                  U R                  5      nU R                  USS5      $ )zCompletely remove restrictions of the protected branch.

See
https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch

:returns:
    True if successful, False otherwise.
:rtype:
    bool
r   r   r   r   s     r    r   ProtectionRestrictions.delete  s)     ||DII&}}T3,,r#   c                     SSK Jn  U R                  U R                  US9nU R	                  US5      nU(       a"  U Vs/ s H  oRR
                  " XP5      PM     sn$ / $ s  snf )aC  Remove teams from protected branch.

See
https://developer.github.com/v3/repos/branches/#remove-team-restrictions-of-protected-branch

:param list teams:
    The list of the team names to stop having access to interact with
    protected branch.
:returns:
    List of removed teams
:rtype:
    List[github3.orgs.ShortTeam]
r   r   rG   r/   )rT   r   rQ   r   r;   r   r   s         r    remove_teams#ProtectionRestrictions.remove_teams(  sS    " 	||DNN|7zz$$@Dt<ttt*t<L"L<r   c                     U R                  U R                  US9nU R                  US5      nSSKJn  U(       a!  U Vs/ s H  oTR                  XP5      PM     sn$ / $ s  snf )aE  Remove users from protected branch.

See
https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch

:param list users:
    The list of the user logins to stop having access to interact with
    protected branch.
:returns:
    List of removed users
:rtype:
    List[github3.users.ShortUser]
rG   r/   r   r
   )rQ   r   r;   rT   r   r   )r   r   r4   r<   r   r   s         r    remove_users#ProtectionRestrictions.remove_users?  sU    " ||DNN|7zz$$&BF>  ,>NBN>s   Ac                     SSK Jn  U R                  U R                  US9nU R	                  US5      nU(       a"  U Vs/ s H  oRR
                  " XP5      PM     sn$ / $ s  snf )aw  Replace teams that will have access to protected branch.

See
https://developer.github.com/v3/repos/branches/#replace-team-restrictions-of-protected-branch

:param list teams:
    The list of the team names to have access to interact with
    protected branch.
:returns:
    List of teams that now have access to the protected branch
:rtype:
    List[github3.orgs.ShortTeam]
r   r   rG   r/   )rT   r   rH   r   r;   r   r   s         r    replace_teams$ProtectionRestrictions.replace_teamsV  sS    " 	yyey4zz$$@Dt<ttt*t<L"L<r   c                 \    U R                  U R                  US9nU R                  USS5      $ )ay  Replace users that will have access to protected branch.

See
https://developer.github.com/v3/repos/branches/#replace-user-restrictions-of-protected-branch

:param list users:
    The list of the user logins to have access to interact with
    protected branch.
:returns:
    List of users that now have access to the protected branch
:rtype:
    List[github3.users.ShortUser]
rG   r/   r   )rH   r   r1   )r   r   
users_resps      r    replace_users$ProtectionRestrictions.replace_usersm  s-    " YYt~~EY:
}}Zc22r#   )r   NNc                 n    SSK Jn  U R                  [        U5      U R                  UR
                  5      $ )zzRetrieve an up-to-date listing of teams.

:returns:
    An iterator of teams
:rtype:
    :class:`~github3.orgs.ShortTeam`
r   r   )rT   r   r   r   r   r   )r   r   r   s      r    r   ProtectionRestrictions.teams  s-     	zzKNNNN
 	
r#   )r   NNc                 n    SSK Jn  U R                  [        U5      U R                  UR
                  5      $ )z{Retrieve an up-to-date listing of users.

:returns:
    An iterator of users
:rtype:
    :class:`~github3.users.ShortUser`
r   r
   )rT   r   r   r   r   r   )r   r   r   s      r    r   ProtectionRestrictions.users  s&     	zz#f+t~~uGGr#   )r   r   r   r   r   r   r   N))rV   rW   rX   rY   rZ   r!   r   r\   r]   rc   r`   r   r   r   	Generatorr	   UnionListr   r   r   rb   r   r   r   r   r   r   r   rd   re   r#   r    r   r   3  s   &P2 MZZ_M	
$	%M M6 OZZ_O	
&	'O O4 @3 @4K(L @ @, 2JJqww{C'7892	
	2 2: 2JJqww{C'7892	
	2 2> 2JJqww{C'7892	
	2 2. - - - MZZ_M	
$	%M M, OZZ_O	
&	'O O, MZZ_M	
$	%M M, 3ZZ_3	
&	'3 3( 

	
1	2
& HH	
3	4H Hr#   r   c                   r    \ rS rSrSrS r\R                      SS j5       r\R                  S 5       r	Sr
g)	r   i  a  The representation of a sub-portion of branch protection.

.. seealso::

    `Branch protection API documentation`_
        GitHub's documentation of branch protection.
    `Branch Required Pull Request Reviews`_
        GitHub's documentation of required pull request review protections

This object has the folllowing attributes:

.. attribute:: dismiss_stale_reviews

    A boolean attribute describing whether stale pull request reviews
    should be automatically dismissed by GitHub.

.. attribute:: dismissal_restrictions

    If specified, a :class:`~github3.repos.branch.ProtectionRestrictions`
    object describing the dismissal restrictions for pull request reviews.

.. attribute:: require_code_owner_reviews

    A boolean attribute describing whether to require "code owners" to
    review a pull request before it may be merged.

.. attribute:: required_approving_review_count

    An integer describing the number (between 1 and 6) of reviews required
    before a pull request may be merged.

.. links
.. _Branch protection API documentation:
    https://developer.github.com/v3/repos/branches/#get-branch-protection
.. _Branch Required Pull Request Reviews:
    https://developer.github.com/v3/repos/branches/#get-pull-request-review-enforcement-of-protected-branch
c                     US   U l         US   U l        US   nX l        US   nX l        S U l        SU;   a  [        US   U 5      U l        g g )Nr   dismiss_stale_reviewsrequire_code_owner_reviewsrequired_approving_review_countdismissal_restrictions)r   r   r  r  r  r   )r   r:   r   s      r    r!   7ProtectionRequiredPullRequestReviews._update_attributes  sk    u%	%/0G%H"78*/'<=/4,&*##z1*@34d+D' 2r#   Nc           
         U R                   [        U R                  S/ 5       Vs/ s H  n[        USU5      PM     sn[        U R                  S/ 5       Vs/ s H  n[        USU5      PM     snS.U R                  U R                  S.nUb  UOUS   Ub  UOUS   Ub  UOUS	   Ub  UOUS
   S.nU R                  U R                  US9n	U R                  U	S5      n
U
(       a  U R                  U
5        U $ s  snf s  snf )a  Update the configuration for the Required Pull Request Reviews.

:param bool dismiss_stale_reviews:
    Whether or not to dismiss stale pull request reviews automatically
:param bool require_code_owner_reviews:
    Blocks merging pull requests until code owners review them
:param int required_approving_review_count:
    The number of reviewers required to approve pull requests.
    Acceptable values are between 1 and 6.
:param dict dismissal_restrictions:
    An empty dictionary will disable this. This must have the
    following keys: ``users`` and ``teams`` each mapping to a list
    of user logins and team slugs respectively.
:returns:
    A updated instance of the required pull request reviews.
:rtype:
    :class:`~github3.repos.branch.ProtectionRequiredPullRequestReviews`
r   loginr   r   )r   r   )r   r  r  r  r   r  r  r  )r   r  r  r  rG   r/   )	r   r   r  r  r  _patchr   r;   r!   )r   r   r  r  r  ur]   existing_valuesupdate_jsonr4   r<   s              r    r   +ProtectionRequiredPullRequestReviews.update  sO   6 &*%?%? %335Er Aw* %335Er Avq)' +/*I*I44%
2 )4 &$%<= .9 +$%AB 3> 0$%FG *5 '$%=>'
, {{499;{7zz$$##D)[s   C8C=c                 ^    U R                  U R                  5      nU R                  USS5      $ )z}Remove the Required Pull Request Reviews.

:returns:
    Whether the operation finished successfully or not
:rtype:
    bool
r   r   r   r   s     r    r   +ProtectionRequiredPullRequestReviews.delete$  r   r#   )r   r   r  r  r  rU   )rV   rW   rX   rY   rZ   r!   r   r\   r   r   rd   re   r#   r    r   r     sR    $L  ##'(,#I IV 	- 	-r#   r   c                      \ rS rSrSrS r\R                  S 5       r\R                  S 5       r	\R                  S 5       r
\R                  S 5       r\R                  S 5       r\R                  SS
 j5       r\R                  S 5       rSrg	)r   i1  a  The representation of a sub-portion of branch protection.

.. seealso::

    `Branch protection API documentation`_
        GitHub's documentation of branch protection
    `Required Status Checks documentation`_
        GitHub's description of required status checks
    `Required Status Checks API documentation`_
        The API documentation for required status checks


.. links
.. _Branch protection API documentation:
    https://developer.github.com/v3/repos/branches/#get-branch-protection
.. _Required Status Checks documentation:
    https://help.github.com/articles/about-required-status-checks
.. _Required Status Checks API documentation:
    https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch
c                 T    US   U l         US   U l        US   U l        US   U l        g )Nr   strictcontextscontexts_url)r   r  original_contextsr  r   s     r    r!   1ProtectionRequiredStatusChecks._update_attributesG  s4    u%	 *!+J!7&~6r#   c                 ^    U R                  U R                  US9nU R                  US5      nU$ )a3  Add contexts to the existing list of required contexts.

See:
https://developer.github.com/v3/repos/branches/#add-required-status-checks-contexts-of-protected-branch

:param list contexts:
    The list of contexts to append to the existing list.
:returns:
    The updated list of contexts.
:rtype:
    list
r   r/   )rM   r  r;   r   r  r4   r<   s       r    add_contexts+ProtectionRequiredStatusChecks.add_contextsM  s1     zz$++(z;zz$$r#   c                 `    U R                  U R                  5      nU R                  US5      nU$ )a  Retrieve the list of contexts required as status checks.

See:
https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch

:returns:
    A list of context names which are required status checks.
:rtype:
    list
r/   )r0   r  r;   )r   r4   r<   s      r    r  'ProtectionRequiredStatusChecks.contexts_  s-     yy**+zz$$r#   c                 ^    U R                  U R                  US9nU R                  US5      nU$ )aA  Remove the specified contexts from the list of required contexts.

See:
https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch

:param list contexts:
    The context names to remove
:returns:
    The updated list of contexts required as status checks.
:rtype:
    list
rG   r/   )rQ   r  r;   r  s       r    remove_contexts.ProtectionRequiredStatusChecks.remove_contextso  s1     ||D--H|=zz$$r#   c                 ^    U R                  U R                  US9nU R                  US5      nU$ )aR  Replace the existing contexts required as status checks.

See
https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch

:param list contexts:
    The names of the contexts to be required as status checks
:returns:
    The new list of contexts required as status checks.
:rtype:
    list
rG   r/   )rH   r  r;   r  s       r    replace_contexts/ProtectionRequiredStatusChecks.replace_contexts  s1     yy**y:zz$$r#   c                 \    U R                  U R                  US9nU R                  USS5      $ )aL  Delete the contexts required as status checks.

See
https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch

:param list contexts:
    The names of the contexts to be required as status checks
:returns:
    The updated list of contexts required as status checks.
:rtype:
    list
rG   r   r   )rQ   r  r1   )r   r  r4   s      r    delete_contexts.ProtectionRequiredStatusChecks.delete_contexts  s/     ||D--H|=}}T3,,r#   Nc                     0 nSnUb  XS'   Ub  X#S'   U(       a,  U R                  U R                  US9nU R                  US5      nUb  U R                  U5        U $ )a  Update required status checks for the branch.

This requires admin or owner permissions to the repository and
branch protection to be enabled.

.. seealso::

    `API docs`_
        Descrption of how to update the required status checks.

:param bool strict:
    Whether this should be strict protection or not.
:param list contexts:
    A list of context names that should be required.
:returns:
    A new instance of this class with the updated information
:rtype:
    :class:`~github3.repos.branch.ProtectionRequiredStatusChecks`


.. links
.. _API docs:
    https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch
Nr  r  rG   r/   )r  r   r;   r!   )r   r  r  update_datar<   r4   s         r    r   %ProtectionRequiredStatusChecks.update  sl    4 $*!&.
#;;txxk;:D::dC(D##D)r#   c                 ^    U R                  U R                  5      nU R                  USS5      $ )zRemove required status checks from this branch.

See:
https://developer.github.com/v3/repos/branches/#remove-required-status-checks-of-protected-branch

:returns:
    True if successful, False otherwise
:rtype:
    bool
r   r   )rQ   r   r1   r   s     r    r   %ProtectionRequiredStatusChecks.delete  s)     ||DHH%}}T3,,r#   )r   r  r  r  )NN)rV   rW   rX   rY   rZ   r!   r   r\   r  r  r  r  r"  r   r   rd   re   r#   r    r   r   1  s    *7  "    "  " - -  $ $L - -r#   r   c                       \ rS rSrSrS rSrg)r   i  a  The representation of a sub-portion of branch protection.

.. seealso::

    `Branch protection API documentation`_
        GitHub's documentation of branch protection

This object has the following attributes:

.. attribute:: enabled

    A boolean attribute indicating whether the ``required_linear_history``
    protection is enabled or disabled.

.. links
.. _Branch protection API documentation:
    https://developer.github.com/v3/repos/branches/#get-branch-protection
c                     US   U l         g Nr   r   r   s     r    r!   2ProtectionRequiredLinearHistory._update_attributes      !),r#   r,  NrV   rW   rX   rY   rZ   r!   rd   re   r#   r    r   r         &-r#   r   c                       \ rS rSrSrS rSrg)r   i  a  The representation of a sub-portion of branch protection.

.. seealso::

    `Branch protection API documentation`_
        GitHub's documentation of branch protection

This object has the following attributes:

.. attribute:: enabled

    A boolean attribute indicating whether the ``allow_force_pushes``
    protection is enabled or disabled.

.. links
.. _Branch protection API documentation:
    https://developer.github.com/v3/repos/branches/#get-branch-protection
c                     US   U l         g r+  r,  r   s     r    r!   -ProtectionAllowForcePushes._update_attributes  r.  r#   r,  Nr/  re   r#   r    r   r     r0  r#   r   c                       \ rS rSrSrS rSrg)r   i  a  The representation of a sub-portion of branch protection.

.. seealso::

    `Branch protection API documentation`_
        GitHub's documentation of branch protection

This object has the following attributes:

.. attribute:: enabled

    A boolean attribute indicating whether the ``allow_deletions``
    protection is enabled or disabled.

.. links
.. _Branch protection API documentation:
    https://developer.github.com/v3/repos/branches/#get-branch-protection
c                     US   U l         g r+  r,  r   s     r    r!   +ProtectionAllowDeletions._update_attributes  r.  r#   r,  Nr/  re   r#   r    r   r     r0  r#   r   c                       \ rS rSrSrS rSrg)r   i#  a  The representation of a sub-portion of branch protection.

.. seealso::

    `Branch protection API documentation`_
        GitHub's documentation of branch protection

This object has the following attributes:

.. attribute:: enabled

    A boolean attribute indicating whether the
    ``required_conversation_resolution`` protection is enabled or
    disabled.

.. links
.. _Branch protection API documentation:
    https://developer.github.com/v3/repos/branches/#get-branch-protection
c                     US   U l         g r+  r,  r   s     r    r!   ;ProtectionRequiredConversationResolution._update_attributes8  r.  r#   r,  Nr/  re   r#   r    r   r   #  s    (-r#   r   )rZ   typingr]   rT   r   r   r   TYPE_CHECKINGr	   tappsr   tusersr   
GitHubCorer   rg   rt   r8   r   r   r   r   r   r   r   r   re   r#   r    <module>r?     s   1    ?? "w
f w
t3+W 3+l' >j-v(( j-Z&-f// &-RlHV.. lH^L-6+<+< L-^g-V%6%6 g-T-f&7&7 -0-!2!2 -0-v00 -0-v/@/@ -r#   