GithubHelp home page GithubHelp logo

Comments (1)

sweep-ai avatar sweep-ai commented on July 24, 2024

🚀 Here's the PR! #2

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: 3cadbf7537)

Tip

I can email you next time I complete a pull request if you set up your email here!


Actions (click)

  • ↻ Restart Sweep

Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.

sweep-learn/sweepai/api.py

Lines 422 to 502 in cbbf580

def handle_event(request_dict, event):
action = request_dict.get("action")
if repo_full_name := request_dict.get("repository", {}).get("full_name"):
if repo_full_name in DISABLED_REPOS:
logger.warning(f"Repo {repo_full_name} is disabled")
return {"success": False, "error_message": "Repo is disabled"}
with logger.contextualize(tracking_id="main", env=ENV):
match event, action:
case "check_run", "completed":
request = CheckRunCompleted(**request_dict)
_, g = get_github_client(request.installation.id)
repo = g.get_repo(request.repository.full_name)
pull_requests = request.check_run.pull_requests
if pull_requests:
logger.info(pull_requests[0].number)
pr = repo.get_pull(pull_requests[0].number)
if (time.time() - pr.created_at.timestamp()) > 60 * 60 and (
pr.title.startswith("[Sweep Rules]")
or pr.title.startswith("[Sweep GHA Fix]")
):
after_sha = pr.head.sha
commit = repo.get_commit(after_sha)
check_suites = commit.get_check_suites()
for check_suite in check_suites:
if check_suite.conclusion == "failure":
pr.edit(state="closed")
break
if (
not (time.time() - pr.created_at.timestamp()) > 60 * 15
and request.check_run.conclusion == "failure"
and pr.state == "open"
and get_gha_enabled(repo)
and len(
[
comment
for comment in pr.get_issue_comments()
if "Fixing PR" in comment.body
]
)
< 2
and GHA_AUTOFIX_ENABLED
):
# check if the base branch is passing
commits = repo.get_commits(sha=pr.base.ref)
latest_commit: Commit = commits[0]
if all(
status != "failure"
for status in [
status.state for status in latest_commit.get_statuses()
]
): # base branch is passing
logs = download_logs(
request.repository.full_name,
request.check_run.run_id,
request.installation.id,
)
logs, user_message = clean_gh_logs(logs)
attributor = request.sender.login
if attributor.endswith("[bot]"):
attributor = commit.author.login
if attributor.endswith("[bot]"):
attributor = pr.assignee.login
if attributor.endswith("[bot]"):
return {
"success": False,
"error_message": "The PR was created by a bot, so I won't attempt to fix it.",
}
tracking_id = get_hash()
chat_logger = ChatLogger(
data={
"username": attributor,
"title": "[Sweep GHA Fix] Fix the failing GitHub Actions",
}
)
if chat_logger.use_faster_model() and not IS_SELF_HOSTED:
return {
"success": False,
"error_message": "Disabled for free users",


Step 2: ⌨️ Coding

Create sweepai/tests/api_test.py with contents:
• Create a new file "api_test.py" under the "sweepai/tests" directory. This directory may need to be created if it does not already exist, adhering to Python's standard project structure for unit tests.
• Begin by importing necessary testing libraries such as `unittest` and `unittest.mock` for creating mock objects and assertions.
• Import the `handle_event` function from `../api.py` to be tested.
• Create a class `TestHandleEvent` that inherits from `unittest.TestCase`.
• Within `TestHandleEvent`, write multiple test methods to cover various scenarios for the `handle_event` function. Each method should setup necessary mock objects for `request_dict`, `event`, and any external dependencies like the GitHub client. Use `unittest.mock.patch` to mock external calls, such as those to the GitHub API.
• Test scenarios should include: - Handling of disabled repositories. - Different combinations of `event` and `action` values. - Pull requests that are too old or have specific titles. - Successful handling of pull requests based on GitHub API interactions. - Error cases, such as when the GitHub API fails or returns unexpected results.
• For each test case, assert the expected outcome from calling `handle_event` with the mocked parameters and dependencies.
  • Running GitHub Actions for sweepai/tests/api_test.pyEdit
Check sweepai/tests/api_test.py with contents:

Ran GitHub Actions for b92f5c2dcbf9246ea6675bc4e5e2a84e399c6201:

  • Modify sweepai/api.py ! No changes made Edit
Modify sweepai/api.py with contents:
• No modifications are specified for "api.py" as the creation of unit tests should not require changes to the business logic. However, if during the implementation of tests it's discovered that the code is not easily testable (e.g., due to hard-coded dependencies), minor refactoring may be needed to improve testability, such as abstracting external dependencies or parameterizing certain function inputs.
  • Running GitHub Actions for sweepai/api.pyEdit
Check sweepai/api.py with contents:

Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/create_unit_test_for_handle_event_of_apy.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description.
Something wrong? Let us know.

This is an automated message generated by Sweep AI.

from sweep-learn.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.