diff --git a/tap_github/streams.py b/tap_github/streams.py index 0f351cc0..7ae56741 100644 --- a/tap_github/streams.py +++ b/tap_github/streams.py @@ -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 @@ -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. @@ -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.""" diff --git a/tap_github/tap.py b/tap_github/tap.py index d1fc1ebe..4f01cae7 100644 --- a/tap_github/tap.py +++ b/tap_github/tap.py @@ -12,6 +12,7 @@ IssueEventsStream, IssuesStream, PullRequestsStream, + PullRequestFilesStream, ReadmeStream, RepositoryStream, StargazersStream, @@ -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),