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

Commitdafcef1

Browse files
committed
feat(api): support file format for repository archive
1 parentac7e329 commitdafcef1

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

‎docs/gl_objects/projects.rst

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

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+
183191
..warning::
184192

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

‎gitlab/v4/objects/repositories.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,18 @@ def repository_contributors(
186186
path=f"/projects/{self.get_id()}/repository/contributors"
187187
returnself.manager.gitlab.http_list(path,**kwargs)
188188

189-
@cli.register_custom_action("Project",tuple(), ("sha",))
189+
@cli.register_custom_action("Project",tuple(), ("sha","format"))
190190
@exc.on_http_error(exc.GitlabListError)
191191
defrepository_archive(
192192
self,
193193
sha:str=None,
194194
streamed:bool=False,
195195
action:Optional[Callable[...,Any]]=None,
196196
chunk_size:int=1024,
197+
format:Optional[str]=None,
197198
**kwargs:Any,
198199
)->Optional[bytes]:
199-
"""Returna tarball of the repository.
200+
"""Returnan archive of the repository.
200201
201202
Args:
202203
sha: ID of the commit (default branch by default)
@@ -206,6 +207,7 @@ def repository_archive(
206207
action: Callable responsible of dealing with chunk of
207208
data
208209
chunk_size: Size of each chunk
210+
format: file format (tar.gz by default)
209211
**kwargs: Extra options to send to the server (e.g. sudo)
210212
211213
Raises:
@@ -216,6 +218,8 @@ def repository_archive(
216218
The binary data of the archive
217219
"""
218220
path=f"/projects/{self.get_id()}/repository/archive"
221+
ifformat:
222+
path+="."+format
219223
query_data= {}
220224
ifsha:
221225
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("main")
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