π OpenHands: AI-Driven Development
[Fix]: Sort github repos in memory for cloud openhands (#8083)
Rohit Malhotrac25a96825ca5
diff --git a/openhands/integrations/github/github_service.py b/openhands/integrations/github/github_service.pyindex c6944a09a5..f222b7021e 100644--- a/openhands/integrations/github/github_service.py+++ b/openhands/integrations/github/github_service.py@@ -18,6 +18,8 @@ from openhands.integrations.service_types import ()from openhands.server.types import AppModefrom openhands.utils.import_utils import get_impl+from datetime import datetime+class GitHubService(BaseGitService, GitService):@@ -157,6 +159,13 @@ class GitHubService(BaseGitService, GitService):return repos[:max_repos] # Trim to max_repos if needed++ def parse_pushed_at_date(self, repo):+ ts = repo.get("pushed_at")+ return datetime.strptime(ts, "%Y-%m-%dT%H:%M:%SZ") if ts else datetime.min+++async def get_repositories(self, sort: str, app_mode: AppMode) -> list[Repository]:MAX_REPOS = 1000PER_PAGE = 100 # Maximum allowed by GitHub API@@ -183,6 +192,11 @@ class GitHubService(BaseGitService, GitService):# If we've already reached MAX_REPOS, no need to check other installationsif len(all_repos) >= MAX_REPOS:break++ if sort == "pushed":+ all_repos.sort(+ key=self.parse_pushed_at_date, reverse=True+ )else:# Original behavior for non-SaaS modeparams = {'per_page': str(PER_PAGE), 'sort': sort}@@ -191,6 +205,7 @@ class GitHubService(BaseGitService, GitService):# Fetch user repositoriesall_repos = await self._fetch_paginated_repos(url, params, MAX_REPOS)+# Convert to Repository objectsreturn [Repository(