Skip to content

Commit d37c605

Browse files
committed
add PullRequestLabelEventsStream
1 parent 9033fe4 commit d37c605

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

tap_github/repository_streams.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,69 @@ class ReviewsStream(GitHubRestStream):
15511551
th.Property("author_association", th.StringType),
15521552
).to_dict()
15531553

1554+
class PullRequestLabelEventsStream(GitHubRestStream):
1555+
"""A stream dedicated to fetching label events (added/removed) for pull requests in a repository.
1556+
Note: This stream uses the issues timeline API since GitHub treats PRs as issues internally."""
1557+
1558+
name = "pull_request_label_events"
1559+
path = "/repos/{org}/{repo}/issues/{pull_number}/timeline"
1560+
primary_keys: ClassVar[list[str]] = ["node_id"]
1561+
parent_stream_type = PullRequestsStream
1562+
ignore_parent_replication_key = True
1563+
state_partitioning_keys: ClassVar[list[str]] = ["repo", "org", "pull_number"]
1564+
tolerated_http_errors: ClassVar[list[int]] = [404]
1565+
1566+
def parse_response(self, response: requests.Response) -> Iterable[dict]:
1567+
"""Parse the response and filter for label events only."""
1568+
for event in super().parse_response(response):
1569+
if event.get("event") == "labeled" or event.get("event") == "unlabeled":
1570+
yield event
1571+
1572+
schema = th.PropertiesList(
1573+
# Parent Keys
1574+
th.Property("repo", th.StringType),
1575+
th.Property("org", th.StringType),
1576+
th.Property("repo_id", th.IntegerType),
1577+
# Event Keys
1578+
th.Property("id", th.IntegerType),
1579+
th.Property("node_id", th.StringType),
1580+
th.Property("url", th.StringType),
1581+
th.Property("event", th.StringType),
1582+
th.Property("commit_id", th.StringType),
1583+
th.Property("created_at", th.DateTimeType),
1584+
th.Property(
1585+
"actor",
1586+
th.ObjectType(
1587+
th.Property("login", th.StringType),
1588+
th.Property("id", th.IntegerType),
1589+
th.Property("node_id", th.StringType),
1590+
th.Property("avatar_url", th.StringType),
1591+
th.Property("gravatar_id", th.StringType),
1592+
th.Property("url", th.StringType),
1593+
th.Property("html_url", th.StringType),
1594+
th.Property("followers_url", th.StringType),
1595+
th.Property("following_url", th.StringType),
1596+
th.Property("gists_url", th.StringType),
1597+
th.Property("starred_url", th.StringType),
1598+
th.Property("subscriptions_url", th.StringType),
1599+
th.Property("organizations_url", th.StringType),
1600+
th.Property("repos_url", th.StringType),
1601+
th.Property("events_url", th.StringType),
1602+
th.Property("received_events_url", th.StringType),
1603+
th.Property("type", th.StringType),
1604+
th.Property("site_admin", th.BooleanType),
1605+
),
1606+
),
1607+
th.Property(
1608+
"label",
1609+
th.ObjectType(
1610+
th.Property("name", th.StringType),
1611+
th.Property("color", th.StringType),
1612+
),
1613+
),
1614+
th.Property("performed_via_github_app", th.StringType),
1615+
).to_dict()
1616+
15541617

15551618
class ReviewCommentsStream(GitHubRestStream):
15561619
name = "review_comments"

tap_github/streams.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
PullRequestCommits,
3737
PullRequestDiffsStream,
3838
PullRequestsStream,
39+
PullRequestLabelEventsStream,
3940
ReadmeHtmlStream,
4041
ReadmeStream,
4142
ReleasesStream,
@@ -100,6 +101,7 @@ def __init__(self, valid_queries: set[str], streams: list[type[Stream]]) -> None
100101
PullRequestCommits,
101102
PullRequestDiffsStream,
102103
PullRequestsStream,
104+
PullRequestLabelEventsStream,
103105
ReadmeHtmlStream,
104106
ReadmeStream,
105107
ReleasesStream,

0 commit comments

Comments
 (0)