|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -from typing import TYPE_CHECKING, Any, Optional |
| 3 | +from typing import TYPE_CHECKING, Any, Optional, Tuple |
4 | 4 | from urllib.parse import urlparse
|
5 | 5 |
|
6 | 6 | from ...system import Plugin
|
@@ -29,16 +29,22 @@ def create_adapter(
|
29 | 29 | if not control or isinstance(control, GithubControl):
|
30 | 30 | if parsed.netloc == "github.com":
|
31 | 31 | control = control or GithubControl()
|
32 |
| - splited_url = parsed.path.split("/")[1:] |
33 |
| - if len(splited_url) == 1: |
34 |
| - control.user = splited_url[0] |
35 |
| - return GithubAdapter(control) |
36 |
| - if len(splited_url) == 2: |
37 |
| - control.user, control.repo = splited_url |
| 32 | + |
| 33 | + control.user, control.repo = self._extract_user_and_repo(parsed.path) |
| 34 | + |
38 | 35 | return GithubAdapter(control)
|
39 | 36 | if source is None and isinstance(control, GithubControl):
|
40 | 37 | return GithubAdapter(control=control)
|
41 | 38 |
|
42 | 39 | def select_control_class(self, type: Optional[str] = None):
|
43 | 40 | if type == "github":
|
44 | 41 | return GithubControl
|
| 42 | + |
| 43 | + @staticmethod |
| 44 | + def _extract_user_and_repo(url_path: str) -> Tuple[Optional[str], Optional[str]]: |
| 45 | + splitted_url = url_path.split("/")[1:] |
| 46 | + |
| 47 | + user = splitted_url[0] if len(splitted_url) >= 1 else None |
| 48 | + repo = splitted_url[1] if len(splitted_url) >= 2 else None |
| 49 | + |
| 50 | + return (user, repo) |
0 commit comments