Skip to content

Commit 3c38eb6

Browse files
committed
feat(api): support file format for repository archive
1 parent ae97196 commit 3c38eb6

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

docs/gl_objects/projects.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ Get the repository archive::
170170
# get the archive for a branch/tag/commit
171171
tgz = project.repository_archive(sha='4567abc')
172172

173+
# get the archive in a different format
174+
zip = project.repository_archive(format='zip')
175+
176+
.. note::
177+
178+
For the formats available, refer to
179+
https://docs.gitlab.com/ce/api/repositories.html#get-file-archive
180+
173181
.. warning::
174182

175183
Archives are entirely stored in memory unless you use the streaming feature.

gitlab/v4/objects/repositories.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,18 @@ def repository_contributors(self, **kwargs):
158158
path = "/projects/%s/repository/contributors" % self.get_id()
159159
return self.manager.gitlab.http_list(path, **kwargs)
160160

161-
@cli.register_custom_action("Project", tuple(), ("sha",))
161+
@cli.register_custom_action("Project", tuple(), ("sha", "format"))
162162
@exc.on_http_error(exc.GitlabListError)
163163
def repository_archive(
164-
self, sha=None, streamed=False, action=None, chunk_size=1024, **kwargs
164+
self,
165+
sha=None,
166+
streamed=False,
167+
action=None,
168+
chunk_size=1024,
169+
format=None,
170+
**kwargs
165171
):
166-
"""Return a tarball of the repository.
172+
"""Return an archive of the repository.
167173
168174
Args:
169175
sha (str): ID of the commit (default branch by default)
@@ -173,6 +179,7 @@ def repository_archive(
173179
action (callable): Callable responsible of dealing with chunk of
174180
data
175181
chunk_size (int): Size of each chunk
182+
format (str): file format (tar.gz by default)
176183
**kwargs: Extra options to send to the server (e.g. sudo)
177184
178185
Raises:
@@ -183,6 +190,8 @@ def repository_archive(
183190
str: The binary data of the archive
184191
"""
185192
path = "/projects/%s/repository/archive" % self.get_id()
193+
if format:
194+
path += "." + format
186195
query_data = {}
187196
if sha:
188197
query_data["sha"] = sha

0 commit comments

Comments
 (0)