From d37c6051be5961f1ca810a65887c8cac5f538159 Mon Sep 17 00:00:00 2001 From: Marvin Davila Date: Fri, 21 Feb 2025 00:32:51 -0500 Subject: [PATCH 1/3] add PullRequestLabelEventsStream --- tap_github/repository_streams.py | 63 ++++++++++++++++++++++++++++++++ tap_github/streams.py | 2 + 2 files changed, 65 insertions(+) diff --git a/tap_github/repository_streams.py b/tap_github/repository_streams.py index 1694b9ad..a0ae9591 100644 --- a/tap_github/repository_streams.py +++ b/tap_github/repository_streams.py @@ -1551,6 +1551,69 @@ class ReviewsStream(GitHubRestStream): th.Property("author_association", th.StringType), ).to_dict() +class PullRequestLabelEventsStream(GitHubRestStream): + """A stream dedicated to fetching label events (added/removed) for pull requests in a repository. + Note: This stream uses the issues timeline API since GitHub treats PRs as issues internally.""" + + name = "pull_request_label_events" + path = "/repos/{org}/{repo}/issues/{pull_number}/timeline" + primary_keys: ClassVar[list[str]] = ["node_id"] + parent_stream_type = PullRequestsStream + ignore_parent_replication_key = True + state_partitioning_keys: ClassVar[list[str]] = ["repo", "org", "pull_number"] + tolerated_http_errors: ClassVar[list[int]] = [404] + + def parse_response(self, response: requests.Response) -> Iterable[dict]: + """Parse the response and filter for label events only.""" + for event in super().parse_response(response): + if event.get("event") == "labeled" or event.get("event") == "unlabeled": + yield event + + schema = th.PropertiesList( + # Parent Keys + th.Property("repo", th.StringType), + th.Property("org", th.StringType), + th.Property("repo_id", th.IntegerType), + # Event Keys + th.Property("id", th.IntegerType), + th.Property("node_id", th.StringType), + th.Property("url", th.StringType), + th.Property("event", th.StringType), + th.Property("commit_id", th.StringType), + th.Property("created_at", th.DateTimeType), + th.Property( + "actor", + th.ObjectType( + th.Property("login", th.StringType), + th.Property("id", th.IntegerType), + th.Property("node_id", th.StringType), + th.Property("avatar_url", th.StringType), + th.Property("gravatar_id", th.StringType), + th.Property("url", th.StringType), + th.Property("html_url", th.StringType), + th.Property("followers_url", th.StringType), + th.Property("following_url", th.StringType), + th.Property("gists_url", th.StringType), + th.Property("starred_url", th.StringType), + th.Property("subscriptions_url", th.StringType), + th.Property("organizations_url", th.StringType), + th.Property("repos_url", th.StringType), + th.Property("events_url", th.StringType), + th.Property("received_events_url", th.StringType), + th.Property("type", th.StringType), + th.Property("site_admin", th.BooleanType), + ), + ), + th.Property( + "label", + th.ObjectType( + th.Property("name", th.StringType), + th.Property("color", th.StringType), + ), + ), + th.Property("performed_via_github_app", th.StringType), + ).to_dict() + class ReviewCommentsStream(GitHubRestStream): name = "review_comments" diff --git a/tap_github/streams.py b/tap_github/streams.py index a14ac323..08453a1b 100644 --- a/tap_github/streams.py +++ b/tap_github/streams.py @@ -36,6 +36,7 @@ PullRequestCommits, PullRequestDiffsStream, PullRequestsStream, + PullRequestLabelEventsStream, ReadmeHtmlStream, ReadmeStream, ReleasesStream, @@ -100,6 +101,7 @@ def __init__(self, valid_queries: set[str], streams: list[type[Stream]]) -> None PullRequestCommits, PullRequestDiffsStream, PullRequestsStream, + PullRequestLabelEventsStream, ReadmeHtmlStream, ReadmeStream, ReleasesStream, From 38a4441018af4108321f2960f70fb24dcc8073a4 Mon Sep 17 00:00:00 2001 From: Marvin Davila Date: Fri, 21 Feb 2025 00:39:43 -0500 Subject: [PATCH 2/3] add pull number --- tap_github/repository_streams.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tap_github/repository_streams.py b/tap_github/repository_streams.py index a0ae9591..e5f8ef7a 100644 --- a/tap_github/repository_streams.py +++ b/tap_github/repository_streams.py @@ -1574,6 +1574,7 @@ def parse_response(self, response: requests.Response) -> Iterable[dict]: th.Property("repo", th.StringType), th.Property("org", th.StringType), th.Property("repo_id", th.IntegerType), + th.Property("pull_number", th.IntegerType), # Event Keys th.Property("id", th.IntegerType), th.Property("node_id", th.StringType), From fa88b51199ebc73342c5d6c3069f7d5162b1b257 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 21 Feb 2025 05:41:42 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tap_github/repository_streams.py | 1 + tap_github/streams.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tap_github/repository_streams.py b/tap_github/repository_streams.py index e5f8ef7a..ac265d09 100644 --- a/tap_github/repository_streams.py +++ b/tap_github/repository_streams.py @@ -1551,6 +1551,7 @@ class ReviewsStream(GitHubRestStream): th.Property("author_association", th.StringType), ).to_dict() + class PullRequestLabelEventsStream(GitHubRestStream): """A stream dedicated to fetching label events (added/removed) for pull requests in a repository. Note: This stream uses the issues timeline API since GitHub treats PRs as issues internally.""" diff --git a/tap_github/streams.py b/tap_github/streams.py index 08453a1b..9a1f0905 100644 --- a/tap_github/streams.py +++ b/tap_github/streams.py @@ -35,8 +35,8 @@ ProjectsStream, PullRequestCommits, PullRequestDiffsStream, - PullRequestsStream, PullRequestLabelEventsStream, + PullRequestsStream, ReadmeHtmlStream, ReadmeStream, ReleasesStream,