Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add GitHub Streams (branches, tags) #357

Merged
merged 2 commits into from
Feb 13, 2025
Merged
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
72 changes: 72 additions & 0 deletions tap_github/repository_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -2548,3 +2548,75 @@ class TrafficPageViewsStream(TrafficRestStream):
th.Property("count", th.IntegerType),
th.Property("uniques", th.IntegerType),
).to_dict()


class BranchesStream(GitHubRestStream):
"""A stream dedicated to fetching the branches of a repository."""

name = "branches"
path = "/repos/{org}/{repo}/branches"
primary_keys: ClassVar[list[str]] = ["repo", "org"]
parent_stream_type = RepositoryStream
ignore_parent_replication_key = True
state_partitioning_keys: ClassVar[list[str]] = ["repo", "org"]
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),
# Branch Keys
th.Property("name", th.StringType),
th.Property(
"commit",
th.ObjectType(
th.Property("sha", th.StringType),
th.Property("url", th.StringType),
),
),
th.Property("protected", th.BooleanType),
th.Property(
"protection",
th.ObjectType(
th.Property(
"required_status_checks",
th.ObjectType(
th.Property("enforcement_level", th.StringType),
th.Property("contexts", th.ArrayType(th.StringType)),
),
),
),
),
th.Property("protection_url", th.StringType),
).to_dict()


class TagsStream(GitHubRestStream):
"""A stream dedicated to fetching tags in a repository."""

name = "tags"
path = "/repos/{org}/{repo}/tags"
primary_keys: ClassVar[list[str]] = ["repo", "org"]
parent_stream_type = RepositoryStream
ignore_parent_replication_key = True
state_partitioning_keys: ClassVar[list[str]] = ["repo", "org"]

schema = th.PropertiesList(
# Parent Keys
th.Property("repo", th.StringType),
th.Property("org", th.StringType),
th.Property("repo_id", th.IntegerType),
# Tag Keys
th.Property("name", th.StringType),
th.Property(
"commit",
th.ObjectType(
th.Property("sha", th.StringType),
th.Property("url", th.StringType),
),
),
th.Property("zipball_url", th.StringType),
th.Property("tarball_url", th.StringType),
th.Property("node_id", th.StringType),
).to_dict()
4 changes: 4 additions & 0 deletions tap_github/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tap_github.repository_streams import (
AnonymousContributorsStream,
AssigneesStream,
BranchesStream,
CollaboratorsStream,
CommitCommentsStream,
CommitsStream,
Expand Down Expand Up @@ -42,6 +43,7 @@
StargazersGraphqlStream,
StargazersStream,
StatsContributorsStream,
TagsStream,
TrafficClonesStream,
TrafficPageViewsStream,
TrafficReferralPathsStream,
Expand Down Expand Up @@ -73,6 +75,7 @@ def __init__(self, valid_queries: set[str], streams: list[type[Stream]]) -> None
[
AnonymousContributorsStream,
AssigneesStream,
BranchesStream,
CollaboratorsStream,
CommitCommentsStream,
CommitsStream,
Expand Down Expand Up @@ -103,6 +106,7 @@ def __init__(self, valid_queries: set[str], streams: list[type[Stream]]) -> None
StargazersGraphqlStream,
StargazersStream,
StatsContributorsStream,
TagsStream,
TrafficClonesStream,
TrafficPageViewsStream,
TrafficReferralPathsStream,
Expand Down
Loading