Skip to content

Commit 5e1df65

Browse files
authored
Merge pull request #2199 from orf/patch-1
Support downloading archive subpaths
2 parents b8be32a + cadb0e5 commit 5e1df65

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

gitlab/v4/objects/repositories.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def repository_archive(
201201
action: Optional[Callable[..., Any]] = None,
202202
chunk_size: int = 1024,
203203
format: Optional[str] = None,
204+
path: Optional[str] = None,
204205
*,
205206
iterator: bool = False,
206207
**kwargs: Any,
@@ -218,6 +219,7 @@ def repository_archive(
218219
data
219220
chunk_size: Size of each chunk
220221
format: file format (tar.gz by default)
222+
path: The subpath of the repository to download (all files by default)
221223
**kwargs: Extra options to send to the server (e.g. sudo)
222224
223225
Raises:
@@ -227,14 +229,16 @@ def repository_archive(
227229
Returns:
228230
The binary data of the archive
229231
"""
230-
path = f"/projects/{self.encoded_id}/repository/archive"
232+
url_path = f"/projects/{self.encoded_id}/repository/archive"
231233
if format:
232-
path += "." + format
234+
url_path += "." + format
233235
query_data = {}
234236
if sha:
235237
query_data["sha"] = sha
238+
if path is not None:
239+
query_data["path"] = path
236240
result = self.manager.gitlab.http_get(
237-
path, query_data=query_data, raw=True, streamed=streamed, **kwargs
241+
url_path, query_data=query_data, raw=True, streamed=streamed, **kwargs
238242
)
239243
if TYPE_CHECKING:
240244
assert isinstance(result, requests.Response)

0 commit comments

Comments
 (0)