Repository: All-Hands-AI/OpenHands
File: openhands/integrations/github/github_service.py (Python)

Code before:
            try:
                user_response, _ = await self._make_request(url, user_params)
                user_items = user_response.get('items', [])
                all_repos.extend(user_items)
                logger.info(f'Found {len(user_items)} repos in user search')
            except Exception as e:
                logger.warning(f'User search failed: {e}')
            
            # Search in each organization
            for org in user_orgs:
                org_query = f'{query} org:{org}'
                org_params = params.copy()
                org_params['q'] = org_query
                logger.info(f'Searching org {org} with query: {org_query}')
                
                try:
                    org_response, _ = await self._make_request(url, org_params)
                    org_items = org_response.get('items', [])
                    all_repos.extend(org_items)
                    logger.info(f'Found {len(org_items)} repos in org {org} search')
                except Exception as e:
                    logger.warning(f'Org {org} search failed: {e}')
            
            # Remove duplicates and return
            seen_ids = set()
            unique_repos = []
            for repo in all_repos:
                if repo['id'] not in seen_ids:
                    seen_ids.add(repo['id'])
                    unique_repos.append(repo)
            
            logger.info(f'Total unique repos found: {len(unique_repos)}')
            return [self._parse_repository(repo) for repo in unique_repos]

        # Default case (public search or slash query)
        response, _ = await self._make_request(url, params)
        repo_items = response.get('items', [])
        logger.info(f'GitHub search returned {len(repo_items)} repositories')
        if repo_items:
            logger.info(f'First few repos: {[item.get("full_name") for item in repo_items[:3]]}')
        repos = [self._parse_repository(repo) for repo in repo_items]

        return repos

    async def execute_graphql_query(
        self, query: str, variables: dict[str, Any]
    ) -> dict[str, Any]:
        """Execute a GraphQL query against the GitHub API."""
        try:
            async with httpx.AsyncClient() as client:
                github_headers = await self._get_github_headers()

Review comment (suggestion):
Nice! We should also filter against the org name

So if we have a partial match on the org name, get the first 2 repos inside the org


Currently if I type `All-Hands` it will search for the repo `All-Hands` under every org, whereas we could try matching against `All-Hands` org as well and list a couple of repos from there

Code after:
        if not public and '/' in query:
            org, repo_query = query.split('/', 1)
            query_with_user = f'org:{org} in:name {repo_query}'
            params['q'] = query_with_user
        elif not public:
            # Expand search scope to include user's repositories and organizations they're a member of
            user = await self.get_user()
            user_orgs = await self.get_user_organizations()

            # Search in user repos and org repos separately
            all_repos = []

            # Search in user repositories
            user_query = f'{query} user:{user.login}'
            user_params = params.copy()
            user_params['q'] = user_query

            try:
                user_response, _ = await self._make_request(url, user_params)
                user_items = user_response.get('items', [])
                all_repos.extend(user_items)
            except Exception as e:
                logger.warning(f'User search failed: {e}')

            # Search for repos named "query" in each organization
            for org in user_orgs:
                org_query = f'{query} org:{org}'
                org_params = params.copy()
                org_params['q'] = org_query

                try:
                    org_response, _ = await self._make_request(url, org_params)
                    org_items = org_response.get('items', [])
                    all_repos.extend(org_items)
                except Exception as e:
                    logger.warning(f'Org {org} search failed: {e}')

            # Also search for top repos from orgs that match the query name
            for org in user_orgs:
                if self._fuzzy_match_org_name(query, org):
                    org_repos_query = f'org:{org}'
                    org_repos_params = params.copy()
                    org_repos_params['q'] = org_repos_query
                    org_repos_params['sort'] = 'stars'
                    org_repos_params['per_page'] = 2  # Limit to first 2 repos

                    try:
                        org_repos_response, _ = await self._make_request(
                            url, org_repos_params
                        )
                        org_repo_items = org_repos_response.get('items', [])