Skip to content

Commit

Permalink
lint2
Browse files Browse the repository at this point in the history
  • Loading branch information
angelachenn committed Jan 23, 2025
1 parent cd2e81a commit 43cabe0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tap_github/repository_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,7 @@ def post_process(self, row: dict, context: dict[str, str] | None = None) -> dict
row["pull_number"] = context["pull_number"]
return row


class PullRequestDiffsStream(GitHubRestStream):
name = "pull_request_diffs"
path = "/repos/{org}/{repo}/pulls/{pull_number}"
Expand All @@ -1439,6 +1440,7 @@ class PullRequestDiffsStream(GitHubRestStream):
ignore_parent_replication_key = False
state_partitioning_keys: ClassVar[list[str]] = ["repo", "org"]
tolerated_http_errors: ClassVar[list[int]] = [406, 422, 502]

@property
def http_headers(self) -> dict:
headers = super().http_headers
Expand All @@ -1455,7 +1457,9 @@ def parse_response(self, response: requests.Response) -> Iterable[dict]:
content_length = int(content_length_str)
max_size = 41943040 # 40 MiB
if content_length > max_size:
self.logger.info(f"Skipping PR. The diff size ({content_length / 1024 / 1024:.2f} MiB) exceeded the maximum size limit of 40 MiB.") # noqa: E501
self.logger.info(
f"Skipping PR. The diff size ({content_length / 1024 / 1024:.2f} MiB) exceeded the maximum size limit of 40 MiB." # noqa: E501
)
return

yield {"diff": response.text}
Expand All @@ -1464,7 +1468,9 @@ def validate_response(self, response: requests.Response) -> None:
"""Allow some specific errors."""
if response.status_code in self.tolerated_http_errors:
contents = response.json()
self.logger.info(f"Skipping PR due to {response.status_code} error: {contents['message']}") # noqa: E501
self.logger.info(
f"Skipping PR due to {response.status_code} error: {contents['message']}" # noqa: E501
)
return
super().validate_response(response)

Expand All @@ -1490,6 +1496,7 @@ def post_process(self, row: dict, context: dict[str, str] | None = None) -> dict
th.Property("diff", th.StringType),
).to_dict()


class ReviewsStream(GitHubRestStream):
name = "reviews"
path = "/repos/{org}/{repo}/pulls/{pull_number}/reviews"
Expand Down

0 comments on commit 43cabe0

Please sign in to comment.