Skip to content

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 opening PR from fork (#229)

Kilian Lieretd54d5ac99623
diff --git a/run.py b/run.py
index 92809de6..ee8cf857 100644
--- a/run.py
+++ b/run.py
@@ -51,7 +51,7 @@ class ActionsArguments(FlattenedAccess, FrozenSerializable):
# to fix the issue. Please only set this to False if you are sure the commits are
# not fixes or if this is your own repository!
skip_if_commits_reference_issue: bool = True
- # OBSOLETE. Do not use, will raise error.
+ # OBSOLETE. Do not use, will raise error. Please specify --repo_path instead.
push_gh_repo_url: str = ""
def __post_init__(self):
@@ -149,7 +149,7 @@ def main(args: ScriptArguments):
save_predictions(traj_dir, instance_id, info)
patch_path = save_patch(traj_dir, instance_id, info)
if args.actions.open_pr and should_open_pr(args, info, token=env._github_token):
- env.open_pr(trajectory=trajectory, push_gh_repo_url=args.actions.push_gh_repo_url)
+ env.open_pr(trajectory=trajectory)
if args.actions.apply_patch_locally and patch_path is not None and env.record["repo_type"] == "local":
apply_patch(Path(args.environment.repo_path), patch_file=patch_path)
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index cb39c463..401369ac 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -25,8 +25,6 @@ from sweagent.environment.utils import (
get_container,
get_gh_issue_data,
get_instances,
- parse_gh_issue_url,
- parse_gh_repo_url,
read_with_timeout,
LOGGER_NAME,
)
@@ -769,12 +767,11 @@ class SWEEnv(gym.Env):
raise RuntimeError("Failed to interrupt container")
- def open_pr(self, *, trajectory, push_gh_repo_url: Optional[str] = None, _dry_run: bool=False):
+ def open_pr(self, *, trajectory, _dry_run: bool=False):
"""Create PR to repository
Args:
trajectory: Trajectory of actions taken by the agent
- push_gh_repo_url: URL of the repository to push the PR branch to
_dry_run: Whether to actually push anything or just simulate it
"""
logger.info("Opening PR")
@@ -808,21 +805,8 @@ class SWEEnv(gym.Env):
# If users want to push to a fork, we add a new remote and push to that
# otherwise, we push to 'origin' which has already been set up
remote = "origin"
- if not push_gh_repo_url:
- owner, repo, _ = parse_gh_issue_url(issue_url)
- else:
- owner, repo = parse_gh_repo_url(push_gh_repo_url)
- if push_gh_repo_url:
- token_prefix = ""
- if self._github_token:
- token_prefix = f"{self._github_token}@"
- fork_url = f"https://{token_prefix}github.com/{owner}/{repo}.git"
- self.communicate_with_handling(
- input=f"git remote add fork {fork_url}",
- error_msg="Failed to create new git remote",
- timeout_duration=10,
- )
- remote = "fork"
+ assert self.record is not None # mypy
+ owner, repo = self.record["repo"].split("/")
dry_run_prefix = "echo " if _dry_run else ""
self.communicate_with_handling(
input=f"{dry_run_prefix} git push {remote} {branch_name}",