Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions tap_github/repository_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,7 @@ class DependenciesStream(GitHubGraphqlStream):
parent_stream_type = RepositoryStream
state_partitioning_keys = ["repo_id"]
ignore_parent_replication_key = True
do_not_paginate = False

@property
def http_headers(self) -> dict:
Expand Down Expand Up @@ -2220,7 +2221,7 @@ def query(self) -> str:
"""Return dynamic GraphQL query."""
# Graphql id is equivalent to REST node_id. To keep the tap consistent, we rename "id" to "node_id".
# Due to GrapQl nested-pagination limitations, we loop through the top level dependencyGraphManifests one by one.
return """
initial_query = """
query repositoryDependencies($repo: String! $org: String! $nextPageCursor_0: String $nextPageCursor_1: String) {
repository(name: $repo owner: $org) {
dependencyGraphManifests (first: 1 withDependencies: true after: $nextPageCursor_0) {
Expand Down Expand Up @@ -2263,9 +2264,25 @@ def query(self) -> str:
cost
}
}

"""

if self.do_not_paginate:
no_pagination_query = initial_query.replace(
" $nextPageCursor_0: String $nextPageCursor_1: String", ""
)
no_pagination_query = no_pagination_query.replace(
"after: $nextPageCursor_0", ""
)
no_pagination_query = no_pagination_query.replace(
"after: $nextPageCursor_1", ""
)
no_pagination_query = no_pagination_query.replace("first: 1", "first: 10")
no_pagination_query = no_pagination_query.replace("first: 50", "first: 100")

return no_pagination_query

return initial_query

schema = th.PropertiesList(
# Parent Keys
th.Property("repo", th.StringType),
Expand Down Expand Up @@ -2296,6 +2313,12 @@ def query(self) -> str:
).to_dict()


class DependenciesStreamIncomplete(DependenciesStream):
"""Defines 'DependenciesStreamDirty' stream to limit pagination."""

do_not_paginate = True


class TrafficRestStream(GitHubRestStream):
"""Base class for Traffic Streams"""

Expand Down
2 changes: 2 additions & 0 deletions tap_github/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CommunityProfileStream,
ContributorsStream,
DependenciesStream,
DependenciesStreamIncomplete,
DependentsStream,
EventsStream,
ExtraMetricsStream,
Expand Down Expand Up @@ -75,6 +76,7 @@ def __init__(self, valid_queries: Set[str], streams: List[Type[Stream]]):
CommunityProfileStream,
ContributorsStream,
DependenciesStream,
DependenciesStreamIncomplete,
DependentsStream,
EventsStream,
IssueCommentsStream,
Expand Down