Skip to content

Commit

Permalink
Change: Adapt to new GitHub REST API versioning
Browse files Browse the repository at this point in the history
Adjust Accept header and send new X-GitHub-Api-Version header.

See https://docs.github.com/en/rest/overview/api-versions for more
details about the GitHub REST API versioning.
  • Loading branch information
bjoernricks committed Jan 12, 2023
1 parent 33cf82a commit c35afaa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
7 changes: 6 additions & 1 deletion pontos/github/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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}"
Expand Down
44 changes: 29 additions & 15 deletions tests/github/api/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -79,17 +81,19 @@ 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,
),
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,
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand Down

0 comments on commit c35afaa

Please sign in to comment.