diff --git a/pontos/github/api/client.py b/pontos/github/api/client.py index 5140e759..f0da4266 100644 --- a/pontos/github/api/client.py +++ b/pontos/github/api/client.py @@ -34,6 +34,10 @@ Headers = Dict[str, str] Params = Dict[str, str] +# supported GitHub API version +# https://docs.github.com/en/rest/overview/api-versions +GITHUB_API_VERSION = "2022-11-28" + class GitHubAsyncRESTClient(AbstractAsyncContextManager): """ @@ -67,7 +71,8 @@ def _request_headers( Get the default request headers """ headers = { - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", + "X-GitHub-Api-Version": GITHUB_API_VERSION, } if self.token: headers["Authorization"] = f"token {self.token}" diff --git a/tests/github/api/test_client.py b/tests/github/api/test_client.py index 33968486..75aefa8a 100644 --- a/tests/github/api/test_client.py +++ b/tests/github/api/test_client.py @@ -19,7 +19,7 @@ from unittest.mock import MagicMock, call, patch -from pontos.github.api.client import GitHubAsyncRESTClient +from pontos.github.api.client import GITHUB_API_VERSION, GitHubAsyncRESTClient from pontos.github.api.helper import DEFAULT_GITHUB_API_URL from tests import AsyncMock, IsolatedAsyncioTestCase, aiter, anext @@ -37,8 +37,9 @@ async def test_get(self): self.http_client.get.assert_awaited_once_with( f"{DEFAULT_GITHUB_API_URL}/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, params=None, follow_redirects=True, @@ -50,8 +51,9 @@ async def test_get_url(self): self.http_client.get.assert_awaited_once_with( "https://github.com/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, params=None, follow_redirects=True, @@ -79,8 +81,9 @@ async def test_get_all(self): call( f"{DEFAULT_GITHUB_API_URL}/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, params=None, follow_redirects=True, @@ -88,8 +91,9 @@ async def test_get_all(self): call( f"{url}", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, params=None, follow_redirects=True, @@ -103,8 +107,9 @@ async def test_delete(self): self.http_client.delete.assert_awaited_once_with( f"{DEFAULT_GITHUB_API_URL}/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, params=None, ) @@ -115,8 +120,9 @@ async def test_delete_url(self): self.http_client.delete.assert_awaited_once_with( "https://github.com/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, params=None, ) @@ -127,8 +133,9 @@ async def test_post(self): self.http_client.post.assert_awaited_once_with( f"{DEFAULT_GITHUB_API_URL}/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, json={"foo": "bar"}, params=None, @@ -143,8 +150,9 @@ async def test_post_url(self): self.http_client.post.assert_awaited_once_with( "https://github.com/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, json={"foo": "bar"}, params=None, @@ -157,8 +165,9 @@ async def test_put(self): self.http_client.put.assert_awaited_once_with( f"{DEFAULT_GITHUB_API_URL}/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, json={"foo": "bar"}, params=None, @@ -171,8 +180,9 @@ async def test_put_url(self): self.http_client.put.assert_awaited_once_with( "https://github.com/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, json={"foo": "bar"}, params=None, @@ -185,8 +195,9 @@ async def test_patch(self): self.http_client.patch.assert_awaited_once_with( f"{DEFAULT_GITHUB_API_URL}/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, json={"foo": "bar"}, params=None, @@ -201,8 +212,9 @@ async def test_patch_url(self): self.http_client.patch.assert_awaited_once_with( "https://github.com/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, json={"foo": "bar"}, params=None, @@ -222,8 +234,9 @@ async def test_stream(self): "GET", f"{DEFAULT_GITHUB_API_URL}/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, follow_redirects=True, ) @@ -241,8 +254,9 @@ async def test_stream_url(self): "GET", "https://github.com/foo/bar", headers={ - "Accept": "application/vnd.github.v3+json", + "Accept": "application/vnd.github+json", "Authorization": "token token", + "X-GitHub-Api-Version": GITHUB_API_VERSION, }, follow_redirects=True, )