| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8202e3f commit 3a49f09
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,7 @@ def upload( | |||
| 47 | 47 | package_version: str, | |
| 48 | 48 | file_name: str, | |
| 49 | 49 | path: Union[str, Path], | |
| 50 | + select: Optional[str] = None, | ||
| 50 | 51 | **kwargs: Any, | |
| 51 | 52 | ) -> GenericPackage: | |
| 52 | 53 | """Upload a file as a generic package. | |
@@ -58,6 +59,7 @@ def upload( | |||
| 58 | 59 | version regex rules | |
| 59 | 60 | file_name: The name of the file as uploaded in the registry | |
| 60 | 61 | path: The path to a local file to upload | |
| 62 | + select: GitLab API accepts a value of 'package_file' | ||
| 61 | 63 | ||
| 62 | 64 | Raises: | |
| 63 | 65 | GitlabConnectionError: If the server cannot be reached | |
@@ -77,20 +79,21 @@ def upload( | |||
| 77 | 79 | raise exc.GitlabUploadError(f"Failed to read package file {path}") from e | |
| 78 | 80 | ||
| 79 | 81 | url = f"{self._computed_path}/{package_name}/{package_version}/{file_name}" | |
| 80 | - server_data = self.gitlab.http_put(url, post_data=file_data, raw=True, **kwargs) | ||
| 82 | + query_data = {} if select is None else {"select": select} | ||
| 83 | + server_data = self.gitlab.http_put( | ||
| 84 | + url, query_data=query_data, post_data=file_data, raw=True, **kwargs | ||
| 85 | + ) | ||
| 81 | 86 | if TYPE_CHECKING: | |
| 82 | 87 | assert isinstance(server_data, dict) | |
| 83 | 88 | ||
| 84 | - return self._obj_cls( | ||
| 85 | - self, | ||
| 86 | - attrs={ | ||
| 87 | - "package_name": package_name, | ||
| 88 | - "package_version": package_version, | ||
| 89 | - "file_name": file_name, | ||
| 90 | - "path": path, | ||
| 91 | - "message": server_data["message"], | ||
| 92 | - }, | ||
| 93 | - ) | ||
| 89 | + attrs = { | ||
| 90 | + "package_name": package_name, | ||
| 91 | + "package_version": package_version, | ||
| 92 | + "file_name": file_name, | ||
| 93 | + "path": path, | ||
| 94 | + } | ||
| 95 | + attrs.update(server_data) | ||
| 96 | + return self._obj_cls(self, attrs=attrs) | ||
| 94 | 97 | ||
| 95 | 98 | @cli.register_custom_action( | |
| 96 | 99 | "GenericPackageManager", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ | |||
| 10 | 10 | package_name = "hello-world" | |
| 11 | 11 | package_version = "v1.0.0" | |
| 12 | 12 | file_name = "hello.tar.gz" | |
| 13 | + file_name2 = "hello2.tar.gz" | ||
| 13 | 14 | file_content = "package content" | |
| 14 | 15 | ||
| 15 | 16 | ||
@@ -37,6 +38,22 @@ def test_upload_generic_package(tmp_path, project): | |||
| 37 | 38 | assert package.message == "201 Created" | |
| 38 | 39 | ||
| 39 | 40 | ||
| 41 | + def test_upload_generic_package_select(tmp_path, project): | ||
| 42 | + path = tmp_path / file_name2 | ||
| 43 | + path.write_text(file_content) | ||
| 44 | + package = project.generic_packages.upload( | ||
| 45 | + package_name=package_name, | ||
| 46 | + package_version=package_version, | ||
| 47 | + file_name=file_name2, | ||
| 48 | + path=path, | ||
| 49 | + select="package_file", | ||
| 50 | + ) | ||
| 51 | + | ||
| 52 | + assert isinstance(package, GenericPackage) | ||
| 53 | + assert package.file_name == file_name2 | ||
| 54 | + assert package.size == path.stat().st_size | ||
| 55 | + | ||
| 56 | + | ||
| 40 | 57 | def test_download_generic_package(project): | |
| 41 | 58 | package = project.generic_packages.download( | |
| 42 | 59 | package_name=package_name, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments