SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Fix batch repo names containing github (#1406)
Yijin Zhou5eb4100df5fd
diff --git a/sweagent/run/batch_instances.py b/sweagent/run/batch_instances.pyindex 7b996bed..db041703 100644--- a/sweagent/run/batch_instances.py+++ b/sweagent/run/batch_instances.py@@ -23,7 +23,7 @@ from sweagent.agent.problem_statement import (from sweagent.environment.repo import GithubRepoConfig, LocalRepoConfig, PreExistingRepoConfig, SWESmithRepoConfigfrom sweagent.environment.swe_env import EnvironmentConfigfrom sweagent.utils.files import load_file-from sweagent.utils.github import _is_repo_private+from sweagent.utils.github import _is_github_repo_url, _is_repo_privatefrom sweagent.utils.log import get_loggerlogger = get_logger("swea-config", emoji="🔧")@@ -98,7 +98,7 @@ class SimpleBatchInstance(BaseModel):repo_name: str = """""Specifies the repository to use. If empty, no repository is used.If the string does not contain a slash, it is interpreted as an already existing repository at the root- of the docker container. If it contains the word "github", it is interpreted as a github repository.+ of the docker container. If it is a GitHub URL, it is interpreted as a github repository.Else, it is interpreted as a local repository."""base_commit: str = "HEAD"@@ -130,7 +130,7 @@ class SimpleBatchInstance(BaseModel):if not self.repo_name:repo = None- elif "github" in self.repo_name:+ elif _is_github_repo_url(self.repo_name):repo = GithubRepoConfig(github_url=self.repo_name, base_commit=self.base_commit)elif "/" not in self.repo_name:repo = PreExistingRepoConfig(repo_name=self.repo_name, base_commit=self.base_commit)diff --git a/tests/test_batch_instance.py b/tests/test_batch_instance.pyindex 540befb9..8ce2a291 100644--- a/tests/test_batch_instance.py+++ b/tests/test_batch_instance.py@@ -4,7 +4,7 @@ import pytestfrom swerex.deployment.config import DockerDeploymentConfigfrom sweagent.agent.problem_statement import TextProblemStatement-from sweagent.environment.repo import PreExistingRepoConfig+from sweagent.environment.repo import GithubRepoConfig, PreExistingRepoConfigfrom sweagent.run.batch_instances import BatchInstance, SimpleBatchInstance, SWEBenchInstances, _slice_spec_to_slice@@ -22,6 +22,31 @@ def test_simple_batch_from_swe_bench_to_full_batch_instance(test_data_sources_paassert instance.problem_statement.id == "pydicom__pydicom-1458"[email protected]("repo_name", ["go-github", "github", "github-action-build-chain"])+def test_simple_batch_treats_repo_names_containing_github_as_existing_repos(repo_name):+ instance = SimpleBatchInstance(+ image_name="python:3.11",+ problem_statement="Fix the bug",+ instance_id="repo-name-with-github",+ repo_name=repo_name,+ ).to_full_batch_instance(DockerDeploymentConfig(image="python:3.11"))++ assert isinstance(instance.env.repo, PreExistingRepoConfig)+ assert instance.env.repo.repo_name == repo_name+++def test_simple_batch_treats_github_urls_as_github_repos():+ instance = SimpleBatchInstance(+ image_name="python:3.11",+ problem_statement="Fix the bug",+ instance_id="github-url",+ repo_name="https://github.com/SWE-agent/test-repo",+ ).to_full_batch_instance(DockerDeploymentConfig(image="python:3.11"))++ assert isinstance(instance.env.repo, GithubRepoConfig)+ assert instance.env.repo.github_url == "https://github.com/SWE-agent/test-repo"++def test_slice_spec_to_slice():assert _slice_spec_to_slice("10") == slice(10)assert _slice_spec_to_slice("10:20") == slice(10, 20)