| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eef8059 commit 85252e4
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -180,6 +180,14 @@ Get the repository archive:: | |||
| 180 | 180 | # get the archive for a branch/tag/commit | |
| 181 | 181 | tgz = project.repository_archive(sha='4567abc') | |
| 182 | 182 | ||
| 183 | + # get the archive in a different format | ||
| 184 | + zip = project.repository_archive(format='zip') | ||
| 185 | + | ||
| 186 | + .. note:: | ||
| 187 | + | ||
| 188 | + For the formats available, refer to | ||
| 189 | + https://docs.gitlab.com/ce/api/repositories.html#get-file-archive | ||
| 190 | + | ||
| 183 | 191 | .. warning:: | |
| 184 | 192 | ||
| 185 | 193 | Archives are entirely stored in memory unless you use the streaming feature. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -186,17 +186,18 @@ def repository_contributors( | |||
| 186 | 186 | path = f"/projects/{self.get_id()}/repository/contributors" | |
| 187 | 187 | return self.manager.gitlab.http_list(path, **kwargs) | |
| 188 | 188 | ||
| 189 | - @cli.register_custom_action("Project", tuple(), ("sha",)) | ||
| 189 | + @cli.register_custom_action("Project", tuple(), ("sha", "format")) | ||
| 190 | 190 | @exc.on_http_error(exc.GitlabListError) | |
| 191 | 191 | def repository_archive( | |
| 192 | 192 | self, | |
| 193 | 193 | sha: str = None, | |
| 194 | 194 | streamed: bool = False, | |
| 195 | 195 | action: Optional[Callable[..., Any]] = None, | |
| 196 | 196 | chunk_size: int = 1024, | |
| 197 | + format: Optional[str] = None, | ||
| 197 | 198 | **kwargs: Any, | |
| 198 | 199 | ) -> Optional[bytes]: | |
| 199 | - """Return a tarball of the repository. | ||
| 200 | + """Return an archive of the repository. | ||
| 200 | 201 | ||
| 201 | 202 | Args: | |
| 202 | 203 | sha: ID of the commit (default branch by default) | |
@@ -206,6 +207,7 @@ def repository_archive( | |||
| 206 | 207 | action: Callable responsible of dealing with chunk of | |
| 207 | 208 | data | |
| 208 | 209 | chunk_size: Size of each chunk | |
| 210 | + format: file format (tar.gz by default) | ||
| 209 | 211 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 210 | 212 | ||
| 211 | 213 | Raises: | |
@@ -216,6 +218,8 @@ def repository_archive( | |||
| 216 | 218 | The binary data of the archive | |
| 217 | 219 | """ | |
| 218 | 220 | path = f"/projects/{self.get_id()}/repository/archive" | |
| 221 | + if format: | ||
| 222 | + path += "." + format | ||
| 219 | 223 | query_data = {} | |
| 220 | 224 | if sha: | |
| 221 | 225 | query_data["sha"] = sha | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,8 @@ | |||
| 1 | 1 | import base64 | |
| 2 | + import tarfile | ||
| 2 | 3 | import time | |
| 4 | + import zipfile | ||
| 5 | + from io import BytesIO | ||
| 3 | 6 | ||
| 4 | 7 | import pytest | |
| 5 | 8 | ||
@@ -48,14 +51,34 @@ def test_repository_tree(project): | |||
| 48 | 51 | blob = project.repository_raw_blob(blob_id) | |
| 49 | 52 | assert blob.decode() == "Initial content" | |
| 50 | 53 | ||
| 54 | + snapshot = project.snapshot() | ||
| 55 | + assert isinstance(snapshot, bytes) | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + def test_repository_archive(project): | ||
| 51 | 59 | archive = project.repository_archive() | |
| 52 | 60 | assert isinstance(archive, bytes) | |
| 53 | 61 | ||
| 54 | 62 | archive2 = project.repository_archive("main") | |
| 55 | 63 | assert archive == archive2 | |
| 56 | 64 | ||
| 57 | - snapshot = project.snapshot() | ||
| 58 | - assert isinstance(snapshot, bytes) | ||
| 65 | + | ||
| 66 | + @pytest.mark.parametrize( | ||
| 67 | + "format,assertion", | ||
| 68 | + [ | ||
| 69 | + ("tbz", tarfile.is_tarfile), | ||
| 70 | + ("tbz2", tarfile.is_tarfile), | ||
| 71 | + ("tb2", tarfile.is_tarfile), | ||
| 72 | + ("bz2", tarfile.is_tarfile), | ||
| 73 | + ("tar", tarfile.is_tarfile), | ||
| 74 | + ("tar.gz", tarfile.is_tarfile), | ||
| 75 | + ("tar.bz2", tarfile.is_tarfile), | ||
| 76 | + ("zip", zipfile.is_zipfile), | ||
| 77 | + ], | ||
| 78 | + ) | ||
| 79 | + def test_repository_archive_formats(project, format, assertion): | ||
| 80 | + archive = project.repository_archive(format=format) | ||
| 81 | + assert assertion(BytesIO(archive)) | ||
| 59 | 82 | ||
| 60 | 83 | ||
| 61 | 84 | def test_create_commit(project): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments