Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set GitHub API version #1132

Merged
merged 2 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/github3/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,17 @@ def set_client_id(self, id, secret):
"""
self.session.params = {"client_id": id, "client_secret": secret}

def set_api_version(self, api_version):
"""Allow to set a specific API version.

:param str api_version:
API version to send with X-GitHub-Api-Version header.
See https://docs.github.com/en/rest/overview/api-versions?apiVersion=2022-11-28 for details on API versions.
""" # noqa: E501
if not api_version:
return
self.session.headers.update({"X-GitHub-Api-Version": api_version})

def set_user_agent(self, user_agent):
"""Allow the user to set their own user agent string.

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,12 @@ def test_set_user_agent_required_user_agent(self):

self.session.headers.update.called is False

def test_set_api_version(self):
self.instance.set_api_version("2022-11-28")
self.session.headers.update.assert_called_once_with(
{"X-GitHub-Api-Version": "2022-11-28"}
)

def test_set_user_agent(self):
self.instance.set_user_agent("github3py")
self.session.headers.update.assert_called_once_with(
Expand Down