| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -252,18 +252,18 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser: | |||
| 252 | 252 | def _get_parser() -> argparse.ArgumentParser: | |
| 253 | 253 | # NOTE: We must delay import of gitlab.v4.cli until now or | |
| 254 | 254 | # otherwise it will cause circular import errors | |
| 255 | - import gitlab.v4.cli | ||
| 255 | + from gitlab.v4 import cli as v4_cli | ||
| 256 | 256 | ||
| 257 | 257 | parser = _get_base_parser() | |
| 258 | - return gitlab.v4.cli.extend_parser(parser) | ||
| 258 | + return v4_cli.extend_parser(parser) | ||
| 259 | 259 | ||
| 260 | 260 | ||
| 261 | 261 | def _parse_value(v: Any) -> Any: | |
| 262 | 262 | if isinstance(v, str) and v.startswith("@"): | |
| 263 | 263 | # If the user-provided value starts with @, we try to read the file | |
| 264 | 264 | # path provided after @ as the real value. Exit on any error. | |
| 265 | 265 | try: | |
| 266 | - with open(v[1:]) as f: | ||
| 266 | + with open(v[1:], encoding="utf-8") as f: | ||
| 267 | 267 | return f.read() | |
| 268 | 268 | except Exception as e: | |
| 269 | 269 | sys.stderr.write(f"{e}\n") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,10 +119,10 @@ def __init__( | |||
| 119 | 119 | raise ModuleNotFoundError(f"gitlab.v{self._api_version}.objects") | |
| 120 | 120 | # NOTE: We must delay import of gitlab.v4.objects until now or | |
| 121 | 121 | # otherwise it will cause circular import errors | |
| 122 | - import gitlab.v4.objects | ||
| 122 | + from gitlab.v4 import objects | ||
| 123 | 123 | ||
| 124 | - objects = gitlab.v4.objects | ||
| 125 | 124 | self._objects = objects | |
| 125 | + self.user: Optional[objects.CurrentUser] = None | ||
| 126 | 126 | ||
| 127 | 127 | self.broadcastmessages = objects.BroadcastMessageManager(self) | |
| 128 | 128 | """See :class:`~gitlab.v4.objects.BroadcastMessageManager`""" | |
@@ -213,9 +213,9 @@ def __setstate__(self, state: Dict[str, Any]) -> None: | |||
| 213 | 213 | ) # pragma: no cover, dead code currently | |
| 214 | 214 | # NOTE: We must delay import of gitlab.v4.objects until now or | |
| 215 | 215 | # otherwise it will cause circular import errors | |
| 216 | - import gitlab.v4.objects | ||
| 216 | + from gitlab.v4 import objects | ||
| 217 | 217 | ||
| 218 | - self._objects = gitlab.v4.objects | ||
| 218 | + self._objects = objects | ||
| 219 | 219 | ||
| 220 | 220 | @property | |
| 221 | 221 | def url(self) -> str: | |
@@ -514,7 +514,8 @@ def _set_auth_info(self) -> None: | |||
| 514 | 514 | self.http_username, self.http_password | |
| 515 | 515 | ) | |
| 516 | 516 | ||
| 517 | - def enable_debug(self) -> None: | ||
| 517 | + @staticmethod | ||
| 518 | + def enable_debug() -> None: | ||
| 518 | 519 | import logging | |
| 519 | 520 | from http.client import HTTPConnection # noqa | |
| 520 | 521 | ||
@@ -533,7 +534,8 @@ def _get_session_opts(self) -> Dict[str, Any]: | |||
| 533 | 534 | "verify": self.ssl_verify, | |
| 534 | 535 | } | |
| 535 | 536 | ||
| 536 | - def _get_base_url(self, url: Optional[str] = None) -> str: | ||
| 537 | + @staticmethod | ||
| 538 | + def _get_base_url(url: Optional[str] = None) -> str: | ||
| 537 | 539 | """Return the base URL with the trailing slash stripped. | |
| 538 | 540 | If the URL is a Falsy value, return the default URL. | |
| 539 | 541 | Returns: | |
@@ -555,10 +557,10 @@ def _build_url(self, path: str) -> str: | |||
| 555 | 557 | """ | |
| 556 | 558 | if path.startswith("http://") or path.startswith("https://"): | |
| 557 | 559 | return path | |
| 558 | - else: | ||
| 559 | - return f"{self._url}{path}" | ||
| 560 | + return f"{self._url}{path}" | ||
| 560 | 561 | ||
| 561 | - def _check_redirects(self, result: requests.Response) -> None: | ||
| 562 | + @staticmethod | ||
| 563 | + def _check_redirects(result: requests.Response) -> None: | ||
| 562 | 564 | # Check the requests history to detect 301/302 redirections. | |
| 563 | 565 | # If the initial verb is POST or PUT, the redirected request will use a | |
| 564 | 566 | # GET request, leading to unwanted behaviour. | |
@@ -583,8 +585,8 @@ def _check_redirects(self, result: requests.Response) -> None: | |||
| 583 | 585 | ) | |
| 584 | 586 | ) | |
| 585 | 587 | ||
| 588 | + @staticmethod | ||
| 586 | 589 | def _prepare_send_data( | |
| 587 | - self, | ||
| 588 | 590 | files: Optional[Dict[str, Any]] = None, | |
| 589 | 591 | post_data: Optional[Union[Dict[str, Any], bytes]] = None, | |
| 590 | 592 | raw: bool = False, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,7 +56,9 @@ def _get_config_files( | |||
| 56 | 56 | try: | |
| 57 | 57 | resolved = _resolve_file(config_file) | |
| 58 | 58 | except OSError as e: | |
| 59 | - raise GitlabConfigMissingError(f"Cannot read config from file: {e}") | ||
| 59 | + raise GitlabConfigMissingError( | ||
| 60 | + f"Cannot read config from file: {e}" | ||
| 61 | + ) from e | ||
| 60 | 62 | resolved_files.append(resolved) | |
| 61 | 63 | ||
| 62 | 64 | return resolved_files | |
@@ -69,7 +71,7 @@ def _get_config_files( | |||
| 69 | 71 | except OSError as e: | |
| 70 | 72 | raise GitlabConfigMissingError( | |
| 71 | 73 | f"Cannot read config from PYTHON_GITLAB_CFG: {e}" | |
| 72 | - ) | ||
| 74 | + ) from e | ||
| 73 | 75 | ||
| 74 | 76 | for config_file in _DEFAULT_FILES: | |
| 75 | 77 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,8 +47,7 @@ def __init__( | |||
| 47 | 47 | def __str__(self) -> str: | |
| 48 | 48 | if self.response_code is not None: | |
| 49 | 49 | return f"{self.response_code}: {self.error_message}" | |
| 50 | - else: | ||
| 51 | - return f"{self.error_message}" | ||
| 50 | + return f"{self.error_message}" | ||
| 52 | 51 | ||
| 53 | 52 | ||
| 54 | 53 | class GitlabAuthenticationError(GitlabError): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -231,8 +231,7 @@ def list(self, **kwargs: Any) -> Union[base.RESTObjectList, List[base.RESTObject | |||
| 231 | 231 | obj = self.gitlab.http_list(path, **data) | |
| 232 | 232 | if isinstance(obj, list): | |
| 233 | 233 | return [self._obj_cls(self, item, created_from_list=True) for item in obj] | |
| 234 | - else: | ||
| 235 | - return base.RESTObjectList(self, self._obj_cls, obj) | ||
| 234 | + return base.RESTObjectList(self, self._obj_cls, obj) | ||
| 236 | 235 | ||
| 237 | 236 | ||
| 238 | 237 | class RetrieveMixin(ListMixin, GetMixin): | |
@@ -244,8 +243,6 @@ class RetrieveMixin(ListMixin, GetMixin): | |||
| 244 | 243 | _path: Optional[str] | |
| 245 | 244 | gitlab: gitlab.Gitlab | |
| 246 | 245 | ||
| 247 | - pass | ||
| 248 | - | ||
| 249 | 246 | ||
| 250 | 247 | class CreateMixin(_RestManagerBase): | |
| 251 | 248 | _computed_path: Optional[str] | |
@@ -429,8 +426,6 @@ class CRUDMixin(GetMixin, ListMixin, CreateMixin, UpdateMixin, DeleteMixin): | |||
| 429 | 426 | _path: Optional[str] | |
| 430 | 427 | gitlab: gitlab.Gitlab | |
| 431 | 428 | ||
| 432 | - pass | ||
| 433 | - | ||
| 434 | 429 | ||
| 435 | 430 | class NoUpdateMixin(GetMixin, ListMixin, CreateMixin, DeleteMixin): | |
| 436 | 431 | _computed_path: Optional[str] | |
@@ -441,8 +436,6 @@ class NoUpdateMixin(GetMixin, ListMixin, CreateMixin, DeleteMixin): | |||
| 441 | 436 | _path: Optional[str] | |
| 442 | 437 | gitlab: gitlab.Gitlab | |
| 443 | 438 | ||
| 444 | - pass | ||
| 445 | - | ||
| 446 | 439 | ||
| 447 | 440 | class SaveMixin(_RestObjectBase): | |
| 448 | 441 | """Mixin for RESTObject's that can be updated.""" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,10 +103,12 @@ def get_for_api(self) -> str: | |||
| 103 | 103 | ||
| 104 | 104 | ||
| 105 | 105 | class FileAttribute(GitlabAttribute): | |
| 106 | - def get_file_name(self, attr_name: Optional[str] = None) -> Optional[str]: | ||
| 106 | + @staticmethod | ||
| 107 | + def get_file_name(attr_name: Optional[str] = None) -> Optional[str]: | ||
| 107 | 108 | return attr_name | |
| 108 | 109 | ||
| 109 | 110 | ||
| 110 | 111 | class ImageAttribute(FileAttribute): | |
| 111 | - def get_file_name(self, attr_name: Optional[str] = None) -> str: | ||
| 112 | + @staticmethod | ||
| 113 | + def get_file_name(attr_name: Optional[str] = None) -> str: | ||
| 112 | 114 | return f"{attr_name}.png" if attr_name else "image.png" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -377,13 +377,14 @@ def get_dict( | |||
| 377 | 377 | ||
| 378 | 378 | ||
| 379 | 379 | class JSONPrinter: | |
| 380 | - def display(self, d: Union[str, Dict[str, Any]], **kwargs: Any) -> None: | ||
| 380 | + @staticmethod | ||
| 381 | + def display(d: Union[str, Dict[str, Any]], **kwargs: Any) -> None: | ||
| 381 | 382 | import json # noqa | |
| 382 | 383 | ||
| 383 | 384 | print(json.dumps(d)) | |
| 384 | 385 | ||
| 386 | + @staticmethod | ||
| 385 | 387 | def display_list( | |
| 386 | - self, | ||
| 387 | 388 | data: List[Union[str, gitlab.base.RESTObject]], | |
| 388 | 389 | fields: List[str], | |
| 389 | 390 | **kwargs: Any, | |
@@ -394,7 +395,8 @@ def display_list( | |||
| 394 | 395 | ||
| 395 | 396 | ||
| 396 | 397 | class YAMLPrinter: | |
| 397 | - def display(self, d: Union[str, Dict[str, Any]], **kwargs: Any) -> None: | ||
| 398 | + @staticmethod | ||
| 399 | + def display(d: Union[str, Dict[str, Any]], **kwargs: Any) -> None: | ||
| 398 | 400 | try: | |
| 399 | 401 | import yaml # noqa | |
| 400 | 402 | ||
@@ -406,8 +408,8 @@ def display(self, d: Union[str, Dict[str, Any]], **kwargs: Any) -> None: | |||
| 406 | 408 | "to use the yaml output feature" | |
| 407 | 409 | ) | |
| 408 | 410 | ||
| 411 | + @staticmethod | ||
| 409 | 412 | def display_list( | |
| 410 | - self, | ||
| 411 | 413 | data: List[Union[str, gitlab.base.RESTObject]], | |
| 412 | 414 | fields: List[str], | |
| 413 | 415 | **kwargs: Any, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,8 @@ | |||
| 26 | 26 | class ProjectFile(SaveMixin, ObjectDeleteMixin, RESTObject): | |
| 27 | 27 | _id_attr = "file_path" | |
| 28 | 28 | _repr_attr = "file_path" | |
| 29 | + branch: str | ||
| 30 | + commit_message: str | ||
| 29 | 31 | file_path: str | |
| 30 | 32 | manager: "ProjectFileManager" | |
| 31 | 33 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,5 +49,4 @@ def list(self, **kwargs: Any) -> Union[List[LDAPGroup], RESTObjectList]: | |||
| 49 | 49 | obj = self.gitlab.http_list(path, **data) | |
| 50 | 50 | if isinstance(obj, list): | |
| 51 | 51 | return [self._obj_cls(self, item) for item in obj] | |
| 52 | - else: | ||
| 53 | - return RESTObjectList(self, self._obj_cls, obj) | ||
| 52 | + return RESTObjectList(self, self._obj_cls, obj) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -168,6 +168,8 @@ class ProjectMergeRequestApprovalRule(SaveMixin, ObjectDeleteMixin, RESTObject): | |||
| 168 | 168 | _id_attr = "approval_rule_id" | |
| 169 | 169 | _repr_attr = "approval_rule" | |
| 170 | 170 | id: int | |
| 171 | + approval_rule_id: int | ||
| 172 | + merge_request_iid: int | ||
| 171 | 173 | ||
| 172 | 174 | @exc.on_http_error(exc.GitlabUpdateError) | |
| 173 | 175 | def save(self, **kwargs: Any) -> None: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments