From 5b57a501537b7c12f7b4101a0a9d484adaaf9e9b Mon Sep 17 00:00:00 2001 From: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:56:46 +0200 Subject: [PATCH] Properly read user and repo for github portal for github portal --- frictionless/portals/github/plugin.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/frictionless/portals/github/plugin.py b/frictionless/portals/github/plugin.py index 989f0717bc..1be4deb3e9 100644 --- a/frictionless/portals/github/plugin.py +++ b/frictionless/portals/github/plugin.py @@ -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 @@ -29,12 +29,9 @@ 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) @@ -42,3 +39,12 @@ def create_adapter( 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)