Skip to content

Commit 9033fe4

Browse files
authored
feat: Added deployments and deployment_statuses streams (#363)
Adding 2 new stream for deployments: - [deployment list](https://docs.github.com/en/rest/deployments/deployments?apiVersion=2022-11-28#list-deployments) - [deployment status list](https://docs.github.com/en/rest/deployments/statuses?apiVersion=2022-11-28#list-deployment-statuses)
1 parent 1acfed3 commit 9033fe4

File tree

2 files changed

+133
-1
lines changed

2 files changed

+133
-1
lines changed

tap_github/repository_streams.py

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class ReadmeStream(GitHubRestStream):
294294
"""
295295
A stream dedicated to fetching the object version of a README.md.
296296
297-
Inclduding its content, base64 encoded of the readme in GitHub flavored Markdown.
297+
Including its content, base64 encoded of the readme in GitHub flavored Markdown.
298298
For html, see ReadmeHtmlStream.
299299
"""
300300

@@ -2625,3 +2625,131 @@ class TagsStream(GitHubRestStream):
26252625
th.Property("tarball_url", th.StringType),
26262626
th.Property("node_id", th.StringType),
26272627
).to_dict()
2628+
2629+
2630+
class DeploymentsStream(GitHubRestStream):
2631+
"""A stream dedicated to fetching deployments in a repository."""
2632+
2633+
name = "deployments"
2634+
path = "/repos/{org}/{repo}/deployments"
2635+
primary_keys: ClassVar[list[str]] = ["node_id"]
2636+
parent_stream_type = RepositoryStream
2637+
ignore_parent_replication_key = True
2638+
state_partitioning_keys: ClassVar[list[str]] = ["repo", "org"]
2639+
2640+
schema = th.PropertiesList(
2641+
# Parent Keys
2642+
th.Property("repo", th.StringType),
2643+
th.Property("org", th.StringType),
2644+
th.Property("repo_id", th.IntegerType),
2645+
# Deployment Keys
2646+
th.Property("url", th.StringType),
2647+
th.Property("id", th.IntegerType),
2648+
th.Property("node_id", th.StringType),
2649+
th.Property("sha", th.StringType),
2650+
th.Property("ref", th.StringType),
2651+
th.Property("task", th.StringType),
2652+
th.Property("payload", th.StringType),
2653+
th.Property("original_environment", th.StringType),
2654+
th.Property("environment", th.StringType),
2655+
th.Property("description", th.StringType),
2656+
th.Property(
2657+
"creator",
2658+
th.ObjectType(
2659+
th.Property("login", th.StringType),
2660+
th.Property("id", th.IntegerType),
2661+
th.Property("node_id", th.StringType),
2662+
th.Property("avatar_url", th.StringType),
2663+
th.Property("gravatar_id", th.StringType),
2664+
th.Property("url", th.StringType),
2665+
th.Property("html_url", th.StringType),
2666+
th.Property("followers_url", th.StringType),
2667+
th.Property("following_url", th.StringType),
2668+
th.Property("gists_url", th.StringType),
2669+
th.Property("starred_url", th.StringType),
2670+
th.Property("subscriptions_url", th.StringType),
2671+
th.Property("organizations_url", th.StringType),
2672+
th.Property("repos_url", th.StringType),
2673+
th.Property("events_url", th.StringType),
2674+
th.Property("received_events_url", th.StringType),
2675+
th.Property("type", th.StringType),
2676+
th.Property("site_admin", th.BooleanType),
2677+
),
2678+
),
2679+
th.Property("created_at", th.DateTimeType),
2680+
th.Property("updated_at", th.DateTimeType),
2681+
th.Property("statuses_url", th.StringType),
2682+
th.Property("repository_url", th.StringType),
2683+
th.Property("transient_environment", th.BooleanType),
2684+
th.Property("production_environment", th.BooleanType),
2685+
).to_dict()
2686+
2687+
def get_child_context(self, record: dict, context: dict | None) -> dict:
2688+
"""Return a child context object from the record and optional provided context.
2689+
By default, will return context if provided and otherwise the record dict.
2690+
Developers may override this behavior to send specific information to child
2691+
streams for context.
2692+
"""
2693+
return {
2694+
"org": context["org"] if context else None,
2695+
"repo": context["repo"] if context else None,
2696+
"deployment_id": record["id"],
2697+
"repo_id": context["repo_id"] if context else None,
2698+
}
2699+
2700+
2701+
class DeploymentStatusesStream(GitHubRestStream):
2702+
"""A stream dedicated to fetching deployment statuses in a repository."""
2703+
2704+
name = "deployment_statuses"
2705+
path = "/repos/{org}/{repo}/deployments/{deployment_id}/statuses"
2706+
primary_keys: ClassVar[list[str]] = ["node_id"]
2707+
parent_stream_type = DeploymentsStream
2708+
ignore_parent_replication_key = True
2709+
state_partitioning_keys: ClassVar[list[str]] = ["repo", "org", "deployment_id"]
2710+
tolerated_http_errors: ClassVar[list[int]] = [404]
2711+
2712+
schema = th.PropertiesList(
2713+
# Parent Keys
2714+
th.Property("repo", th.StringType),
2715+
th.Property("org", th.StringType),
2716+
th.Property("repo_id", th.IntegerType),
2717+
th.Property("deployment_id", th.IntegerType),
2718+
# Deployment Status Keys
2719+
th.Property("url", th.StringType),
2720+
th.Property("id", th.IntegerType),
2721+
th.Property("node_id", th.StringType),
2722+
th.Property("state", th.StringType),
2723+
th.Property(
2724+
"creator",
2725+
th.ObjectType(
2726+
th.Property("login", th.StringType),
2727+
th.Property("id", th.IntegerType),
2728+
th.Property("node_id", th.StringType),
2729+
th.Property("avatar_url", th.StringType),
2730+
th.Property("gravatar_id", th.StringType),
2731+
th.Property("url", th.StringType),
2732+
th.Property("html_url", th.StringType),
2733+
th.Property("followers_url", th.StringType),
2734+
th.Property("following_url", th.StringType),
2735+
th.Property("gists_url", th.StringType),
2736+
th.Property("starred_url", th.StringType),
2737+
th.Property("subscriptions_url", th.StringType),
2738+
th.Property("organizations_url", th.StringType),
2739+
th.Property("repos_url", th.StringType),
2740+
th.Property("events_url", th.StringType),
2741+
th.Property("received_events_url", th.StringType),
2742+
th.Property("type", th.StringType),
2743+
th.Property("site_admin", th.BooleanType),
2744+
),
2745+
),
2746+
th.Property("description", th.StringType),
2747+
th.Property("environment", th.StringType),
2748+
th.Property("target_url", th.StringType),
2749+
th.Property("created_at", th.DateTimeType),
2750+
th.Property("updated_at", th.DateTimeType),
2751+
th.Property("deployment_url", th.StringType),
2752+
th.Property("repository_url", th.StringType),
2753+
th.Property("environment_url", th.StringType),
2754+
th.Property("log_url", th.StringType),
2755+
).to_dict()

tap_github/streams.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
ContributorsStream,
2121
DependenciesStream,
2222
DependentsStream,
23+
DeploymentsStream,
24+
DeploymentStatusesStream,
2325
EventsStream,
2426
ExtraMetricsStream,
2527
IssueCommentsStream,
@@ -83,6 +85,8 @@ def __init__(self, valid_queries: set[str], streams: list[type[Stream]]) -> None
8385
ContributorsStream,
8486
DependenciesStream,
8587
DependentsStream,
88+
DeploymentsStream,
89+
DeploymentStatusesStream,
8690
EventsStream,
8791
IssueCommentsStream,
8892
IssueEventsStream,

0 commit comments

Comments
 (0)