Skip to content

Commit

Permalink
primary_key added
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Chvalyuk <grubberr@gmail.com>
  • Loading branch information
grubberr committed Apr 13, 2022
1 parent 49bed23 commit 865ac5f
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1010,12 +1010,14 @@ class TeamMembers(GithubStream):
API docs: https://docs.github.com/en/rest/reference/teams#list-team-members
"""

primary_key = ["id", "team_slug"]

def __init__(self, parent: HttpStream, **kwargs):
super().__init__(**kwargs)
self.parent = parent

def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
return f"orgs/{stream_slice['organization']}/teams/{stream_slice['slug']}/members"
return f"orgs/{stream_slice['organization']}/teams/{stream_slice['team_slug']}/members"

def stream_slices(
self, sync_mode: SyncMode, cursor_field: List[str] = None, stream_state: Mapping[str, Any] = None
Expand All @@ -1028,11 +1030,11 @@ def stream_slices(
sync_mode=SyncMode.full_refresh, cursor_field=cursor_field, stream_slice=stream_slice, stream_state=stream_state
)
for record in parent_records:
yield {"organization": record["organization"], "slug": record["slug"]}
yield {"organization": record["organization"], "team_slug": record["slug"]}

def transform(self, record: MutableMapping[str, Any], stream_slice: Mapping[str, Any]) -> MutableMapping[str, Any]:
record["organization"] = stream_slice["organization"]
record["slug"] = stream_slice["slug"]
record["team_slug"] = stream_slice["team_slug"]
return record


Expand All @@ -1041,12 +1043,14 @@ class TeamMemberships(GithubStream):
API docs: https://docs.github.com/en/rest/reference/teams#get-team-membership-for-a-user
"""

primary_key = ["url"]

def __init__(self, parent: HttpStream, **kwargs):
super().__init__(**kwargs)
self.parent = parent

def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
return f"orgs/{stream_slice['organization']}/teams/{stream_slice['slug']}/memberships/{stream_slice['username']}"
return f"orgs/{stream_slice['organization']}/teams/{stream_slice['team_slug']}/memberships/{stream_slice['username']}"

def stream_slices(
self, sync_mode: SyncMode, cursor_field: List[str] = None, stream_state: Mapping[str, Any] = None
Expand All @@ -1059,14 +1063,14 @@ def stream_slices(
sync_mode=SyncMode.full_refresh, cursor_field=cursor_field, stream_slice=stream_slice, stream_state=stream_state
)
for record in parent_records:
yield {"organization": record["organization"], "slug": record["slug"], "username": record["login"]}
yield {"organization": record["organization"], "team_slug": record["team_slug"], "username": record["login"]}

def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
stream_slice = kwargs["stream_slice"]
yield self.transform(response.json(), stream_slice=stream_slice)

def transform(self, record: MutableMapping[str, Any], stream_slice: Mapping[str, Any]) -> MutableMapping[str, Any]:
record["organization"] = stream_slice["organization"]
record["slug"] = stream_slice["slug"]
record["team_slug"] = stream_slice["team_slug"]
record["username"] = stream_slice["username"]
return record

1 comment on commit 865ac5f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarQube Report

SonarQube report for Airbyte Connectors Source Github(#11893)

Measures

Name Value Name Value Name Value
Lines of Code 937 Coverage 30.8 Lines to Cover 26
Security Rating A Duplicated Blocks 7 Vulnerabilities 0
Reliability Rating A Duplicated Lines (%) 22.9 Quality Gate Status ERROR
Bugs 0 Code Smells 4 Blocker Issues 0
Critical Issues 2 Major Issues 2 Minor Issues 0

Detected Issues

Rule File Description Message
python:S3776 (CRITICAL) source_github/streams.py:90 Cognitive Complexity of functions should not be too high Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.
python:S5886 (MAJOR) source_github/streams.py:83 Function return types should be consistent with their type hint Return a value of type "Union[int, float]" instead of "NoneType" or update function "backoff_time" type hint.
python:S5797 (CRITICAL) fixtures/github.py:79 Constants should not be used as conditions Replace this expression; used as a condition it will always be constant.
python:S112 (MAJOR) source_github/source.py:77 "Exception" and "BaseException" should not be raised Replace this generic exception class with a more specific one.

Coverage (30.8%)

File Coverage File Coverage
fixtures/github.py 0.0 fixtures/main.py 0.0
source_github/init.py 100.0 source_github/source.py 71.4
source_github/streams.py 89.7

Please sign in to comment.