airbyte-source-github 1.5.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- airbyte_source_github-1.5.7.dist-info/METADATA +144 -0
- airbyte_source_github-1.5.7.dist-info/RECORD +88 -0
- airbyte_source_github-1.5.7.dist-info/WHEEL +5 -0
- airbyte_source_github-1.5.7.dist-info/entry_points.txt +2 -0
- airbyte_source_github-1.5.7.dist-info/top_level.txt +3 -0
- integration_tests/__init__.py +0 -0
- integration_tests/abnormal_state.json +237 -0
- integration_tests/acceptance.py +16 -0
- integration_tests/configured_catalog.json +435 -0
- integration_tests/configured_catalog_full_refresh_test.json +415 -0
- integration_tests/invalid_config.json +5 -0
- integration_tests/sample_config.json +5 -0
- integration_tests/sample_state.json +137 -0
- source_github/__init__.py +27 -0
- source_github/config_migrations.py +106 -0
- source_github/constants.py +9 -0
- source_github/github_schema.py +41034 -0
- source_github/graphql.py +327 -0
- source_github/run.py +17 -0
- source_github/schemas/assignees.json +63 -0
- source_github/schemas/branches.json +48 -0
- source_github/schemas/collaborators.json +80 -0
- source_github/schemas/comments.json +104 -0
- source_github/schemas/commit_comment_reactions.json +4 -0
- source_github/schemas/commit_comments.json +53 -0
- source_github/schemas/commits.json +126 -0
- source_github/schemas/contributor_activity.json +109 -0
- source_github/schemas/deployments.json +77 -0
- source_github/schemas/events.json +63 -0
- source_github/schemas/issue_comment_reactions.json +4 -0
- source_github/schemas/issue_events.json +335 -0
- source_github/schemas/issue_labels.json +30 -0
- source_github/schemas/issue_milestones.json +61 -0
- source_github/schemas/issue_reactions.json +28 -0
- source_github/schemas/issue_timeline_events.json +1056 -0
- source_github/schemas/issues.json +281 -0
- source_github/schemas/organizations.json +197 -0
- source_github/schemas/project_cards.json +50 -0
- source_github/schemas/project_columns.json +38 -0
- source_github/schemas/projects.json +50 -0
- source_github/schemas/projects_v2.json +80 -0
- source_github/schemas/pull_request_comment_reactions.json +28 -0
- source_github/schemas/pull_request_commits.json +122 -0
- source_github/schemas/pull_request_stats.json +84 -0
- source_github/schemas/pull_requests.json +363 -0
- source_github/schemas/releases.json +126 -0
- source_github/schemas/repositories.json +313 -0
- source_github/schemas/review_comments.json +118 -0
- source_github/schemas/reviews.json +69 -0
- source_github/schemas/shared/events/comment.json +188 -0
- source_github/schemas/shared/events/commented.json +118 -0
- source_github/schemas/shared/events/committed.json +56 -0
- source_github/schemas/shared/events/cross_referenced.json +784 -0
- source_github/schemas/shared/events/reviewed.json +139 -0
- source_github/schemas/shared/reaction.json +27 -0
- source_github/schemas/shared/reactions.json +35 -0
- source_github/schemas/shared/user.json +59 -0
- source_github/schemas/shared/user_graphql.json +26 -0
- source_github/schemas/stargazers.json +19 -0
- source_github/schemas/tags.json +32 -0
- source_github/schemas/team_members.json +66 -0
- source_github/schemas/team_memberships.json +24 -0
- source_github/schemas/teams.json +50 -0
- source_github/schemas/users.json +63 -0
- source_github/schemas/workflow_jobs.json +109 -0
- source_github/schemas/workflow_runs.json +449 -0
- source_github/schemas/workflows.json +41 -0
- source_github/source.py +339 -0
- source_github/spec.json +179 -0
- source_github/streams.py +1678 -0
- source_github/utils.py +152 -0
- unit_tests/__init__.py +3 -0
- unit_tests/conftest.py +29 -0
- unit_tests/projects_v2_pull_requests_query.json +3 -0
- unit_tests/pull_request_stats_query.json +3 -0
- unit_tests/responses/contributor_activity_response.json +33 -0
- unit_tests/responses/graphql_reviews_responses.json +405 -0
- unit_tests/responses/issue_timeline_events.json +166 -0
- unit_tests/responses/issue_timeline_events_response.json +170 -0
- unit_tests/responses/projects_v2_response.json +45 -0
- unit_tests/responses/pull_request_comment_reactions.json +744 -0
- unit_tests/responses/pull_request_stats_response.json +317 -0
- unit_tests/test_migrations/test_config.json +8 -0
- unit_tests/test_migrations/test_new_config.json +8 -0
- unit_tests/test_multiple_token_authenticator.py +160 -0
- unit_tests/test_source.py +326 -0
- unit_tests/test_stream.py +1471 -0
- unit_tests/utils.py +78 -0
@@ -0,0 +1,106 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
|
3
|
+
#
|
4
|
+
import abc
|
5
|
+
import logging
|
6
|
+
from abc import ABC
|
7
|
+
from typing import Any, List, Mapping
|
8
|
+
|
9
|
+
from airbyte_cdk.config_observation import create_connector_config_control_message
|
10
|
+
from airbyte_cdk.entrypoint import AirbyteEntrypoint
|
11
|
+
from airbyte_cdk.sources.message import InMemoryMessageRepository, MessageRepository
|
12
|
+
|
13
|
+
from .source import SourceGithub
|
14
|
+
|
15
|
+
logger = logging.getLogger("airbyte_logger")
|
16
|
+
|
17
|
+
|
18
|
+
class MigrateStringToArray(ABC):
|
19
|
+
"""
|
20
|
+
This class stands for migrating the config at runtime,
|
21
|
+
while providing the backward compatibility when falling back to the previous source version.
|
22
|
+
|
23
|
+
Specifically, starting from `1.4.6`, the `repository` and `branch` properties should be like :
|
24
|
+
> List(["<repository_1>", "<repository_2>", ..., "<repository_n>"])
|
25
|
+
instead of, in `1.4.5`:
|
26
|
+
> JSON STR: "repository_1 repository_2"
|
27
|
+
"""
|
28
|
+
|
29
|
+
message_repository: MessageRepository = InMemoryMessageRepository()
|
30
|
+
|
31
|
+
@property
|
32
|
+
@abc.abstractmethod
|
33
|
+
def migrate_from_key(self) -> str:
|
34
|
+
...
|
35
|
+
|
36
|
+
@property
|
37
|
+
@abc.abstractmethod
|
38
|
+
def migrate_to_key(self) -> str:
|
39
|
+
...
|
40
|
+
|
41
|
+
@classmethod
|
42
|
+
def _should_migrate(cls, config: Mapping[str, Any]) -> bool:
|
43
|
+
"""
|
44
|
+
This method determines whether config require migration.
|
45
|
+
Returns:
|
46
|
+
> True, if the transformation is necessary
|
47
|
+
> False, otherwise.
|
48
|
+
"""
|
49
|
+
if cls.migrate_from_key in config and cls.migrate_to_key not in config:
|
50
|
+
return True
|
51
|
+
return False
|
52
|
+
|
53
|
+
@classmethod
|
54
|
+
def _transform_to_array(cls, config: Mapping[str, Any], source: SourceGithub = None) -> Mapping[str, Any]:
|
55
|
+
# assign old values to new property that will be used within the new version
|
56
|
+
config[cls.migrate_to_key] = config[cls.migrate_to_key] if cls.migrate_to_key in config else []
|
57
|
+
data = set(filter(None, config.get(cls.migrate_from_key).split(" ")))
|
58
|
+
config[cls.migrate_to_key] = list(data | set(config[cls.migrate_to_key]))
|
59
|
+
return config
|
60
|
+
|
61
|
+
@classmethod
|
62
|
+
def _modify_and_save(cls, config_path: str, source: SourceGithub, config: Mapping[str, Any]) -> Mapping[str, Any]:
|
63
|
+
# modify the config
|
64
|
+
migrated_config = cls._transform_to_array(config, source)
|
65
|
+
# save the config
|
66
|
+
source.write_config(migrated_config, config_path)
|
67
|
+
# return modified config
|
68
|
+
return migrated_config
|
69
|
+
|
70
|
+
@classmethod
|
71
|
+
def _emit_control_message(cls, migrated_config: Mapping[str, Any]) -> None:
|
72
|
+
# add the Airbyte Control Message to message repo
|
73
|
+
cls.message_repository.emit_message(create_connector_config_control_message(migrated_config))
|
74
|
+
# emit the Airbyte Control Message from message queue to stdout
|
75
|
+
for message in cls.message_repository._message_queue:
|
76
|
+
print(message.json(exclude_unset=True))
|
77
|
+
|
78
|
+
@classmethod
|
79
|
+
def migrate(cls, args: List[str], source: SourceGithub) -> None:
|
80
|
+
"""
|
81
|
+
This method checks the input args, should the config be migrated,
|
82
|
+
transform if necessary and emit the CONTROL message.
|
83
|
+
"""
|
84
|
+
# get config path
|
85
|
+
config_path = AirbyteEntrypoint(source).extract_config(args)
|
86
|
+
# proceed only if `--config` arg is provided
|
87
|
+
if config_path:
|
88
|
+
# read the existing config
|
89
|
+
config = source.read_config(config_path)
|
90
|
+
# migration check
|
91
|
+
if cls._should_migrate(config):
|
92
|
+
cls._emit_control_message(
|
93
|
+
cls._modify_and_save(config_path, source, config),
|
94
|
+
)
|
95
|
+
|
96
|
+
|
97
|
+
class MigrateRepository(MigrateStringToArray):
|
98
|
+
|
99
|
+
migrate_from_key: str = "repository"
|
100
|
+
migrate_to_key: str = "repositories"
|
101
|
+
|
102
|
+
|
103
|
+
class MigrateBranch(MigrateStringToArray):
|
104
|
+
|
105
|
+
migrate_from_key: str = "branch"
|
106
|
+
migrate_to_key: str = "branches"
|