2
2
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3
3
#
4
4
import logging
5
- from typing import Dict , List , Optional , Tuple
5
+ from typing import Dict , Optional , Set , Tuple
6
6
7
7
import git
8
8
import requests
14
14
SOURCE_CONNECTOR_PATH_PREFIX = CONNECTOR_PATH_PREFIX + "/source-"
15
15
ACCEPTANCE_TEST_CONFIG_FILE_NAME = "acceptance-test-config.yml"
16
16
AIRBYTE_DOCKER_REPO = "airbyte"
17
+ SOURCE_DEFINITIONS_FILE_PATH = "airbyte-config/init/src/main/resources/seed/source_definitions.yaml"
18
+ DESTINATION_DEFINITIONS_FILE_PATH = "airbyte-config/init/src/main/resources/seed/destination_definitions.yaml"
19
+ DEFINITIONS_FILE_PATH = {"source" : SOURCE_DEFINITIONS_FILE_PATH , "destination" : DESTINATION_DEFINITIONS_FILE_PATH }
17
20
18
21
19
22
def download_catalog (catalog_url ):
@@ -24,28 +27,34 @@ def download_catalog(catalog_url):
24
27
OSS_CATALOG = download_catalog (OSS_CATALOG_URL )
25
28
26
29
27
- def get_changed_connector_names () -> List [str ]:
30
+ def read_definitions (definitions_file_path : str ) -> Dict :
31
+ with open (definitions_file_path ) as definitions_file :
32
+ return yaml .safe_load (definitions_file )
33
+
34
+
35
+ def get_changed_connector_names () -> Set [str ]:
28
36
"""Retrieve a list of connector names that were changed in the current branch (compared to master).
29
37
30
38
Returns:
31
- List [str]: List of connector names e.g ["source-pokeapi"]
39
+ Set [str]: Set of connector names e.g ["source-pokeapi"]
32
40
"""
33
- head_commit = AIRBYTE_REPO .head .commit
34
- master_diffs = head_commit .diff (AIRBYTE_REPO .remotes .origin .refs .master )
35
- changed_source_connector_files = [diff .b_path for diff in master_diffs if diff .b_path .startswith (SOURCE_CONNECTOR_PATH_PREFIX )]
41
+ changed_source_connector_files = {
42
+ file_path
43
+ for file_path in AIRBYTE_REPO .git .diff ("--name-only" , "origin/master..." ).split ("\n " )
44
+ if file_path .startswith (SOURCE_CONNECTOR_PATH_PREFIX )
45
+ }
36
46
37
47
def get_connector_name_from_path (path ):
38
48
return path .split ("/" )[2 ]
39
49
40
- return [ get_connector_name_from_path (changed_file ) for changed_file in changed_source_connector_files ]
50
+ return { get_connector_name_from_path (changed_file ) for changed_file in changed_source_connector_files }
41
51
42
52
43
- def get_connector_definition (connector_name : str , catalog : Dict = OSS_CATALOG ) -> Optional [Dict ]:
53
+ def get_connector_definition (connector_name : str ) -> Optional [Dict ]:
44
54
"""Find a connector definition from the catalog.
45
55
46
56
Args:
47
57
connector_name (str): The connector name. E.G. 'source-pokeapi'
48
- catalog (Dict, optional): The connector catalog. Defaults to OSS_CATALOG.
49
58
50
59
Raises:
51
60
Exception: Raised if the definition type (source/destination) could not be determined from connector name.
@@ -58,22 +67,22 @@ def get_connector_definition(connector_name: str, catalog: Dict = OSS_CATALOG) -
58
67
assert definition_type in ["source" , "destination" ]
59
68
except AssertionError :
60
69
raise Exception (f"Could not determine the definition type for { connector_name } ." )
61
- for definition in catalog [definition_type + "s" ]:
70
+ definitions = read_definitions (DEFINITIONS_FILE_PATH [definition_type ])
71
+ for definition in definitions :
62
72
if definition ["dockerRepository" ].replace (f"{ AIRBYTE_DOCKER_REPO } /" , "" ) == connector_name :
63
73
return definition
64
74
65
75
66
- def get_connector_release_stage (connector_name : str , catalog : Dict = OSS_CATALOG ) -> Optional [str ]:
76
+ def get_connector_release_stage (connector_name : str ) -> Optional [str ]:
67
77
"""Retrieve the connector release stage (E.G. alpha/beta/generally_available).
68
78
69
79
Args:
70
80
connector_name (str): The connector name. E.G. 'source-pokeapi'
71
- catalog (Dict, optional): The connector catalog. Defaults to OSS_CATALOG.
72
81
73
82
Returns:
74
83
Optional[str]: The connector release stage if it was defined. Returns None otherwise.
75
84
"""
76
- definition = get_connector_definition (connector_name , catalog )
85
+ definition = get_connector_definition (connector_name )
77
86
return definition .get ("releaseStage" )
78
87
79
88
0 commit comments