π OpenHands: AI-Driven Development
fix: can't add gitlab personal access token and add more debug log in validate_provider_token (#8782)
baiib706f59cfd73
diff --git a/openhands/integrations/gitlab/gitlab_service.py b/openhands/integrations/gitlab/gitlab_service.pyindex 59cb168a8e..9ad745c003 100644--- a/openhands/integrations/gitlab/gitlab_service.py+++ b/openhands/integrations/gitlab/gitlab_service.py@@ -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'),diff --git a/openhands/integrations/provider.py b/openhands/integrations/provider.pyindex ad89b042b3..6e60730526 100644--- a/openhands/integrations/provider.py+++ b/openhands/integrations/provider.py@@ -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:diff --git a/openhands/integrations/service_types.py b/openhands/integrations/service_types.pyindex a22f98764e..3e7dea4d79 100644--- a/openhands/integrations/service_types.py+++ b/openhands/integrations/service_types.py@@ -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"""...diff --git a/openhands/integrations/utils.py b/openhands/integrations/utils.pyindex 303fd9cb9b..16f26acd05 100644--- a/openhands/integrations/utils.py+++ b/openhands/integrations/utils.py@@ -1,5 +1,8 @@+import traceback+from pydantic import SecretStr+from openhands.core.logger import openhands_logger as loggerfrom openhands.integrations.github.github_service import GitHubServicefrom openhands.integrations.gitlab.gitlab_service import GitLabServicefrom 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 nexttry: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 Nonediff --git a/openhands/runtime/base.py b/openhands/runtime/base.pyindex d82a9786eb..421c428252 100644--- a/openhands/runtime/base.py+++ b/openhands/runtime/base.py@@ -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 URLif git_provider_tokens and provider in git_provider_tokens:git_token = git_provider_tokens[provider].token