sweepai / sweep

Sweep: open-source AI-powered Software Developer for small features and bug fixes.
https://sweep.dev
Other
7.36k stars 421 forks source link

Sweep: refactor edit_sweep_comment in on_ticket.py to not use nonlocals. put all of these in the function call, and add each argument accordingly #3672

Open wwzeng1 opened 3 months ago

wwzeng1 commented 3 months ago

Branch

No response

sweep-nightly[bot] commented 3 months ago

🚀 Here's the PR! #4026

💎 Sweep Pro: You have unlimited Sweep issues

Actions

Step 1: 🔎 Searching

(Click to expand) Here are the code search results. I'm now analyzing these search results to write the PR. https://github.com/sweepai/sweep/blob/6dc168915b69e15f8bbed64f84452d2c4fa7f23e/sweepai/handlers/on_ticket.py#L1-L734 https://github.com/sweepai/sweep/blob/6dc168915b69e15f8bbed64f84452d2c4fa7f23e/sweepai/utils/ticket_rendering_utils.py#L1-L812 https://github.com/sweepai/sweep/blob/6dc168915b69e15f8bbed64f84452d2c4fa7f23e/sweepai/api.py#L1-L875 https://github.com/sweepai/sweep/blob/6dc168915b69e15f8bbed64f84452d2c4fa7f23e/sweepai/handlers/on_comment.py#L1-L406

Step 2: ⌨️ Coding

I'm going to follow the following steps to help you solve the GitHub issue:

  1. Remove the nonlocal statements from the edit_sweep_comment function in on_ticket.py.
  2. Add parameters to the edit_sweep_comment function for each of the variables that were previously accessed via nonlocal.
  3. Update all calls to edit_sweep_comment in on_ticket.py to pass the required arguments.

Here are the changes we decided to make. I'm done making edits and now I'm just validating the changes using a linter to catch any mistakes like syntax errors or undefined variables:

sweepai/handlers/on_ticket.py

1. Remove the `nonlocal` statement from the `edit_sweep_comment` function. 2. Add parameters to the `edit_sweep_comment` function for each of the variables that were previously accessed via `nonlocal`. 3. Update all calls to `edit_sweep_comment` to pass the required arguments.
--- 
+++ 
@@ -1,12 +1,18 @@
             def edit_sweep_comment(
                 message: str,
                 index: int,
+                current_index: int,
+                user_token: str,
+                g: Github,
+                repo: Repository,
+                issue_comment: IssueComment,
+                initial_sandbox_response: int,
+                initial_sandbox_response_file: str,
                 pr_message="",
                 done=False,
                 step_complete=True,
                 add_bonus_message=True,
             ):
-                nonlocal current_index, user_token, g, repo, issue_comment, initial_sandbox_response, initial_sandbox_response_file
                 message = sanitize_string_for_github(message)
                 if pr_message:
                     pr_message = sanitize_string_for_github(pr_message)

sweepai/handlers/on_ticket.py

Update the first call to `edit_sweep_comment` to pass the required arguments.
--- 
+++ 
@@ -1,4 +1,11 @@
             edit_sweep_comment(
                 "I've just finished validating the issue. I'm now going to start searching for relevant files.",
-                0
+                0,
+                current_index,
+                user_token,
+                g,
+                repo,
+                issue_comment,
+                initial_sandbox_response,
+                initial_sandbox_response_file
             )

sweepai/handlers/on_ticket.py

Update the second call to `edit_sweep_comment` to pass the required arguments.
--- 
+++ 
@@ -17,5 +17,12 @@
                                 else ""
                             ),
                             1,
+                            current_index,
+                            user_token,
+                            g,
+                            repo,
+                            issue_comment,
+                            initial_sandbox_response,
+                            initial_sandbox_response_file,
                             step_complete=False
                         )

sweepai/handlers/on_ticket.py

Update the third call to `edit_sweep_comment` to pass the required arguments.
--- 
+++ 
@@ -17,4 +17,11 @@
                         else ""
                     ),
                     1,
+                    current_index,
+                    user_token,
+                    g,
+                    repo,
+                    issue_comment,
+                    initial_sandbox_response,
+                    initial_sandbox_response_file
                 )

sweepai/handlers/on_ticket.py

Update the fourth call to `edit_sweep_comment` to pass the required arguments.
--- 
+++ 
@@ -1,4 +1,11 @@
                 edit_sweep_comment(
                     "I'm currently validating your changes using parsers and linters to check for mistakes like syntax errors or undefined variables. If I see any of these errors, I will automatically fix them.",
                     3,
+                    current_index,
+                    user_token,
+                    g,
+                    repo,
+                    issue_comment,
+                    initial_sandbox_response,
+                    initial_sandbox_response_file
                 )

sweepai/handlers/on_ticket.py

Update the fifth call to `edit_sweep_comment` to pass the required arguments.
--- 
+++ 
@@ -1,4 +1,11 @@
                 edit_sweep_comment(
                     f"Your changes have been successfully made to the branch [`{pull_request.branch_name}`](https://github.com/{repo_full_name}/tree/{pull_request.branch_name}). I have validated these changes using a syntax checker and a linter.",
                     3,
+                    current_index,
+                    user_token,
+                    g,
+                    repo,
+                    issue_comment,
+                    initial_sandbox_response,
+                    initial_sandbox_response_file
                 )

Step 3: 🔄️ Validating

Your changes have been successfully made to the branch sweep/refactor_edit_sweep_comment_in_on_ticket_8cd5b. I have validated these changes using a syntax checker and a linter.


[!TIP] To recreate the pull request, edit the issue title or description.

This is an automated message generated by Sweep AI.