Skip to content

Commit

Permalink
Properly read user and repo for github portal for github portal
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrecamilleri committed Oct 11, 2024
1 parent 80f03c6 commit 5b57a50
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions frictionless/portals/github/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Any, Optional, Tuple
from urllib.parse import urlparse

from ...system import Plugin
Expand Down Expand Up @@ -29,16 +29,22 @@ def create_adapter(
if not control or isinstance(control, GithubControl):
if parsed.netloc == "github.com":
control = control or GithubControl()
splited_url = parsed.path.split("/")[1:]
if len(splited_url) == 1:
control.user = splited_url[0]
return GithubAdapter(control)
if len(splited_url) == 2:
control.user, control.repo = splited_url

control.user, control.repo = self._extract_user_and_repo(parsed.path)

return GithubAdapter(control)
if source is None and isinstance(control, GithubControl):
return GithubAdapter(control=control)

def select_control_class(self, type: Optional[str] = None):
if type == "github":
return GithubControl

@staticmethod
def _extract_user_and_repo(url_path: str) -> Tuple[Optional[str], Optional[str]]:
splitted_url = url_path.split("/")[1:]

user = splitted_url[0] if len(splitted_url) >= 1 else None
repo = splitted_url[1] if len(splitted_url) >= 2 else None

return (user, repo)

0 comments on commit 5b57a50

Please sign in to comment.