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

Jlvillal/archive#1758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
JohnVillalovos wants to merge2 commits intomainfromjlvillal/archive
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletionsdocs/gl_objects/projects.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -180,6 +180,14 @@ Get the repository archive::
# get the archive for a branch/tag/commit
tgz = project.repository_archive(sha='4567abc')

# get the archive in a different format
zip = project.repository_archive(format='zip')

.. note::

For the formats available, refer to
https://docs.gitlab.com/ce/api/repositories.html#get-file-archive

.. warning::

Archives are entirely stored in memory unless you use the streaming feature.
Expand Down
2 changes: 1 addition & 1 deletiongitlab/client.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -603,7 +603,7 @@ def http_request(
prepped = self.session.prepare_request(req)
if TYPE_CHECKING:
assert prepped.url is not None
prepped.url = utils.sanitized_url(prepped.url)
#prepped.url = utils.sanitized_url(prepped.url)
settings = self.session.merge_environment_settings(
prepped.url, {}, streamed, verify, None
)
Expand Down
8 changes: 6 additions & 2 deletionsgitlab/v4/objects/repositories.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,17 +186,18 @@ def repository_contributors(
path = f"/projects/{self.get_id()}/repository/contributors"
return self.manager.gitlab.http_list(path, **kwargs)

@cli.register_custom_action("Project", tuple(), ("sha",))
@cli.register_custom_action("Project", tuple(), ("sha", "format"))
@exc.on_http_error(exc.GitlabListError)
def repository_archive(
self,
sha: str = None,
streamed: bool = False,
action: Optional[Callable[..., Any]] = None,
chunk_size: int = 1024,
format: Optional[str] = None,
**kwargs: Any,
) -> Optional[bytes]:
"""Returna tarball of the repository.
"""Returnan archive of the repository.

Args:
sha: ID of the commit (default branch by default)
Expand All@@ -206,6 +207,7 @@ def repository_archive(
action: Callable responsible of dealing with chunk of
data
chunk_size: Size of each chunk
format: file format (tar.gz by default)
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
Expand All@@ -216,6 +218,8 @@ def repository_archive(
The binary data of the archive
"""
path = f"/projects/{self.get_id()}/repository/archive"
if format:
path += "." + format
query_data = {}
if sha:
query_data["sha"] = sha
Expand Down
27 changes: 25 additions & 2 deletionstests/functional/api/test_repository.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
import base64
import tarfile
import time
import zipfile
from io import BytesIO

import pytest

Expand DownExpand Up@@ -48,14 +51,34 @@ def test_repository_tree(project):
blob = project.repository_raw_blob(blob_id)
assert blob.decode() == "Initial content"

snapshot = project.snapshot()
assert isinstance(snapshot, bytes)


def test_repository_archive(project):
archive = project.repository_archive()
assert isinstance(archive, bytes)

archive2 = project.repository_archive("main")
assert archive == archive2

snapshot = project.snapshot()
assert isinstance(snapshot, bytes)

@pytest.mark.parametrize(
"format,assertion",
[
("tbz", tarfile.is_tarfile),
("tbz2", tarfile.is_tarfile),
("tb2", tarfile.is_tarfile),
("bz2", tarfile.is_tarfile),
("tar", tarfile.is_tarfile),
("tar.gz", tarfile.is_tarfile),
("tar.bz2", tarfile.is_tarfile),
("zip", zipfile.is_zipfile),
],
)
def test_repository_archive_formats(project, format, assertion):
archive = project.repository_archive(format=format)
assert assertion(BytesIO(archive))


def test_create_commit(project):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp