Skip to content

Commit b706f59

Browse files
fix: can't add gitlab personal access token and add more debug log in validate_provider_token (#8782)
1 parent 633d5b2 commit b706f59

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

openhands/integrations/gitlab/gitlab_service.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,14 @@ async def get_user(self) -> User:
167167
url = f'{self.BASE_URL}/user'
168168
response, _ = await self._make_request(url)
169169

170+
# Use a default avatar URL if not provided
171+
# In some self-hosted GitLab instances, the avatar_url field may be returned as None.
172+
avatar_url = response.get('avatar_url') or ''
173+
170174
return User(
171175
id=response.get('id'),
172176
username=response.get('username'),
173-
avatar_url=response.get('avatar_url'),
177+
avatar_url=avatar_url,
174178
name=response.get('name'),
175179
email=response.get('email'),
176180
company=response.get('organization'),

openhands/integrations/provider.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def _get_service(self, provider: ProviderType) -> GitService:
130130
external_auth_token=self.external_auth_token,
131131
token=token.token,
132132
external_token_manager=self.external_token_manager,
133+
base_domain=token.host,
133134
)
134135

135136
async def get_user(self) -> User:

openhands/integrations/service_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def __init__(
184184
external_auth_id: str | None = None,
185185
external_auth_token: SecretStr | None = None,
186186
external_token_manager: bool = False,
187+
base_domain: str | None = None,
187188
) -> None:
188189
"""Initialize the service with authentication details"""
189190
...

openhands/integrations/utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import traceback
2+
13
from pydantic import SecretStr
24

5+
from openhands.core.logger import openhands_logger as logger
36
from openhands.integrations.github.github_service import GitHubService
47
from openhands.integrations.gitlab.gitlab_service import GitLabService
58
from openhands.integrations.provider import ProviderType
@@ -25,15 +28,19 @@ async def validate_provider_token(
2528
github_service = GitHubService(token=token, base_domain=base_domain)
2629
await github_service.verify_access()
2730
return ProviderType.GITHUB
28-
except Exception:
29-
pass
31+
except Exception as e:
32+
logger.debug(
33+
f'Failed to validate Github token: {e} \n {traceback.format_exc()}'
34+
)
3035

3136
# Try GitLab next
3237
try:
3338
gitlab_service = GitLabService(token=token, base_domain=base_domain)
3439
await gitlab_service.get_user()
3540
return ProviderType.GITLAB
36-
except Exception:
37-
pass
41+
except Exception as e:
42+
logger.debug(
43+
f'Failed to validate GitLab token: {e} \n {traceback.format_exc()}'
44+
)
3845

3946
return None

openhands/runtime/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ async def clone_or_init_repo(
398398

399399
domain = provider_domains[provider]
400400

401+
# If git_provider_tokens is provided, use the host from the token if available
402+
if git_provider_tokens and provider in git_provider_tokens:
403+
domain = git_provider_tokens[provider].host or domain
404+
401405
# Try to use token if available, otherwise use public URL
402406
if git_provider_tokens and provider in git_provider_tokens:
403407
git_token = git_provider_tokens[provider].token

0 commit comments

Comments
 (0)