Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Test fix for event loop #7681

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openhands/integrations/gitlab/gitlab_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ async def search_repositories(
async def get_repositories(
self, sort: str, installation_id: int | None
) -> list[Repository]:
if installation_id:
return [] # Not implementing installation_token case yet
# if installation_id:
# return [] # Not implementing installation_token case yet

MAX_REPOS = 1000
PER_PAGE = 100 # Maximum allowed by GitLab API
Expand Down
8 changes: 7 additions & 1 deletion openhands/runtime/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@ def add_env_vars(self, env_vars: dict[str, str]) -> None:

def on_event(self, event: Event) -> None:
if isinstance(event, Action):
asyncio.get_event_loop().run_until_complete(self._handle_action(event))
# Create a new event loop for this thread to avoid the "attached to a different loop" error
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(self._handle_action(event))
finally:
loop.close()

async def _export_latest_git_provider_tokens(self, event: Action) -> None:
"""
Expand Down
8 changes: 2 additions & 6 deletions openhands/server/routes/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,19 @@
app = APIRouter(prefix='/api/user')


from pydantic import BaseModel


@app.get('/repositories', response_model=list[Repository])
async def get_user_repositories(
sort: str = 'pushed',
installation_id: int | None = None,
provider_tokens: PROVIDER_TOKEN_TYPE | None = Depends(get_provider_tokens),
access_token: SecretStr | None = Depends(get_access_token),
):

if provider_tokens:
client = ProviderHandler(
provider_tokens=provider_tokens, external_auth_token=access_token
)

try:

repos: list[Repository] = await client.get_repositories(
sort, installation_id
)
Expand Down Expand Up @@ -119,6 +114,8 @@ async def get_github_installation_ids(
content=str(e),
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
elif provider_tokens and ProviderType.GITLAB in provider_tokens:
return [1]

return JSONResponse(
content='GitHub token required.',
Expand All @@ -135,7 +132,6 @@ async def search_repositories(
provider_tokens: PROVIDER_TOKEN_TYPE | None = Depends(get_provider_tokens),
access_token: SecretStr | None = Depends(get_access_token),
):

if provider_tokens:
client = ProviderHandler(
provider_tokens=provider_tokens, external_auth_token=access_token
Expand Down
Loading