Skip to content

Support downloading archive subpaths #2199

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2022
Merged

Support downloading archive subpaths #2199

merged 1 commit into from
Jul 29, 2022

Conversation

orf
Copy link
Contributor

@orf orf commented Jul 28, 2022

https://docs.gitlab.com/ee/api/repositories.html#get-file-archive

The archive endpoint supports a path argument. This change adds support for it.

@JohnVillalovos JohnVillalovos enabled auto-merge (rebase) July 28, 2022 17:22
@JohnVillalovos
Copy link
Member

@orf Thanks for the contribution!

@JohnVillalovos JohnVillalovos disabled auto-merge July 28, 2022 17:31
Copy link
Member

@JohnVillalovos JohnVillalovos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like conflict with the pre-existing path variable.

@nejch
Copy link
Member

nejch commented Jul 29, 2022

@JohnVillalovos for later: we could potentially also prefix these internal python-gitlab variables in the mixins and custom methods to always avoid clashes with GitLab API attributes. So this would be _path here for example. Not sure how ugly that would get.

@orf sometimes our variables happen to overlap with upstream API attributes hence the suggestion.

diff --git a/gitlab/v4/objects/repositories.py b/gitlab/v4/objects/repositories.py
index 8f99e5d..b8dbdd8 100644
--- a/gitlab/v4/objects/repositories.py
+++ b/gitlab/v4/objects/repositories.py
@@ -229,16 +229,16 @@ class RepositoryMixin(_RestObjectBase):
         Returns:
             The binary data of the archive
         """
-        path = f"/projects/{self.encoded_id}/repository/archive"
+        url_path = f"/projects/{self.encoded_id}/repository/archive"
         if format:
-            path += "." + format
+            url_path += "." + format
         query_data = {}
         if sha:
             query_data["sha"] = sha
         if path is not None:
             query_data["path"] = path
         result = self.manager.gitlab.http_get(
-            path, query_data=query_data, raw=True, streamed=streamed, **kwargs
+            url_path, query_data=query_data, raw=True, streamed=streamed, **kwargs
         )
         if TYPE_CHECKING:
             assert isinstance(result, requests.Response)

@orf
Copy link
Contributor Author

orf commented Jul 29, 2022

Thank you both! I've applied your suggestions 🙏

@nejch
Copy link
Member

nejch commented Jul 29, 2022

I guess we can get this one in, I hope you don't mind @JohnVillalovos ;)

@orf thanks again! I think I recognized your username from the loguru saga, fun popcorn material. :)

@nejch nejch merged commit 5e1df65 into python-gitlab:main Jul 29, 2022
@orf orf deleted the patch-1 branch July 29, 2022 12:50
@JohnVillalovos
Copy link
Member

I guess we can get this one in, I hope you don't mind @JohnVillalovos ;)

Thanks for reviewing it @nejch !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants