mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-08 22:38:05 -05:00
Update GithubIntegration to use auth=Auth.AppAuth() (#12204)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -6,7 +6,7 @@ from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
from github import Github, GithubIntegration
|
||||
from github import Auth, Github, GithubIntegration
|
||||
from integrations.github.github_view import (
|
||||
GithubIssue,
|
||||
)
|
||||
@@ -84,7 +84,7 @@ class GitHubDataCollector:
|
||||
# self.full_saved_pr_path = 'github_data/prs/{}-{}/data.json'
|
||||
self.full_saved_pr_path = 'prs/github/{}-{}/data.json'
|
||||
self.github_integration = GithubIntegration(
|
||||
GITHUB_APP_CLIENT_ID, GITHUB_APP_PRIVATE_KEY
|
||||
auth=Auth.AppAuth(GITHUB_APP_CLIENT_ID, GITHUB_APP_PRIVATE_KEY)
|
||||
)
|
||||
self.conversation_id = None
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from types import MappingProxyType
|
||||
|
||||
from github import Github, GithubIntegration
|
||||
from github import Auth, Github, GithubIntegration
|
||||
from integrations.github.data_collector import GitHubDataCollector
|
||||
from integrations.github.github_solvability import summarize_issue_solvability
|
||||
from integrations.github.github_view import (
|
||||
@@ -43,7 +43,7 @@ class GithubManager(Manager):
|
||||
self.token_manager = token_manager
|
||||
self.data_collector = data_collector
|
||||
self.github_integration = GithubIntegration(
|
||||
GITHUB_APP_CLIENT_ID, GITHUB_APP_PRIVATE_KEY
|
||||
auth=Auth.AppAuth(GITHUB_APP_CLIENT_ID, GITHUB_APP_PRIVATE_KEY)
|
||||
)
|
||||
|
||||
self.jinja_env = Environment(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from dataclasses import dataclass
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from github import Github, GithubIntegration
|
||||
from github import Auth, Github, GithubIntegration
|
||||
from github.Issue import Issue
|
||||
from integrations.github.github_types import (
|
||||
WorkflowRun,
|
||||
@@ -729,7 +729,7 @@ class GithubFactory:
|
||||
|
||||
def _interact_with_github() -> Issue | None:
|
||||
with GithubIntegration(
|
||||
GITHUB_APP_CLIENT_ID, GITHUB_APP_PRIVATE_KEY
|
||||
auth=Auth.AppAuth(GITHUB_APP_CLIENT_ID, GITHUB_APP_PRIVATE_KEY)
|
||||
) as integration:
|
||||
access_token = integration.get_access_token(
|
||||
payload['installation']['id']
|
||||
@@ -867,7 +867,7 @@ class GithubFactory:
|
||||
|
||||
access_token = ''
|
||||
with GithubIntegration(
|
||||
GITHUB_APP_CLIENT_ID, GITHUB_APP_PRIVATE_KEY
|
||||
auth=Auth.AppAuth(GITHUB_APP_CLIENT_ID, GITHUB_APP_PRIVATE_KEY)
|
||||
) as integration:
|
||||
access_token = integration.get_access_token(installation_id).token
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Any
|
||||
from uuid import UUID
|
||||
|
||||
import httpx
|
||||
from github import Github, GithubIntegration
|
||||
from github import Auth, Github, GithubIntegration
|
||||
from pydantic import Field
|
||||
|
||||
from openhands.agent_server.models import AskAgentRequest, AskAgentResponse
|
||||
@@ -124,8 +124,7 @@ class GithubV1CallbackProcessor(EventCallbackProcessor):
|
||||
raise ValueError('GitHub App credentials are not configured')
|
||||
|
||||
github_integration = GithubIntegration(
|
||||
github_app_client_id,
|
||||
github_app_private_key,
|
||||
auth=Auth.AppAuth(github_app_client_id, github_app_private_key),
|
||||
)
|
||||
token_data = github_integration.get_access_token(installation_id)
|
||||
return token_data.token
|
||||
|
||||
@@ -211,6 +211,7 @@ class TestGithubV1CallbackProcessor:
|
||||
@patch(
|
||||
'openhands.app_server.event_callback.github_v1_callback_processor.get_prompt_template'
|
||||
)
|
||||
@patch('openhands.app_server.event_callback.github_v1_callback_processor.Auth')
|
||||
@patch(
|
||||
'openhands.app_server.event_callback.github_v1_callback_processor.GithubIntegration'
|
||||
)
|
||||
@@ -219,6 +220,7 @@ class TestGithubV1CallbackProcessor:
|
||||
self,
|
||||
mock_github,
|
||||
mock_github_integration,
|
||||
mock_auth,
|
||||
mock_get_prompt_template,
|
||||
mock_get_httpx_client,
|
||||
mock_get_sandbox_service,
|
||||
@@ -242,6 +244,10 @@ class TestGithubV1CallbackProcessor:
|
||||
|
||||
mock_get_prompt_template.return_value = 'Please provide a summary'
|
||||
|
||||
# Auth.AppAuth mock
|
||||
mock_app_auth_instance = MagicMock()
|
||||
mock_auth.AppAuth.return_value = mock_app_auth_instance
|
||||
|
||||
# GitHub integration
|
||||
mock_token_data = MagicMock()
|
||||
mock_token_data.token = 'test_access_token'
|
||||
@@ -271,9 +277,8 @@ class TestGithubV1CallbackProcessor:
|
||||
assert result.detail == 'Test summary from agent'
|
||||
assert github_callback_processor.should_request_summary is False
|
||||
|
||||
mock_github_integration.assert_called_once_with(
|
||||
'test_client_id', 'test_private_key'
|
||||
)
|
||||
mock_auth.AppAuth.assert_called_once_with('test_client_id', 'test_private_key')
|
||||
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')
|
||||
@@ -618,12 +623,17 @@ class TestGithubV1CallbackProcessor:
|
||||
'GITHUB_APP_PRIVATE_KEY': 'test_private_key\\nwith_newlines',
|
||||
},
|
||||
)
|
||||
@patch('openhands.app_server.event_callback.github_v1_callback_processor.Auth')
|
||||
@patch(
|
||||
'openhands.app_server.event_callback.github_v1_callback_processor.GithubIntegration'
|
||||
)
|
||||
def test_get_installation_access_token_success(
|
||||
self, mock_github_integration, github_callback_processor
|
||||
self, mock_github_integration, mock_auth, github_callback_processor
|
||||
):
|
||||
# Auth.AppAuth mock
|
||||
mock_app_auth_instance = MagicMock()
|
||||
mock_auth.AppAuth.return_value = mock_app_auth_instance
|
||||
|
||||
mock_token_data = MagicMock()
|
||||
mock_token_data.token = 'test_access_token'
|
||||
mock_integration_instance = MagicMock()
|
||||
@@ -633,9 +643,10 @@ class TestGithubV1CallbackProcessor:
|
||||
token = github_callback_processor._get_installation_access_token()
|
||||
|
||||
assert token == 'test_access_token'
|
||||
mock_github_integration.assert_called_once_with(
|
||||
mock_auth.AppAuth.assert_called_once_with(
|
||||
'test_client_id', 'test_private_key\nwith_newlines'
|
||||
)
|
||||
mock_github_integration.assert_called_once_with(auth=mock_app_auth_instance)
|
||||
mock_integration_instance.get_access_token.assert_called_once_with(12345)
|
||||
|
||||
@patch('openhands.app_server.event_callback.github_v1_callback_processor.Github')
|
||||
|
||||
Reference in New Issue
Block a user