mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-08 22:38:05 -05:00
Fix Python deprecation warning: use auth=Auth.Token() instead of login_or_token (#12299)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -138,7 +138,7 @@ class GithubV1CallbackProcessor(EventCallbackProcessor):
|
||||
issue_number = self.github_view_data['issue_number']
|
||||
|
||||
if self.inline_pr_comment:
|
||||
with Github(installation_token) as github_client:
|
||||
with Github(auth=Auth.Token(installation_token)) as github_client:
|
||||
repo = github_client.get_repo(full_repo_name)
|
||||
pr = repo.get_pull(issue_number)
|
||||
pr.create_review_comment_reply(
|
||||
@@ -146,7 +146,7 @@ class GithubV1CallbackProcessor(EventCallbackProcessor):
|
||||
)
|
||||
return
|
||||
|
||||
with Github(installation_token) as github_client:
|
||||
with Github(auth=Auth.Token(installation_token)) as github_client:
|
||||
repo = github_client.get_repo(full_repo_name)
|
||||
issue = repo.get_issue(number=issue_number)
|
||||
issue.create_comment(summary)
|
||||
|
||||
@@ -240,9 +240,11 @@ class TestGithubV1CallbackProcessor:
|
||||
|
||||
mock_get_summary_instruction.return_value = 'Please provide a summary'
|
||||
|
||||
# Auth.AppAuth mock
|
||||
# Auth.AppAuth and Auth.Token mock
|
||||
mock_app_auth_instance = MagicMock()
|
||||
mock_auth.AppAuth.return_value = mock_app_auth_instance
|
||||
mock_token_auth_instance = MagicMock()
|
||||
mock_auth.Token.return_value = mock_token_auth_instance
|
||||
|
||||
# GitHub integration
|
||||
mock_token_data = MagicMock()
|
||||
@@ -277,7 +279,8 @@ class TestGithubV1CallbackProcessor:
|
||||
mock_github_integration.assert_called_once_with(auth=mock_app_auth_instance)
|
||||
mock_integration_instance.get_access_token.assert_called_once_with(12345)
|
||||
|
||||
mock_github.assert_called_once_with('test_access_token')
|
||||
mock_auth.Token.assert_called_once_with('test_access_token')
|
||||
mock_github.assert_called_once_with(auth=mock_token_auth_instance)
|
||||
mock_github_client.get_repo.assert_called_once_with('test-owner/test-repo')
|
||||
mock_repo.get_issue.assert_called_once_with(number=42)
|
||||
mock_issue.create_comment.assert_called_once_with('Test summary from agent')
|
||||
@@ -662,9 +665,10 @@ class TestGithubV1CallbackProcessor:
|
||||
mock_github_integration.assert_called_once_with(auth=mock_app_auth_instance)
|
||||
mock_integration_instance.get_access_token.assert_called_once_with(12345)
|
||||
|
||||
@patch('integrations.github.github_v1_callback_processor.Auth')
|
||||
@patch('integrations.github.github_v1_callback_processor.Github')
|
||||
async def test_post_summary_to_github_issue_comment(
|
||||
self, mock_github, github_callback_processor
|
||||
self, mock_github, mock_auth, github_callback_processor
|
||||
):
|
||||
mock_github_client = MagicMock()
|
||||
mock_repo = MagicMock()
|
||||
@@ -673,6 +677,9 @@ class TestGithubV1CallbackProcessor:
|
||||
mock_github_client.get_repo.return_value = mock_repo
|
||||
mock_github.return_value.__enter__.return_value = mock_github_client
|
||||
|
||||
mock_token_auth = MagicMock()
|
||||
mock_auth.Token.return_value = mock_token_auth
|
||||
|
||||
with patch.object(
|
||||
github_callback_processor,
|
||||
'_get_installation_access_token',
|
||||
@@ -680,14 +687,16 @@ class TestGithubV1CallbackProcessor:
|
||||
):
|
||||
await github_callback_processor._post_summary_to_github('Test summary')
|
||||
|
||||
mock_github.assert_called_once_with('test_token')
|
||||
mock_auth.Token.assert_called_once_with('test_token')
|
||||
mock_github.assert_called_once_with(auth=mock_token_auth)
|
||||
mock_github_client.get_repo.assert_called_once_with('test-owner/test-repo')
|
||||
mock_repo.get_issue.assert_called_once_with(number=42)
|
||||
mock_issue.create_comment.assert_called_once_with('Test summary')
|
||||
|
||||
@patch('integrations.github.github_v1_callback_processor.Auth')
|
||||
@patch('integrations.github.github_v1_callback_processor.Github')
|
||||
async def test_post_summary_to_github_pr_comment(
|
||||
self, mock_github, github_callback_processor_inline
|
||||
self, mock_github, mock_auth, github_callback_processor_inline
|
||||
):
|
||||
mock_github_client = MagicMock()
|
||||
mock_repo = MagicMock()
|
||||
@@ -696,6 +705,9 @@ class TestGithubV1CallbackProcessor:
|
||||
mock_github_client.get_repo.return_value = mock_repo
|
||||
mock_github.return_value.__enter__.return_value = mock_github_client
|
||||
|
||||
mock_token_auth = MagicMock()
|
||||
mock_auth.Token.return_value = mock_token_auth
|
||||
|
||||
with patch.object(
|
||||
github_callback_processor_inline,
|
||||
'_get_installation_access_token',
|
||||
@@ -705,7 +717,8 @@ class TestGithubV1CallbackProcessor:
|
||||
'Test summary'
|
||||
)
|
||||
|
||||
mock_github.assert_called_once_with('test_token')
|
||||
mock_auth.Token.assert_called_once_with('test_token')
|
||||
mock_github.assert_called_once_with(auth=mock_token_auth)
|
||||
mock_github_client.get_repo.assert_called_once_with('test-owner/test-repo')
|
||||
mock_repo.get_pull.assert_called_once_with(42)
|
||||
mock_pr.create_review_comment_reply.assert_called_once_with(
|
||||
|
||||
Reference in New Issue
Block a user