| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9a2f54c commit 7828ba2
22 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -495,10 +495,10 @@ def _check_redirects(self, result: requests.Response) -> None: | |||
| 495 | 495 | def _prepare_send_data( | |
| 496 | 496 | self, | |
| 497 | 497 | files: Optional[Dict[str, Any]] = None, | |
| 498 | - post_data: Optional[Dict[str, Any]] = None, | ||
| 498 | + post_data: Optional[Union[Dict[str, Any], bytes]] = None, | ||
| 499 | 499 | raw: bool = False, | |
| 500 | 500 | ) -> Tuple[ | |
| 501 | - Optional[Dict[str, Any]], | ||
| 501 | + Optional[Union[Dict[str, Any], bytes]], | ||
| 502 | 502 | Optional[Union[Dict[str, Any], MultipartEncoder]], | |
| 503 | 503 | str, | |
| 504 | 504 | ]: | |
@@ -508,6 +508,8 @@ def _prepare_send_data( | |||
| 508 | 508 | else: | |
| 509 | 509 | # booleans does not exists for data (neither for MultipartEncoder): | |
| 510 | 510 | # cast to string int to avoid: 'bool' object has no attribute 'encode' | |
| 511 | + if TYPE_CHECKING: | ||
| 512 | + assert isinstance(post_data, dict) | ||
| 511 | 513 | for k, v in post_data.items(): | |
| 512 | 514 | if isinstance(v, bool): | |
| 513 | 515 | post_data[k] = str(int(v)) | |
@@ -527,7 +529,7 @@ def http_request( | |||
| 527 | 529 | verb: str, | |
| 528 | 530 | path: str, | |
| 529 | 531 | query_data: Optional[Dict[str, Any]] = None, | |
| 530 | - post_data: Optional[Dict[str, Any]] = None, | ||
| 532 | + post_data: Optional[Union[Dict[str, Any], bytes]] = None, | ||
| 531 | 533 | raw: bool = False, | |
| 532 | 534 | streamed: bool = False, | |
| 533 | 535 | files: Optional[Dict[str, Any]] = None, | |
@@ -544,7 +546,7 @@ def http_request( | |||
| 544 | 546 | path (str): Path or full URL to query ('/projects' or | |
| 545 | 547 | 'http://whatever/v4/api/projecs') | |
| 546 | 548 | query_data (dict): Data to send as query parameters | |
| 547 | - post_data (dict): Data to send in the body (will be converted to | ||
| 549 | + post_data (dict|bytes): Data to send in the body (will be converted to | ||
| 548 | 550 | json by default) | |
| 549 | 551 | raw (bool): If True, do not convert post_data to json | |
| 550 | 552 | streamed (bool): Whether the data should be streamed | |
@@ -800,7 +802,7 @@ def http_put( | |||
| 800 | 802 | self, | |
| 801 | 803 | path: str, | |
| 802 | 804 | query_data: Optional[Dict[str, Any]] = None, | |
| 803 | - post_data: Optional[Dict[str, Any]] = None, | ||
| 805 | + post_data: Optional[Union[Dict[str, Any], bytes]] = None, | ||
| 804 | 806 | raw: bool = False, | |
| 805 | 807 | files: Optional[Dict[str, Any]] = None, | |
| 806 | 808 | **kwargs: Any, | |
@@ -811,7 +813,7 @@ def http_put( | |||
| 811 | 813 | path (str): Path or full URL to query ('/projects' or | |
| 812 | 814 | 'http://whatever/v4/api/projecs') | |
| 813 | 815 | query_data (dict): Data to send as query parameters | |
| 814 | - post_data (dict): Data to send in the body (will be converted to | ||
| 816 | + post_data (dict|bytes): Data to send in the body (will be converted to | ||
| 815 | 817 | json by default) | |
| 816 | 818 | raw (bool): If True, do not convert post_data to json | |
| 817 | 819 | files (dict): The files to send to the server | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,6 +103,8 @@ def do_project_export_download(self) -> None: | |||
| 103 | 103 | if TYPE_CHECKING: | |
| 104 | 104 | assert export_status is not None | |
| 105 | 105 | data = export_status.download() | |
| 106 | + if TYPE_CHECKING: | ||
| 107 | + assert data is not None | ||
| 106 | 108 | sys.stdout.buffer.write(data) | |
| 107 | 109 | ||
| 108 | 110 | except Exception as e: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + from typing import Any, cast, Dict, Optional, Union | ||
| 2 | + | ||
| 1 | 3 | from gitlab import exceptions as exc | |
| 2 | 4 | from gitlab.base import RequiredOptional, RESTManager, RESTObject | |
| 3 | 5 | from gitlab.mixins import GetWithoutIdMixin, SaveMixin, UpdateMixin | |
@@ -32,7 +34,12 @@ class ApplicationAppearanceManager(GetWithoutIdMixin, UpdateMixin, RESTManager): | |||
| 32 | 34 | ) | |
| 33 | 35 | ||
| 34 | 36 | @exc.on_http_error(exc.GitlabUpdateError) | |
| 35 | - def update(self, id=None, new_data=None, **kwargs): | ||
| 37 | + def update( | ||
| 38 | + self, | ||
| 39 | + id: Optional[Union[str, int]] = None, | ||
| 40 | + new_data: Dict[str, Any] = None, | ||
| 41 | + **kwargs: Any | ||
| 42 | + ) -> Dict[str, Any]: | ||
| 36 | 43 | """Update an object on the server. | |
| 37 | 44 | ||
| 38 | 45 | Args: | |
@@ -49,4 +56,9 @@ def update(self, id=None, new_data=None, **kwargs): | |||
| 49 | 56 | """ | |
| 50 | 57 | new_data = new_data or {} | |
| 51 | 58 | data = new_data.copy() | |
| 52 | - super(ApplicationAppearanceManager, self).update(id, data, **kwargs) | ||
| 59 | + return super(ApplicationAppearanceManager, self).update(id, data, **kwargs) | ||
| 60 | + | ||
| 61 | + def get( | ||
| 62 | + self, id: Optional[Union[int, str]] = None, **kwargs: Any | ||
| 63 | + ) -> Optional[ApplicationAppearance]: | ||
| 64 | + return cast(ApplicationAppearance, super().get(id=id, **kwargs)) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + from typing import Any, cast, Union | ||
| 2 | + | ||
| 1 | 3 | from gitlab.base import RequiredOptional, RESTManager, RESTObject | |
| 2 | 4 | from gitlab.mixins import BadgeRenderMixin, CRUDMixin, ObjectDeleteMixin, SaveMixin | |
| 3 | 5 | ||
@@ -31,3 +33,8 @@ class ProjectBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager): | |||
| 31 | 33 | _from_parent_attrs = {"project_id": "id"} | |
| 32 | 34 | _create_attrs = RequiredOptional(required=("link_url", "image_url")) | |
| 33 | 35 | _update_attrs = RequiredOptional(optional=("link_url", "image_url")) | |
| 36 | + | ||
| 37 | + def get( | ||
| 38 | + self, id: Union[str, int], lazy: bool = False, **kwargs: Any | ||
| 39 | + ) -> ProjectBadge: | ||
| 40 | + return cast(ProjectBadge, super().get(id=id, lazy=lazy, **kwargs)) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + from typing import Any, cast, Union | ||
| 2 | + | ||
| 1 | 3 | from gitlab.base import RequiredOptional, RESTManager, RESTObject | |
| 2 | 4 | from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin | |
| 3 | 5 | ||
@@ -24,6 +26,11 @@ class GroupBoardListManager(CRUDMixin, RESTManager): | |||
| 24 | 26 | _create_attrs = RequiredOptional(required=("label_id",)) | |
| 25 | 27 | _update_attrs = RequiredOptional(required=("position",)) | |
| 26 | 28 | ||
| 29 | + def get( | ||
| 30 | + self, id: Union[str, int], lazy: bool = False, **kwargs: Any | ||
| 31 | + ) -> GroupBoardList: | ||
| 32 | + return cast(GroupBoardList, super().get(id=id, lazy=lazy, **kwargs)) | ||
| 33 | + | ||
| 27 | 34 | ||
| 28 | 35 | class GroupBoard(SaveMixin, ObjectDeleteMixin, RESTObject): | |
| 29 | 36 | lists: GroupBoardListManager | |
@@ -35,6 +42,9 @@ class GroupBoardManager(CRUDMixin, RESTManager): | |||
| 35 | 42 | _from_parent_attrs = {"group_id": "id"} | |
| 36 | 43 | _create_attrs = RequiredOptional(required=("name",)) | |
| 37 | 44 | ||
| 45 | + def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> GroupBoard: | ||
| 46 | + return cast(GroupBoard, super().get(id=id, lazy=lazy, **kwargs)) | ||
| 47 | + | ||
| 38 | 48 | ||
| 39 | 49 | class ProjectBoardList(SaveMixin, ObjectDeleteMixin, RESTObject): | |
| 40 | 50 | pass | |
@@ -47,6 +57,11 @@ class ProjectBoardListManager(CRUDMixin, RESTManager): | |||
| 47 | 57 | _create_attrs = RequiredOptional(required=("label_id",)) | |
| 48 | 58 | _update_attrs = RequiredOptional(required=("position",)) | |
| 49 | 59 | ||
| 60 | + def get( | ||
| 61 | + self, id: Union[str, int], lazy: bool = False, **kwargs: Any | ||
| 62 | + ) -> ProjectBoardList: | ||
| 63 | + return cast(ProjectBoardList, super().get(id=id, lazy=lazy, **kwargs)) | ||
| 64 | + | ||
| 50 | 65 | ||
| 51 | 66 | class ProjectBoard(SaveMixin, ObjectDeleteMixin, RESTObject): | |
| 52 | 67 | lists: ProjectBoardListManager | |
@@ -57,3 +72,8 @@ class ProjectBoardManager(CRUDMixin, RESTManager): | |||
| 57 | 72 | _obj_cls = ProjectBoard | |
| 58 | 73 | _from_parent_attrs = {"project_id": "id"} | |
| 59 | 74 | _create_attrs = RequiredOptional(required=("name",)) | |
| 75 | + | ||
| 76 | + def get( | ||
| 77 | + self, id: Union[str, int], lazy: bool = False, **kwargs: Any | ||
| 78 | + ) -> ProjectBoard: | ||
| 79 | + return cast(ProjectBoard, super().get(id=id, lazy=lazy, **kwargs)) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + from typing import Any, cast, Dict, Optional | ||
| 2 | + | ||
| 1 | 3 | from gitlab import exceptions as exc | |
| 2 | 4 | from gitlab.base import RequiredOptional, RESTManager, RESTObject | |
| 3 | 5 | from gitlab.mixins import CreateMixin, CRUDMixin, ObjectDeleteMixin, SaveMixin | |
@@ -33,7 +35,9 @@ class GroupClusterManager(CRUDMixin, RESTManager): | |||
| 33 | 35 | ) | |
| 34 | 36 | ||
| 35 | 37 | @exc.on_http_error(exc.GitlabStopError) | |
| 36 | - def create(self, data, **kwargs): | ||
| 38 | + def create( | ||
| 39 | + self, data: Optional[Dict[str, Any]] = None, **kwargs: Any | ||
| 40 | + ) -> GroupCluster: | ||
| 37 | 41 | """Create a new object. | |
| 38 | 42 | ||
| 39 | 43 | Args: | |
@@ -51,7 +55,7 @@ def create(self, data, **kwargs): | |||
| 51 | 55 | the data sent by the server | |
| 52 | 56 | """ | |
| 53 | 57 | path = f"{self.path}/user" | |
| 54 | - return CreateMixin.create(self, data, path=path, **kwargs) | ||
| 58 | + return cast(GroupCluster, CreateMixin.create(self, data, path=path, **kwargs)) | ||
| 55 | 59 | ||
| 56 | 60 | ||
| 57 | 61 | class ProjectCluster(SaveMixin, ObjectDeleteMixin, RESTObject): | |
@@ -77,7 +81,9 @@ class ProjectClusterManager(CRUDMixin, RESTManager): | |||
| 77 | 81 | ) | |
| 78 | 82 | ||
| 79 | 83 | @exc.on_http_error(exc.GitlabStopError) | |
| 80 | - def create(self, data, **kwargs): | ||
| 84 | + def create( | ||
| 85 | + self, data: Optional[Dict[str, Any]] = None, **kwargs: Any | ||
| 86 | + ) -> ProjectCluster: | ||
| 81 | 87 | """Create a new object. | |
| 82 | 88 | ||
| 83 | 89 | Args: | |
@@ -95,4 +101,4 @@ def create(self, data, **kwargs): | |||
| 95 | 101 | the data sent by the server | |
| 96 | 102 | """ | |
| 97 | 103 | path = f"{self.path}/user" | |
| 98 | - return CreateMixin.create(self, data, path=path, **kwargs) | ||
| 104 | + return cast(ProjectCluster, CreateMixin.create(self, data, path=path, **kwargs)) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + from typing import Any, TYPE_CHECKING | ||
| 2 | + | ||
| 1 | 3 | from gitlab import cli | |
| 2 | 4 | from gitlab import exceptions as exc | |
| 3 | 5 | from gitlab.base import RESTManager, RESTObject | |
@@ -36,7 +38,7 @@ class ProjectRegistryTagManager(DeleteMixin, RetrieveMixin, RESTManager): | |||
| 36 | 38 | optional=("keep_n", "name_regex_keep", "older_than"), | |
| 37 | 39 | ) | |
| 38 | 40 | @exc.on_http_error(exc.GitlabDeleteError) | |
| 39 | - def delete_in_bulk(self, name_regex_delete, **kwargs): | ||
| 41 | + def delete_in_bulk(self, name_regex_delete: str, **kwargs: Any) -> None: | ||
| 40 | 42 | """Delete Tag in bulk | |
| 41 | 43 | ||
| 42 | 44 | Args: | |
@@ -55,4 +57,6 @@ def delete_in_bulk(self, name_regex_delete, **kwargs): | |||
| 55 | 57 | valid_attrs = ["keep_n", "name_regex_keep", "older_than"] | |
| 56 | 58 | data = {"name_regex_delete": name_regex_delete} | |
| 57 | 59 | data.update({k: v for k, v in kwargs.items() if k in valid_attrs}) | |
| 60 | + if TYPE_CHECKING: | ||
| 61 | + assert self.path is not None | ||
| 58 | 62 | self.gitlab.http_delete(self.path, query_data=data, **kwargs) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,7 @@ | |||
| 1 | + from typing import Any, cast, Dict, Union | ||
| 2 | + | ||
| 3 | + import requests | ||
| 4 | + | ||
| 1 | 5 | from gitlab import cli | |
| 2 | 6 | from gitlab import exceptions as exc | |
| 3 | 7 | from gitlab.base import RequiredOptional, RESTManager, RESTObject | |
@@ -33,7 +37,9 @@ class ProjectKeyManager(CRUDMixin, RESTManager): | |||
| 33 | 37 | ||
| 34 | 38 | @cli.register_custom_action("ProjectKeyManager", ("key_id",)) | |
| 35 | 39 | @exc.on_http_error(exc.GitlabProjectDeployKeyError) | |
| 36 | - def enable(self, key_id, **kwargs): | ||
| 40 | + def enable( | ||
| 41 | + self, key_id: int, **kwargs: Any | ||
| 42 | + ) -> Union[Dict[str, Any], requests.Response]: | ||
| 37 | 43 | """Enable a deploy key for a project. | |
| 38 | 44 | ||
| 39 | 45 | Args: | |
@@ -43,6 +49,12 @@ def enable(self, key_id, **kwargs): | |||
| 43 | 49 | Raises: | |
| 44 | 50 | GitlabAuthenticationError: If authentication is not correct | |
| 45 | 51 | GitlabProjectDeployKeyError: If the key could not be enabled | |
| 52 | + | ||
| 53 | + Returns: | ||
| 54 | + A dict of the result. | ||
| 46 | 55 | """ | |
| 47 | 56 | path = f"{self.path}/{key_id}/enable" | |
| 48 | - self.gitlab.http_post(path, **kwargs) | ||
| 57 | + return self.gitlab.http_post(path, **kwargs) | ||
| 58 | + | ||
| 59 | + def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> ProjectKey: | ||
| 60 | + return cast(ProjectKey, super().get(id=id, lazy=lazy, **kwargs)) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,7 @@ | |||
| 1 | + from typing import Any, Dict, Union | ||
| 2 | + | ||
| 3 | + import requests | ||
| 4 | + | ||
| 1 | 5 | from gitlab import cli | |
| 2 | 6 | from gitlab import exceptions as exc | |
| 3 | 7 | from gitlab.base import RequiredOptional, RESTManager, RESTObject | |
@@ -19,7 +23,7 @@ | |||
| 19 | 23 | class ProjectEnvironment(SaveMixin, ObjectDeleteMixin, RESTObject): | |
| 20 | 24 | @cli.register_custom_action("ProjectEnvironment") | |
| 21 | 25 | @exc.on_http_error(exc.GitlabStopError) | |
| 22 | - def stop(self, **kwargs): | ||
| 26 | + def stop(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | ||
| 23 | 27 | """Stop the environment. | |
| 24 | 28 | ||
| 25 | 29 | Args: | |
@@ -28,9 +32,12 @@ def stop(self, **kwargs): | |||
| 28 | 32 | Raises: | |
| 29 | 33 | GitlabAuthenticationError: If authentication is not correct | |
| 30 | 34 | GitlabStopError: If the operation failed | |
| 35 | + | ||
| 36 | + Returns: | ||
| 37 | + A dict of the result. | ||
| 31 | 38 | """ | |
| 32 | 39 | path = f"{self.manager.path}/{self.get_id()}/stop" | |
| 33 | - self.manager.gitlab.http_post(path, **kwargs) | ||
| 40 | + return self.manager.gitlab.http_post(path, **kwargs) | ||
| 34 | 41 | ||
| 35 | 42 | ||
| 36 | 43 | class ProjectEnvironmentManager( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + from typing import Any, cast, Optional, Union | ||
| 2 | + | ||
| 1 | 3 | from gitlab.base import RequiredOptional, RESTManager, RESTObject | |
| 2 | 4 | from gitlab.mixins import CreateMixin, DownloadMixin, GetWithoutIdMixin, RefreshMixin | |
| 3 | 5 | ||
@@ -22,6 +24,11 @@ class GroupExportManager(GetWithoutIdMixin, CreateMixin, RESTManager): | |||
| 22 | 24 | _obj_cls = GroupExport | |
| 23 | 25 | _from_parent_attrs = {"group_id": "id"} | |
| 24 | 26 | ||
| 27 | + def get( | ||
| 28 | + self, id: Optional[Union[int, str]] = None, **kwargs: Any | ||
| 29 | + ) -> Optional[GroupExport]: | ||
| 30 | + return cast(GroupExport, super().get(id=id, **kwargs)) | ||
| 31 | + | ||
| 25 | 32 | ||
| 26 | 33 | class GroupImport(RESTObject): | |
| 27 | 34 | _id_attr = None | |
@@ -32,6 +39,11 @@ class GroupImportManager(GetWithoutIdMixin, RESTManager): | |||
| 32 | 39 | _obj_cls = GroupImport | |
| 33 | 40 | _from_parent_attrs = {"group_id": "id"} | |
| 34 | 41 | ||
| 42 | + def get( | ||
| 43 | + self, id: Optional[Union[int, str]] = None, **kwargs: Any | ||
| 44 | + ) -> Optional[GroupImport]: | ||
| 45 | + return cast(GroupImport, super().get(id=id, **kwargs)) | ||
| 46 | + | ||
| 35 | 47 | ||
| 36 | 48 | class ProjectExport(DownloadMixin, RefreshMixin, RESTObject): | |
| 37 | 49 | _id_attr = None | |
@@ -43,6 +55,11 @@ class ProjectExportManager(GetWithoutIdMixin, CreateMixin, RESTManager): | |||
| 43 | 55 | _from_parent_attrs = {"project_id": "id"} | |
| 44 | 56 | _create_attrs = RequiredOptional(optional=("description",)) | |
| 45 | 57 | ||
| 58 | + def get( | ||
| 59 | + self, id: Optional[Union[int, str]] = None, **kwargs: Any | ||
| 60 | + ) -> Optional[ProjectExport]: | ||
| 61 | + return cast(ProjectExport, super().get(id=id, **kwargs)) | ||
| 62 | + | ||
| 46 | 63 | ||
| 47 | 64 | class ProjectImport(RefreshMixin, RESTObject): | |
| 48 | 65 | _id_attr = None | |
@@ -52,3 +69,8 @@ class ProjectImportManager(GetWithoutIdMixin, RESTManager): | |||
| 52 | 69 | _path = "/projects/%(project_id)s/import" | |
| 53 | 70 | _obj_cls = ProjectImport | |
| 54 | 71 | _from_parent_attrs = {"project_id": "id"} | |
| 72 | + | ||
| 73 | + def get( | ||
| 74 | + self, id: Optional[Union[int, str]] = None, **kwargs: Any | ||
| 75 | + ) -> Optional[ProjectImport]: | ||
| 76 | + return cast(ProjectImport, super().get(id=id, **kwargs)) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments