Skip to content

Commit

Permalink
SemiIncrementalGithubStream -> SemiIncrementalMixin
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 23, 2022
1 parent 63f6fc5 commit 6121b4f
Showing 1 changed file with 19 additions and 19 deletions.
Expand Up @@ -172,7 +172,7 @@ def transform(self, record: MutableMapping[str, Any], stream_slice: Mapping[str,
return record


class SemiIncrementalGithubStream(GithubStream):
class SemiIncrementalMixin:
"""
Semi incremental streams are also incremental but with one difference, they:
- read all records;
Expand Down Expand Up @@ -239,7 +239,7 @@ def read_records(
break


class IncrementalGithubStream(SemiIncrementalGithubStream):
class IncrementalMixin(SemiIncrementalMixin):
def request_params(self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, **kwargs) -> MutableMapping[str, Any]:
params = super().request_params(stream_state=stream_state, **kwargs)
since_params = self.get_starting_point(stream_state=stream_state, stream_slice=stream_slice)
Expand Down Expand Up @@ -376,7 +376,7 @@ def parse_response(self, response: requests.Response, stream_slice: Mapping[str,
# Below are semi incremental streams


class Releases(SemiIncrementalGithubStream):
class Releases(SemiIncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/repos#list-releases
"""
Expand All @@ -394,15 +394,15 @@ def transform(self, record: MutableMapping[str, Any], stream_slice: Mapping[str,
return record


class Events(SemiIncrementalGithubStream):
class Events(SemiIncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/activity#list-repository-events
"""

cursor_field = "created_at"


class PullRequests(SemiIncrementalGithubStream):
class PullRequests(SemiIncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/pulls#list-pull-requests
"""
Expand Down Expand Up @@ -449,7 +449,7 @@ def is_sorted_descending(self) -> bool:
return not self._first_read


class CommitComments(SemiIncrementalGithubStream):
class CommitComments(SemiIncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/repos#list-commit-comments-for-a-repository
"""
Expand All @@ -458,7 +458,7 @@ def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
return f"repos/{stream_slice['repository']}/comments"


class IssueMilestones(SemiIncrementalGithubStream):
class IssueMilestones(SemiIncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/issues#list-milestones
"""
Expand All @@ -474,7 +474,7 @@ def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
return f"repos/{stream_slice['repository']}/milestones"


class Stargazers(SemiIncrementalGithubStream):
class Stargazers(SemiIncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/activity#list-stargazers
"""
Expand All @@ -500,7 +500,7 @@ def transform(self, record: MutableMapping[str, Any], stream_slice: Mapping[str,
return record


class Projects(SemiIncrementalGithubStream):
class Projects(SemiIncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/projects#list-repository-projects
"""
Expand All @@ -518,7 +518,7 @@ def request_headers(self, **kwargs) -> Mapping[str, Any]:
return {**base_headers, **headers}


class IssueEvents(SemiIncrementalGithubStream):
class IssueEvents(SemiIncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/issues#list-issue-events-for-a-repository
"""
Expand All @@ -532,7 +532,7 @@ def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
# Below are incremental streams


class Comments(IncrementalGithubStream):
class Comments(IncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/issues#list-issue-comments-for-a-repository
"""
Expand All @@ -543,7 +543,7 @@ def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
return f"repos/{stream_slice['repository']}/issues/comments"


class Commits(IncrementalGithubStream):
class Commits(IncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/repos#list-commits
Expand All @@ -559,7 +559,7 @@ def __init__(self, branches_to_pull: Mapping[str, List[str]], default_branches:
self.default_branches = default_branches

def request_params(self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, **kwargs) -> MutableMapping[str, Any]:
params = super(IncrementalGithubStream, self).request_params(stream_state=stream_state, stream_slice=stream_slice, **kwargs)
params = super(IncrementalMixin, self).request_params(stream_state=stream_state, stream_slice=stream_slice, **kwargs)
params["since"] = self.get_starting_point(stream_state=stream_state, stream_slice=stream_slice)
params["sha"] = stream_slice["branch"]
return params
Expand Down Expand Up @@ -616,7 +616,7 @@ def get_starting_point(self, stream_state: Mapping[str, Any], stream_slice: Mapp
return self._start_date


class Issues(IncrementalGithubStream):
class Issues(IncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/issues#list-repository-issues
"""
Expand All @@ -630,7 +630,7 @@ class Issues(IncrementalGithubStream):
}


class ReviewComments(IncrementalGithubStream):
class ReviewComments(IncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/pulls#list-review-comments-in-a-repository
"""
Expand All @@ -644,7 +644,7 @@ def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
# Pull request substreams


class PullRequestSubstream(HttpSubStream, SemiIncrementalGithubStream, ABC):
class PullRequestSubstream(HttpSubStream, SemiIncrementalMixin, GithubStream):
use_cache = False

def __init__(self, parent: PullRequests, **kwargs):
Expand Down Expand Up @@ -675,9 +675,9 @@ def read_records(
) -> Iterable[Mapping[str, Any]]:
"""
We've already determined the list of pull requests to run the stream against.
Skip the start_point_map and cursor_field logic in SemiIncrementalGithubStream.read_records.
Skip the start_point_map and cursor_field logic in SemiIncrementalMixin.read_records.
"""
yield from super(SemiIncrementalGithubStream, self).read_records(
yield from super(SemiIncrementalMixin, self).read_records(
sync_mode=sync_mode, cursor_field=cursor_field, stream_slice=stream_slice, stream_state=stream_state
)

Expand Down Expand Up @@ -827,7 +827,7 @@ class PullRequestCommentReactions(ReactionStream):
parent_entity = ReviewComments


class Deployments(SemiIncrementalGithubStream):
class Deployments(SemiIncrementalMixin, GithubStream):
"""
API docs: https://docs.github.com/en/rest/reference/deployments#list-deployments
"""
Expand Down

1 comment on commit 6121b4f

@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(#12294)

Measures

Name Value Name Value Name Value
Lines to Cover 705 Duplicated Blocks 7 Security Rating A
Bugs 0 Lines of Code 936 Vulnerabilities 0
Reliability Rating A Quality Gate Status OK Coverage 79.3
Code Smells 4 Duplicated Lines (%) 6.0 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 (79.3%)

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 94.4

Please sign in to comment.