Source Github: Repository field accept full URL (#25778)
Signed-off-by: Sergey Chvalyuk <grubberr@gmail.com>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
|
||||
#
|
||||
|
||||
import re
|
||||
from typing import Any, Dict, List, Mapping, Set, Tuple
|
||||
|
||||
from airbyte_cdk import AirbyteLogger
|
||||
@@ -57,23 +56,6 @@ from .utils import read_full_refresh
|
||||
|
||||
|
||||
class SourceGithub(AbstractSource):
|
||||
@staticmethod
|
||||
def _is_repositories_config_valid(config_repositories: Set[str]) -> bool:
|
||||
"""
|
||||
_is_repositories_config_valid validates that each repo config matches regex to highlight problem in provided config.
|
||||
Valid examples: airbytehq/airbyte airbytehq/another-repo airbytehq/* airbytehq/airbyte
|
||||
Args:
|
||||
config_repositories: set of provided repositories
|
||||
Returns:
|
||||
True if config valid, False if it's not
|
||||
"""
|
||||
pattern = re.compile(r"^(?:[\w.-]+/)+(?:\*|[\w.-]+)$")
|
||||
|
||||
for repo in config_repositories:
|
||||
if not pattern.match(repo):
|
||||
return False
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _get_and_prepare_repositories_config(config: Mapping[str, Any]) -> Set[str]:
|
||||
"""
|
||||
@@ -84,11 +66,6 @@ class SourceGithub(AbstractSource):
|
||||
set of provided repositories
|
||||
"""
|
||||
config_repositories = set(filter(None, config["repository"].split(" ")))
|
||||
# removing spaces
|
||||
config_repositories = {repo.strip() for repo in config_repositories}
|
||||
# removing redundant / in the end
|
||||
config_repositories = {repo[:-1] if repo.endswith("/") else repo for repo in config_repositories}
|
||||
|
||||
return config_repositories
|
||||
|
||||
@staticmethod
|
||||
@@ -100,14 +77,6 @@ class SourceGithub(AbstractSource):
|
||||
authenticator(MultipleTokenAuthenticator): authenticator object
|
||||
"""
|
||||
config_repositories = SourceGithub._get_and_prepare_repositories_config(config)
|
||||
if not SourceGithub._is_repositories_config_valid(config_repositories):
|
||||
raise Exception(
|
||||
f"You provided invalid format of repositories config: {' ' .join(config_repositories)}."
|
||||
f" Valid examples: airbytehq/airbyte airbytehq/another-repo airbytehq/* airbytehq/airbyte"
|
||||
)
|
||||
|
||||
if not config_repositories:
|
||||
raise Exception("Field `repository` required to be provided for connect to Github API")
|
||||
|
||||
repositories = set()
|
||||
organizations = set()
|
||||
|
||||
Reference in New Issue
Block a user