Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3910048

Browse files
committed
feat(api): support file format for repository archive
1 parentae97196 commit3910048

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
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
returnself.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
defrepository_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-
"""Returna tarball of the repository.
172+
"""Returnan 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+
ifformat:
194+
path+="."+format
186195
query_data= {}
187196
ifsha:
188197
query_data["sha"]=sha

‎tests/functional/api/test_repository.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
importbase64
2+
importtarfile
23
importtime
4+
importzipfile
5+
fromioimportBytesIO
36

47
importpytest
58

@@ -48,14 +51,34 @@ def test_repository_tree(project):
4851
blob=project.repository_raw_blob(blob_id)
4952
assertblob.decode()=="Initial content"
5053

54+
snapshot=project.snapshot()
55+
assertisinstance(snapshot,bytes)
56+
57+
58+
deftest_repository_archive(project):
5159
archive=project.repository_archive()
5260
assertisinstance(archive,bytes)
5361

5462
archive2=project.repository_archive("master")
5563
assertarchive==archive2
5664

57-
snapshot=project.snapshot()
58-
assertisinstance(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+
deftest_repository_archive_formats(project,format,assertion):
80+
archive=project.repository_archive(format=format)
81+
assertassertion(BytesIO(archive))
5982

6083

6184
deftest_create_commit(project):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp