Skip to content

Commit

Permalink
feat: Updated 2 files
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-nightly[bot] authored Apr 6, 2024
1 parent 776a66f commit 55fe959
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
15 changes: 6 additions & 9 deletions sweepai/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from fastapi.responses import HTMLResponse
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from fastapi.templating import Jinja2Templates
from github import GithubException
from github.Commit import Commit
from prometheus_fastapi_instrumentator import Instrumentator

Expand Down Expand Up @@ -76,7 +75,7 @@
)
from sweepai.utils.chat_logger import ChatLogger
from sweepai.utils.event_logger import logger, posthog
from sweepai.utils.github_utils import CURRENT_USERNAME, get_github_client
from sweepai.utils.github_utils import CURRENT_USERNAME, get_github_client, rebase_feature_branch
from sweepai.utils.progress import TicketProgress
from sweepai.utils.safe_pqueue import SafePriorityQueue
from sweepai.utils.str_utils import BOT_SUFFIX, get_hash
Expand Down Expand Up @@ -404,13 +403,11 @@ def update_sweep_prs_v2(repo_full_name: str, installation_id: int):
continue

try:
repo.rebase(pr.base.ref, feature_branch)
except GithubException as e:
if e.status == 409: # Merge conflict
pr.edit(state="closed")
continue
else:
raise
rebase_feature_branch(repo, feature_branch, pr.base.ref, token)
except Exception as e:
logger.warning(f"Failed to rebase feature branch for PR #{pr.number}: {e}")
pr.edit(state="closed")
continue

# Check if the merged PR is the config PR
if pr.title == "Configure Sweep" and pr.merged:
Expand Down
12 changes: 12 additions & 0 deletions sweepai/utils/github_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,18 @@ def update_file(root_dir: str, file_path: str, new_contents: str):
logger.error(f"Failed to update file: {e}")
return False

def rebase_feature_branch(repo, feature_branch, base_branch, token):
clone_url = repo.clone_url.replace("https://", f"https://{token}@")

with tempfile.TemporaryDirectory() as temp_dir:
cloned_repo = git.Repo.clone_from(clone_url, temp_dir)

cloned_repo.git.checkout(feature_branch)
cloned_repo.git.rebase(base_branch)

cloned_repo.git.push("origin", feature_branch, force=True)


@dataclass
class MockClonedRepo(ClonedRepo):
_repo_dir: str = ""
Expand Down

0 comments on commit 55fe959

Please sign in to comment.