Skip to content

Commit

Permalink
🟢
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrecamilleri committed Nov 15, 2024
1 parent 3765e2b commit 74a8c27
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
19 changes: 14 additions & 5 deletions frictionless/portals/github/__spec__/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ def test_github_plugin_parse_repo():


def test_github_url_control_mismatch():
url = "https://github.com/user/some-repo"
control = GithubControl(user="wrong-user")
test_cases = [
{
"url": "https://github.com/user/some-repo",
"control": GithubControl(user="wrong-user"),
},
{
"url": "https://github.com/user/some-repo",
"control": GithubControl(repo="wrong-repo"),
},
]

plugin = GithubPlugin()
with pytest.raises(FrictionlessException):
plugin.create_adapter(source=url, control=control)
for test_case in test_cases:
plugin = GithubPlugin()
with pytest.raises(FrictionlessException):
plugin.create_adapter(source=test_case["url"], control=test_case["control"])
4 changes: 2 additions & 2 deletions frictionless/portals/github/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class GithubControl(Control):
"""The number of results per page. Default value is 30. Max value is 100."""

repo: Optional[str] = None
"""Name of the repo to read or write."""
"""Name of the repository to read or write."""

search: Optional[str] = None
"""Search query containing one or more search keywords and qualifiers to filter the repositories.
Expand All @@ -65,7 +65,7 @@ class GithubControl(Control):
By default the results are sorted by best match in desc order."""

user: Optional[str] = None
"""username of the github account."""
"""Owner of the repository (user or organisation)"""

filename: Optional[str] = None
"""Custom data package file name while publishing the data. By default it will use 'datapackage.json'."""
Expand Down
17 changes: 16 additions & 1 deletion frictionless/portals/github/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import TYPE_CHECKING, Optional, Tuple
from urllib.parse import urlparse

from ...exception import FrictionlessException
from ...system import Plugin
from .adapter import GithubAdapter
from .control import GithubControl
Expand Down Expand Up @@ -30,7 +31,21 @@ def create_adapter(
if parsed.netloc == "github.com":
control = control or GithubControl()

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

if control.user and control.user != user:
raise FrictionlessException(
'Mismatch between url and provided "user" information'
)

control.user = user

if control.repo and control.repo != repo:
raise FrictionlessException(
'Mismatch between url and provided "repo" information'
)

control.repo = repo

return GithubAdapter(control)

Expand Down

0 comments on commit 74a8c27

Please sign in to comment.