From 26095e2a62f6b183a8f9fe8092c32742081142e8 Mon Sep 17 00:00:00 2001 From: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:01:11 +0100 Subject: [PATCH 1/3] fix: github adapter only applies to rightly formatted URLs --- frictionless/portals/github/plugin.py | 51 ++++++++++++++++++++------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/frictionless/portals/github/plugin.py b/frictionless/portals/github/plugin.py index 989f0717bc..054fbdbd6e 100644 --- a/frictionless/portals/github/plugin.py +++ b/frictionless/portals/github/plugin.py @@ -24,21 +24,48 @@ def create_adapter( basepath: Optional[str] = None, packagify: bool = False, ): - if isinstance(source, str): - parsed = urlparse(source) - 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 - return GithubAdapter(control) + """Checks if the source is meant to access a Github Data portal, and returns the adapter if applicable + + The source is expected to be in one of the formatsĀ : + + - https://github.com/user_or_org + - https://github.com/user_or_org/repo + + Alternatively, user and/or repo information can be provided in the + GithubControl, with an empty source. + + """ + if control and not isinstance(control, GithubControl): + # Explicit control for other plugin + return + if source is None and isinstance(control, GithubControl): + # Source informations are inside the control return GithubAdapter(control=control) + if not isinstance(source, str): + return + + parsed_url = urlparse(source) + splited_url = parsed_url.path.split("/")[1:] + + if ( + parsed_url.netloc == "github.com" + and len(splited_url) < 1 + and len(splited_url) > 2 + ): + control = control or GithubControl() + control.user = splited_url[0] + + if len(splited_url) == 2: + control.repo = splited_url[1] + + return GithubAdapter(control) + + else: + # Url has not an expected format + return + def select_control_class(self, type: Optional[str] = None): if type == "github": return GithubControl From aa4a9c5e4bb0a0d6792fdc41056e5de2e10381a1 Mon Sep 17 00:00:00 2001 From: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:55:02 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=94=B5=20Introduce=20variable=20for?= =?UTF-8?q?=20better=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frictionless/portals/github/plugin.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/frictionless/portals/github/plugin.py b/frictionless/portals/github/plugin.py index 054fbdbd6e..328f9f4d14 100644 --- a/frictionless/portals/github/plugin.py +++ b/frictionless/portals/github/plugin.py @@ -49,11 +49,13 @@ def create_adapter( parsed_url = urlparse(source) splited_url = parsed_url.path.split("/")[1:] - if ( + has_expected_format = ( parsed_url.netloc == "github.com" and len(splited_url) < 1 and len(splited_url) > 2 - ): + ) + + if has_expected_format: control = control or GithubControl() control.user = splited_url[0] @@ -62,10 +64,6 @@ def create_adapter( return GithubAdapter(control) - else: - # Url has not an expected format - return - def select_control_class(self, type: Optional[str] = None): if type == "github": return GithubControl From 4bdbe95a1af857c152c7ff590cc9cdda1adf4bbd Mon Sep 17 00:00:00 2001 From: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:57:39 +0100 Subject: [PATCH 3/3] fix: oups --- frictionless/portals/github/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frictionless/portals/github/plugin.py b/frictionless/portals/github/plugin.py index 328f9f4d14..bb6a757e74 100644 --- a/frictionless/portals/github/plugin.py +++ b/frictionless/portals/github/plugin.py @@ -51,8 +51,8 @@ def create_adapter( has_expected_format = ( parsed_url.netloc == "github.com" - and len(splited_url) < 1 - and len(splited_url) > 2 + and len(splited_url) >= 1 + and len(splited_url) <= 2 ) if has_expected_format: