def initialize_repository_for_runtime(
    runtime: Runtime, selected_repository: str | None = None
) -> str | None:
    """Initialize the repository for the runtime.

    Args:
        runtime: The runtime to initialize the repository for.
        selected_repository: (optional) The GitHub repository to use.

    Returns:
        The repository directory path if a repository was cloned, None otherwise.
    """
    # clone selected repository if provided
    provider_tokens = {}
    if 'GITHUB_TOKEN' in os.environ:
        github_token = SecretStr(os.environ['GITHUB_TOKEN'])
        provider_tokens[ProviderType.GITHUB] = ProviderToken(token=github_token)

    if 'GITLAB_TOKEN' in os.environ:
        gitlab_token = SecretStr(os.environ['GITLAB_TOKEN'])
        provider_tokens[ProviderType.GITLAB] = ProviderToken(token=gitlab_token)

    secret_store = (
        UserSecrets(provider_tokens=provider_tokens) if provider_tokens else None
    )
    immutable_provider_tokens = secret_store.provider_tokens if secret_store else None

    logger.debug(f'Selected repository {selected_repository}.')
    repo_directory = call_async_from_sync(
        runtime.clone_or_init_repo,
        GENERAL_TIMEOUT,
        immutable_provider_tokens,
        selected_repository,
        None,
    )
    # Run setup script if it exists
    runtime.maybe_run_setup_script()
    # Set up git hooks if pre-commit.sh exists
    runtime.maybe_setup_git_hooks()

    return repo_directory
Initialize the repository for the runtime.

    Args:
        runtime: The runtime to initialize the repository for.
        selected_repository: (optional) The GitHub repository to use.

    Returns:
        The repository directory path if a repository was cloned, None otherwise.
    
openhands/core/setup.py