a Æ*Naª ã@s:dZddlmZddlmZddlmZGdd„dƒZdS)zŒ GitLab API: https://docs.gitlab.com/ee/api/repositories.html Currently this module only contains repository-related methods for projects. é)Úcli)Ú exceptions)Úutilsc@seZdZe dd¡e ej¡dd„ƒƒZe de ƒd¡e ej ¡ddd „ƒƒZ e dd ¡e ej ¡d d „ƒƒZ e dd ¡e ej ¡ddd„ƒƒZ e dd¡e ej ¡dd„ƒƒZe d¡e ej ¡dd„ƒƒZe de ƒd ¡e ej¡ddd„ƒƒZe d¡e ej¡dd„ƒƒZd S)ÚRepositoryMixinZProject)Ú submoduleÚbranchÚ commit_shacKsL| dd¡}d| ¡|f}||dœ}d|vr:|d|d<|jjj||dS)aüUpdate a project submodule Args: submodule (str): Full path to the submodule branch (str): Name of the branch to commit into commit_sha (str): Full commit SHA to update the submodule to commit_message (str): Commit message. If no message is provided, a default one will be set (optional) Raises: GitlabAuthenticationError: If authentication is not correct GitlabPutError: If the submodule could not be updated ú/z%2Fz%/projects/%s/repository/submodules/%s)rrZcommit_message)Z post_data)ÚreplaceÚget_idÚmanagerÚgitlabZhttp_put)ÚselfrrrÚkwargsÚpathÚdata©rúy/private/var/folders/js/6pj4vh5d4zd0k6bxv74qrbhr0000gr/T/pip-target-22xwyzbs/lib/python/gitlab/v4/objects/repositories.pyÚupdate_submodule s    z RepositoryMixin.update_submodule)rÚrefÚ recursiveÚFcKsFd| ¡}d|i}|r ||d<|r,||d<|jjj|fd|i|¤ŽS)a|Return a list of files in the repository. Args: path (str): Path of the top folder (/ by default) ref (str): Reference to a commit or branch recursive (bool): Whether to get the tree recursively all (bool): If True, return all the items, without pagination per_page (int): Number of items to retrieve per request page (int): ID of the page to return (starts with page 1) as_list (bool): If set to False and no pagination option is defined, return a generator instead of a list **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server failed to perform the request Returns: list: The representation of the tree z/projects/%s/repository/treerrrÚ query_data©r r r Z http_list)rrrrrZgl_pathrrrrÚrepository_tree$s zRepositoryMixin.repository_tree)ÚshacKs&d| ¡|f}|jjj|fi|¤ŽS)a€Return a file by blob SHA. Args: sha(str): ID of the blob **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server failed to perform the request Returns: dict: The blob content and metadata z /projects/%s/repository/blobs/%s©r r r Úhttp_get)rrrrrrrÚrepository_blobCszRepositoryMixin.repository_blobNécKs<d| ¡|f}|jjj|f|ddœ|¤Ž}t ||||¡S)aåReturn the raw file contents for a blob. Args: sha(str): ID of the blob streamed (bool): If True the data will be processed by chunks of `chunk_size` and each chunk is passed to `action` for treatment action (callable): Callable responsible of dealing with chunk of data chunk_size (int): Size of each chunk **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server failed to perform the request Returns: str: The blob content if streamed is False, None otherwise z$/projects/%s/repository/blobs/%s/rawT)ÚstreamedÚraw©r r r rrZresponse_content)rrr ÚactionÚ chunk_sizerrÚresultrrrÚrepository_raw_blobWsÿÿÿz#RepositoryMixin.repository_raw_blob)Úfrom_ÚtocKs0d| ¡}||dœ}|jjj|fd|i|¤ŽS)a¬Return a diff between two branches/commits. Args: from_(str): Source branch/SHA to(str): Destination branch/SHA **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server failed to perform the request Returns: str: The diff z/projects/%s/repository/compare)Úfromr(rr)rr'r(rrrrrrÚrepository_compareus  z"RepositoryMixin.repository_comparecKs"d| ¡}|jjj|fi|¤ŽS)a¼Return a list of contributors for the project. Args: all (bool): If True, return all the items, without pagination per_page (int): Number of items to retrieve per request page (int): ID of the page to return (starts with page 1) as_list (bool): If set to False and no pagination option is defined, return a generator instead of a list **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server failed to perform the request Returns: list: The contributors z$/projects/%s/repository/contributorsr©rrrrrrÚrepository_contributorsŠs z'RepositoryMixin.repository_contributorsc KsJd| ¡}i}|r||d<|jjj|f|d|dœ|¤Ž}t ||||¡S)aéReturn a tarball of the repository. Args: sha (str): ID of the commit (default branch by default) streamed (bool): If True the data will be processed by chunks of `chunk_size` and each chunk is passed to `action` for treatment action (callable): Callable responsible of dealing with chunk of data chunk_size (int): Size of each chunk **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabListError: If the server failed to perform the request Returns: str: The binary data of the archive z/projects/%s/repository/archiverT)rr!r r") rrr r#r$rrrr%rrrÚrepository_archive¡s ÿÿÿz"RepositoryMixin.repository_archivecKs&d| ¡}|jjj|fi|¤ŽdS)aDelete merged branches. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server failed to perform the request z'/projects/%s/repository/merged_branchesN)r r r Z http_deleter+rrrÚdelete_merged_branchesÂs z&RepositoryMixin.delete_merged_branches)rrF)FNr)NFNr)Ú__name__Ú __module__Ú __qualname__rZregister_custom_actionÚexcZ on_http_errorZGitlabUpdateErrorrÚtupleZGitlabGetErrorrrr&r*r,ZGitlabListErrorr-ZGitlabDeleteErrorr.rrrrr s4         ÿ      ÿ rN)Ú__doc__r rrr2rrrrrrÚs