Use pooled GitHub request sessions

Signed-off-by: Glenn Jocher <[email protected]>
This commit is contained in:
Glenn Jocher
2026-06-30 20:14:44 +02:00
committed by GitHub
parent 25f4525e1b
commit ab45c216a9
2 changed files with 3 additions and 2 deletions
+2 -1
View File
@@ -124,6 +124,7 @@ class Action:
self.owner, self.repo_name = self.repository.split("/") if self.repository else (None, None)
self.headers = {"Authorization": f"Bearer {self.token}", "Accept": "application/vnd.github+json"}
self.headers_diff = {"Authorization": f"Bearer {self.token}", "Accept": "application/vnd.github.v3.diff"}
self.session = requests.Session()
self.verbose = verbose
self.eyes_reaction_id = None
self._pr_diff_cache = None
@@ -138,7 +139,7 @@ class Action:
def _request(self, method: str, url: str, headers=None, expected_status=None, hard=False, **kwargs):
"""Unified request handler with error checking."""
r = getattr(requests, method)(url, headers=headers or self.headers, **kwargs)
r = getattr(self.session, method)(url, headers=headers or self.headers, **kwargs)
expected = expected_status or self._default_status[method]
status_expected = r.status_code in expected
success = status_expected and r.status_code < 400
+1 -1
View File
@@ -40,7 +40,7 @@ def test_action_init():
def test_action_request_methods():
"""Test Action HTTP request methods."""
with patch("requests.get") as mock_get:
with patch("requests.Session.get") as mock_get:
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.elapsed.total_seconds.return_value = 0.3