Skip to content

Commit

Permalink
šŸ› Source Github: Remove optional parameter Accept for reaction's stā€¦
Browse files Browse the repository at this point in the history
ā€¦reams to fix error with `502` HTTP status code (#9492)

* Source Github: Remove optional parameter Accept for reaction's streams to fix error with 502 HTTP status code
  • Loading branch information
yevhenii-ldv authored Jan 17, 2022
1 parent 25fb7e7 commit cb6d9ab
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
- name: GitHub
sourceDefinitionId: ef69ef6e-aa7f-4af1-a01d-ef775033524e
dockerRepository: airbyte/source-github
dockerImageTag: 0.2.10
dockerImageTag: 0.2.11
documentationUrl: https://docs.airbyte.io/integrations/sources/github
icon: github.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-github:0.2.10"
- dockerImage: "airbyte/source-github:0.2.11"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/github"
connectionSpecification:
Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-github/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.2.10
LABEL io.airbyte.version=0.2.11
LABEL io.airbyte.name=airbyte/source-github
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ def next_page_token(self, response: requests.Response) -> Optional[Mapping[str,
def should_retry(self, response: requests.Response) -> bool:
# We don't call `super()` here because we have custom error handling and GitHub API sometimes returns strange
# errors. So in `read_records()` we have custom error handling which don't require to call `super()` here.
return response.headers.get("X-RateLimit-Remaining") == "0" or response.status_code in (
retry_flag = response.headers.get("X-RateLimit-Remaining") == "0" or response.status_code in (
requests.codes.SERVER_ERROR,
requests.codes.BAD_GATEWAY,
)
if retry_flag:
self.logger.info(
f"Rate limit handling for the response with {response.status_code} status code with message: {response.json()}"
)
return retry_flag

def backoff_time(self, response: requests.Response) -> Union[int, float]:
# This method is called if we run into the rate limit. GitHub limits requests to 5000 per hour and provides
Expand Down Expand Up @@ -765,9 +770,6 @@ def stream_slices(self, **kwargs) -> Iterable[Optional[Mapping[str, Any]]]:
for parent_record in self._parent_stream.read_records(sync_mode=SyncMode.full_refresh, stream_slice=stream_slice):
yield {self.parent_key: parent_record[self.parent_key], "repository": stream_slice["repository"]}

def request_headers(self, **kwargs) -> Mapping[str, Any]:
return {"Accept": "application/vnd.github.squirrel-girl-preview+json"}


class CommitCommentReactions(ReactionStream):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@ def test_bad_gateway_retry(time_mock):
stream = PullRequestCommentReactions(**args)
stream_slice = {"repository": "test_repo", "id": "id"}

responses.add("GET", "https://api.github.com/repos/test_repo/pulls/comments/id/reactions", status=HTTPStatus.BAD_GATEWAY)
responses.add(
"GET",
"https://api.github.com/repos/test_repo/pulls/comments/id/reactions",
status=HTTPStatus.BAD_GATEWAY,
json={"message": "Bad request"},
)
with pytest.raises(BaseBackoffException):
list(stream.read_records(sync_mode="full_refresh", stream_slice=stream_slice))

sleep_delays = [delay[0][0] for delay in time_mock.call_args_list]
assert sleep_delays == DEFAULT_BACKOFF_DELAYS

time_mock.reset_mock()
responses.add("GET", "https://api.github.com/repos/test_repo/pulls/comments/id/reactions", status=HTTPStatus.INTERNAL_SERVER_ERROR)
responses.add(
"GET",
"https://api.github.com/repos/test_repo/pulls/comments/id/reactions",
status=HTTPStatus.INTERNAL_SERVER_ERROR,
json={"message": "Server Error"},
)
with pytest.raises(BaseBackoffException):
list(stream.read_records(sync_mode="full_refresh", stream_slice=stream_slice))

Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Your token should have at least the `repo` scope. Depending on which streams you

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.2.11 | 2021-01-17 | [9492](https://github.com/airbytehq/airbyte/pull/9492) | Remove optional parameter `Accept` for reaction`s streams to fix error with 502 HTTP status code in response |
| 0.2.10 | 2021-01-03 | [7250](https://github.com/airbytehq/airbyte/pull/7250) | Use CDK caching and convert PR-related streams to incremental |
| 0.2.9 | 2021-12-29 | [9179](https://github.com/airbytehq/airbyte/pull/9179) | Use default retry delays on server error responses |
| 0.2.8 | 2021-12-07 | [8524](https://github.com/airbytehq/airbyte/pull/8524) | Update connector fields title/description |
Expand Down

0 comments on commit cb6d9ab

Please sign in to comment.