mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
fix: can't add gitlab personal access token and add more debug log in validate_provider_token (#8782)
This commit is contained in:
parent
633d5b26d0
commit
b706f59cfd
@ -167,10 +167,14 @@ class GitLabService(BaseGitService, GitService):
|
||||
url = f'{self.BASE_URL}/user'
|
||||
response, _ = await self._make_request(url)
|
||||
|
||||
# Use a default avatar URL if not provided
|
||||
# In some self-hosted GitLab instances, the avatar_url field may be returned as None.
|
||||
avatar_url = response.get('avatar_url') or ''
|
||||
|
||||
return User(
|
||||
id=response.get('id'),
|
||||
username=response.get('username'),
|
||||
avatar_url=response.get('avatar_url'),
|
||||
avatar_url=avatar_url,
|
||||
name=response.get('name'),
|
||||
email=response.get('email'),
|
||||
company=response.get('organization'),
|
||||
|
||||
@ -130,6 +130,7 @@ class ProviderHandler:
|
||||
external_auth_token=self.external_auth_token,
|
||||
token=token.token,
|
||||
external_token_manager=self.external_token_manager,
|
||||
base_domain=token.host,
|
||||
)
|
||||
|
||||
async def get_user(self) -> User:
|
||||
|
||||
@ -184,6 +184,7 @@ class GitService(Protocol):
|
||||
external_auth_id: str | None = None,
|
||||
external_auth_token: SecretStr | None = None,
|
||||
external_token_manager: bool = False,
|
||||
base_domain: str | None = None,
|
||||
) -> None:
|
||||
"""Initialize the service with authentication details"""
|
||||
...
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import traceback
|
||||
|
||||
from pydantic import SecretStr
|
||||
|
||||
from openhands.core.logger import openhands_logger as logger
|
||||
from openhands.integrations.github.github_service import GitHubService
|
||||
from openhands.integrations.gitlab.gitlab_service import GitLabService
|
||||
from openhands.integrations.provider import ProviderType
|
||||
@ -25,15 +28,19 @@ async def validate_provider_token(
|
||||
github_service = GitHubService(token=token, base_domain=base_domain)
|
||||
await github_service.verify_access()
|
||||
return ProviderType.GITHUB
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.debug(
|
||||
f'Failed to validate Github token: {e} \n {traceback.format_exc()}'
|
||||
)
|
||||
|
||||
# Try GitLab next
|
||||
try:
|
||||
gitlab_service = GitLabService(token=token, base_domain=base_domain)
|
||||
await gitlab_service.get_user()
|
||||
return ProviderType.GITLAB
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.debug(
|
||||
f'Failed to validate GitLab token: {e} \n {traceback.format_exc()}'
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
@ -398,6 +398,10 @@ class Runtime(FileEditRuntimeMixin):
|
||||
|
||||
domain = provider_domains[provider]
|
||||
|
||||
# If git_provider_tokens is provided, use the host from the token if available
|
||||
if git_provider_tokens and provider in git_provider_tokens:
|
||||
domain = git_provider_tokens[provider].host or domain
|
||||
|
||||
# Try to use token if available, otherwise use public URL
|
||||
if git_provider_tokens and provider in git_provider_tokens:
|
||||
git_token = git_provider_tokens[provider].token
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user