airbyte-source-github 1.8.35__py3-none-any.whl → 1.8.36.dev202507211247__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: airbyte-source-github
3
- Version: 1.8.35
3
+ Version: 1.8.36.dev202507211247
4
4
  Summary: Source implementation for GitHub.
5
5
  License: MIT
6
6
  Author: Airbyte
@@ -1,5 +1,5 @@
1
1
  source_github/__init__.py,sha256=punPc3v0mXEYOun7cbkfM5KUhgjv72B9DgDhI4VtzcQ,1134
2
- source_github/backoff_strategies.py,sha256=ChkWEmqZL7Qrr1zidOfjZWlMWIVRVO2yqZ7QE_HaZP8,2287
2
+ source_github/backoff_strategies.py,sha256=0BWPR4_EtguVIIhN1-_fsPExiGs40FuXrtK_4qxHeKg,2936
3
3
  source_github/config_migrations.py,sha256=H58hHqAnuvb0B8IXHW4aEDZ3HotEg7HdA2rXDG9XW7A,3832
4
4
  source_github/constants.py,sha256=Hj3Q4y7OoU-Iff4m9gEC2CjwmWJYXhNbHVNjg8EBLmQ,238
5
5
  source_github/errors_handlers.py,sha256=POqpvbrNAoZztjwByOJxJbIaxhWC8KWLi3gK1WzbiK8,7259
@@ -57,8 +57,8 @@ source_github/schemas/workflows.json,sha256=gSNw8WZaVKbX4AL97PbjZHzvxcOltXqv9Ao1
57
57
  source_github/source.py,sha256=1o8eayigi4xSUeNHdCd-mhNswGUq_XQrVk2eihTjm1o,14246
58
58
  source_github/spec.json,sha256=7LOQm01fP_RvPF-HifhNPJ7i0AxT2LTNPaLAA3uOfNY,7443
59
59
  source_github/streams.py,sha256=h5YMPLIsLTv7WX_mcURVC2LmmWBLraZvKH8J_GzV1IE,77441
60
- source_github/utils.py,sha256=Ztd8VWwzTNUg_A96_8R9XSKorIcBa8wJ6aYUqygRkyk,5492
61
- airbyte_source_github-1.8.35.dist-info/METADATA,sha256=P147eE6-Wz5AIJSJju6a0VFArfxrQIAuEvRurEUVtZQ,5202
62
- airbyte_source_github-1.8.35.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
63
- airbyte_source_github-1.8.35.dist-info/entry_points.txt,sha256=gYhqVrTAZvMwuYByg0b_-o115yUFLLcfNxMrLZmiW9k,55
64
- airbyte_source_github-1.8.35.dist-info/RECORD,,
60
+ source_github/utils.py,sha256=SzjCYAOOtpzmpj7A3KOAMSlY-v2HSWOXOWUjxOk2Ges,5959
61
+ airbyte_source_github-1.8.36.dev202507211247.dist-info/METADATA,sha256=NS3dCMe40d7sDPv3VEiGAp8__vLr6nGGKRb_hjhiEAk,5218
62
+ airbyte_source_github-1.8.36.dev202507211247.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
63
+ airbyte_source_github-1.8.36.dev202507211247.dist-info/entry_points.txt,sha256=gYhqVrTAZvMwuYByg0b_-o115yUFLLcfNxMrLZmiW9k,55
64
+ airbyte_source_github-1.8.36.dev202507211247.dist-info/RECORD,,
@@ -12,6 +12,10 @@ from airbyte_cdk.sources.streams.http import HttpStream
12
12
 
13
13
 
14
14
  class GithubStreamABCBackoffStrategy(BackoffStrategy):
15
+ min_backoff_time = 60.0
16
+ # https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api?apiVersion=2022-11-28
17
+ RATE_LIMITS_STATUS_CODES = [403, 429]
18
+
15
19
  def __init__(self, stream: HttpStream, **kwargs): # type: ignore # noqa
16
20
  self.stream = stream
17
21
  super().__init__(**kwargs)
@@ -23,23 +27,30 @@ class GithubStreamABCBackoffStrategy(BackoffStrategy):
23
27
  # `X-RateLimit-Reset` header which contains time when this hour will be finished and limits will be reset so
24
28
  # we again could have 5000 per another hour.
25
29
  if isinstance(response_or_exception, requests.Response):
26
- min_backoff_time = 60.0
27
30
  retry_after = response_or_exception.headers.get("Retry-After")
28
31
  if retry_after is not None:
29
- backoff_time_in_seconds = max(float(retry_after), min_backoff_time)
30
- return self.get_waiting_time(backoff_time_in_seconds)
32
+ backoff_time_in_seconds = max(float(retry_after), self.min_backoff_time)
33
+ return self.get_waiting_time(backoff_time_in_seconds, response_or_exception)
31
34
 
32
35
  reset_time = response_or_exception.headers.get("X-RateLimit-Reset")
33
36
  if reset_time:
34
- backoff_time_in_seconds = max(float(reset_time) - time.time(), min_backoff_time)
35
- return self.get_waiting_time(backoff_time_in_seconds)
37
+ backoff_time_in_seconds = max(float(reset_time) - time.time(), self.min_backoff_time)
38
+ return self.get_waiting_time(backoff_time_in_seconds, response_or_exception)
36
39
  return None
37
40
 
38
- def get_waiting_time(self, backoff_time_in_seconds: Optional[float]) -> Optional[float]:
41
+ def get_waiting_time(self, backoff_time_in_seconds: float, response: requests.Response) -> Optional[float]:
39
42
  if backoff_time_in_seconds < 60 * 10: # type: ignore[operator]
40
43
  return backoff_time_in_seconds
41
44
  else:
42
- self.stream._http_client._session.auth.update_token() # New token will be used in next request
45
+ # New token will be used in the next request or fail if all tokens are exhausted
46
+ if response.status_code in self.RATE_LIMITS_STATUS_CODES:
47
+ self.stream._http_client._session.auth.find_available_token(response.request)
48
+ else:
49
+ self.stream._http_client._session.auth.update_token()
50
+
51
+ # update headers in the request itself so the next request will use new token
52
+ response.request.headers.update(self.stream._http_client._session.auth.get_auth_header())
53
+
43
54
  return 1
44
55
 
45
56
 
source_github/utils.py CHANGED
@@ -76,8 +76,14 @@ class MultipleTokenAuthenticatorWithRateLimiter(AbstractHeaderAuthenticator):
76
76
  return {self.auth_header: self.token}
77
77
  return {}
78
78
 
79
- def __call__(self, request):
80
- """Attach the HTTP headers required to authenticate on the HTTP request"""
79
+ def find_available_token(self, request: requests.Request):
80
+ """
81
+ Iterates over each provided token and check their availability.
82
+ If no tokens are available or reset time is more than 10 minutes, an error is raised.
83
+ Method process_token() returns True is current token is available,
84
+ otherwise goes to the next token and sets it as current and checks for availability.
85
+ """
86
+
81
87
  while True:
82
88
  current_token = self._tokens[self.current_active_token]
83
89
  if "graphql" in request.path_url:
@@ -87,6 +93,11 @@ class MultipleTokenAuthenticatorWithRateLimiter(AbstractHeaderAuthenticator):
87
93
  if self.process_token(current_token, "count_rest", "reset_at_rest"):
88
94
  break
89
95
 
96
+ def __call__(self, request):
97
+ """Attach the HTTP headers required to authenticate on the HTTP request"""
98
+
99
+ self.find_available_token(request)
100
+
90
101
  request.headers.update(self.get_auth_header())
91
102
 
92
103
  return request