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
113 changes: 113 additions & 0 deletions tap_github/repository_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,119 @@ class TagsStream(GitHubRestStream):
th.Property("node_id", th.StringType),
).to_dict()

def get_child_context(self, record: dict, context: dict | None) -> dict:
"""Return a child context object from the record and optional provided context.
By default, will return context if provided and otherwise the record dict.
Developers may override this behavior to send specific information to child
streams for context.
"""
return {
"org": context["org"] if context else None,
"repo": context["repo"] if context else None,
"tag_name": record["name"],
"repo_id": context["repo_id"] if context else None,
}


class GetTagShasStream(GitHubRestStream):
"""A stream dedicated to fetching tag shas of a tag in a repository.

API docs: https://docs.github.com/en/rest/git/refs#get-a-reference
"""

name = "get_tag_shas"
path = "/repos/{org}/{repo}/git/ref/tags/{tag_name}"
primary_keys: ClassVar[list[str]] = ["node_id"]
parent_stream_type = TagsStream
ignore_parent_replication_key = True
state_partitioning_keys: ClassVar[list[str]] = ["repo", "org", "tag_name"]
tolerated_http_errors: ClassVar[list[int]] = [404]

schema = th.PropertiesList(
# Parent Keys
th.Property("repo", th.StringType),
th.Property("org", th.StringType),
th.Property("repo_id", th.IntegerType),
th.Property("tag_name", th.StringType),
# Tag Sha Details
th.Property("ref", th.StringType),
th.Property("node_id", th.StringType),
th.Property("url", th.StringType),
th.Property(
"object",
th.ObjectType(
th.Property("type", th.StringType),
th.Property("sha", th.StringType),
th.Property("url", th.StringType),
),
),
).to_dict()

def get_child_context(self, record: dict, context: dict | None) -> dict:
"""Return a child context object from the record and optional provided context.
By default, will return context if provided and otherwise the record dict.
Developers may override this behavior to send specific information to child
streams for context.
"""
return {
"org": context["org"] if context else None,
"repo": context["repo"] if context else None,
"tag_sha": record["object"]["sha"] if record.get("object") else None,
"repo_id": context["repo_id"] if context else None,
}


class TagDetailsStream(GitHubRestStream):
"""A stream dedicated to fetching details of a tag in a repository."""

name = "tag_details"
path = "/repos/{org}/{repo}/git/tags/{tag_sha}"
primary_keys: ClassVar[list[str]] = ["node_id"]
parent_stream_type = GetTagShasStream
ignore_parent_replication_key = True
state_partitioning_keys: ClassVar[list[str]] = ["repo", "org", "tag_sha"]
tolerated_http_errors: ClassVar[list[int]] = [404]

schema = th.PropertiesList(
# Parent Keys
th.Property("repo", th.StringType),
th.Property("org", th.StringType),
th.Property("repo_id", th.IntegerType),
th.Property("tag_sha", th.StringType),
# Tag Details
th.Property("node_id", th.StringType),
th.Property("tag", th.StringType),
th.Property("sha", th.StringType),
th.Property("url", th.StringType),
th.Property("message", th.StringType),
th.Property(
"tagger",
th.ObjectType(
th.Property("name", th.StringType),
th.Property("email", th.StringType),
th.Property("date", th.DateTimeType),
),
),
th.Property(
"object",
th.ObjectType(
th.Property("type", th.StringType),
th.Property("sha", th.StringType),
th.Property("url", th.StringType),
),
),
th.Property(
"verification",
th.ObjectType(
th.Property("verified", th.BooleanType),
th.Property("reason", th.StringType),
th.Property("signature", th.StringType),
th.Property("payload", th.StringType),
th.Property("verified_at", th.StringType),
),
),
).to_dict()


class DeploymentsStream(GitHubRestStream):
"""A stream dedicated to fetching deployments in a repository."""
Expand Down
4 changes: 4 additions & 0 deletions tap_github/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
DeploymentStatusesStream,
EventsStream,
ExtraMetricsStream,
GetTagShasStream,
IssueCommentsStream,
IssueEventsStream,
IssuesStream,
Expand All @@ -45,6 +46,7 @@
StargazersGraphqlStream,
StargazersStream,
StatsContributorsStream,
TagDetailsStream,
TagsStream,
TrafficClonesStream,
TrafficPageViewsStream,
Expand Down Expand Up @@ -88,6 +90,7 @@ def __init__(self, valid_queries: set[str], streams: list[type[Stream]]) -> None
DeploymentsStream,
DeploymentStatusesStream,
EventsStream,
GetTagShasStream,
IssueCommentsStream,
IssueEventsStream,
IssuesStream,
Expand All @@ -111,6 +114,7 @@ def __init__(self, valid_queries: set[str], streams: list[type[Stream]]) -> None
StargazersStream,
StatsContributorsStream,
TagsStream,
TagDetailsStream,
TrafficClonesStream,
TrafficPageViewsStream,
TrafficReferralPathsStream,
Expand Down