Skip to content
Closed
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
42 changes: 42 additions & 0 deletions tap_github/streams.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Stream type classes for tap-github."""

from typing import Any, Dict, Iterable, List, Optional

from singer_sdk import typing as th # JSON Schema typing helpers

from tap_github.client import GitHubStream
Expand Down Expand Up @@ -675,6 +676,18 @@ def get_url_params(
params["state"] = "all"
return params

def get_child_context(self, record: dict, context: Optional[dict]) -> dict:
"""
Give the PR number to children streams
"""

return {
**super().get_child_context(record, context),
**{
"pull_number": record["number"],
},
}

@property
def http_headers(self) -> dict:
"""Return the http headers needed.
Expand Down Expand Up @@ -906,6 +919,35 @@ def http_headers(self) -> dict:
).to_dict()


class PullRequestFilesStream(GitHubStream):
"""Defines 'PullRequestFiles' stream."""

name = "pull_request_files"
path = "/repos/{org}/{repo}/pulls/{pull_number}/files"
state_partitioning_keys = ["repo", "org", "pull_number"]
primary_keys = state_partitioning_keys + ["filename"]
parent_stream_type = PullRequestsStream
ignore_parent_replication_key = False

schema = th.PropertiesList(
# Keys
th.Property("repo", th.StringType),
th.Property("org", th.StringType),
th.Property("pull_number", th.IntegerType),
th.Property("filename", th.StringType),
# Rest
th.Property("sha", th.StringType),
th.Property("status", th.StringType),
th.Property("additions", th.IntegerType),
th.Property("deletions", th.IntegerType),
th.Property("changes", th.IntegerType),
th.Property("blob_url", th.StringType),
th.Property("raw_url", th.StringType),
th.Property("contents_url", th.StringType),
th.Property("patch", th.StringType),
).to_dict()


class StargazersStream(GitHubStream):
"""Defines 'Stargazers' stream. Warning: this stream does NOT track star deletions."""

Expand Down
2 changes: 2 additions & 0 deletions tap_github/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
IssueEventsStream,
IssuesStream,
PullRequestsStream,
PullRequestFilesStream,
ReadmeStream,
RepositoryStream,
StargazersStream,
Expand Down Expand Up @@ -51,6 +52,7 @@ def discover_streams(self) -> List[Stream]:
IssueEventsStream(tap=self),
IssuesStream(tap=self),
PullRequestsStream(tap=self),
PullRequestFilesStream(tap=self),
ReadmeStream(tap=self),
RepositoryStream(tap=self),
StargazersStream(tap=self),
Expand Down