3 @qhc @s:dZddlmZddlmZddlmZGdddZdS)z GitLab API: https://docs.gitlab.com/ee/api/repositories.html Currently this module only contains repository-related methods for projects. )cli) exceptions)utilsc@seZdZejddejejddZejde d ejej d!d d Z ejdd"ejej ddZ ejdd#ejej d$ddZ ejdd%ejej ddZejdejej ddZejde d&ejejd'ddZejdejejddZdS)(RepositoryMixinZProject submodulebranch commit_shacKsL|jdd}d|j|f}||d}d|kr:|d|d<|jjj||dS)aUpdate 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)replaceget_idmanagergitlabZhttp_put)selfrrrkwargspathdatar]/home/ec2-user/environment/venv/lib/python3.6/dist-packages/gitlab/v4/objects/repositories.pyupdate_submodule s    z RepositoryMixin.update_submodulerref recursiveFcKsFd|j}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 http_list)rrrrrZgl_pathrrrrrepository_tree$s zRepositoryMixin.repository_treeshacKs"d|j|f}|jjj|f|S)aReturn 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)rrrrrrrrepository_blobCszRepositoryMixin.repository_blobNcKs<d|j|f}|jjj|f|dd|}tj||||S)aReturn 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)streamedraw)r r r rrresponse_content)rrraction chunk_sizerrresultrrrrepository_raw_blobWsz#RepositoryMixin.repository_raw_blobfrom_tocKs0d|j}||d}|jjj|fd|i|S)aReturn 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'r)r r r r)rr&r'rrrrrrrepository_compareus  z"RepositoryMixin.repository_comparecKsd|j}|jjj|f|S)aReturn 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/contributors)r r r r)rrrrrrrepository_contributorss z'RepositoryMixin.repository_contributorsc KsJd|j}i}|r||d<|jjj|f|d|d|}tj||||S)aReturn 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 r r rrr!) rrrr"r#rrrr$rrrrepository_archives z"RepositoryMixin.repository_archivecKs"d|j}|jjj|f|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_delete)rrrrrrdelete_merged_branchess z&RepositoryMixin.delete_merged_branches)rrr)rrr)rrF)r)r)FNr)r&r')r)NFNr)__name__ __module__ __qualname__rZregister_custom_actionexcZ on_http_errorZGitlabUpdateErrorrtupleZGitlabGetErrorrrr%r)r*ZGitlabListErrorr+ZGitlabDeleteErrorr,rrrrr s&       rN)__doc__r rrr0rrrrrrs