-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Ye
committed
Jun 5, 2024
1 parent
0e00c52
commit ea71fc5
Showing
3 changed files
with
666 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Python CI All | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
paths: | ||
- 'sweepai/**' | ||
- 'tests/**' | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
paths: | ||
- 'sweepai/**' | ||
- 'tests/**' | ||
|
||
jobs: | ||
code-quality: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.10"] | ||
# python-version: ["3.10", "3.11"] | ||
os: [ubuntu-latest] | ||
# outputs: | ||
# cache-key: ${{ steps.cache-dependencies.outputs.cache-key }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: 1.67.0 | ||
override: true | ||
# - uses: Swatinem/rust-cache@v1 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
# - run: echo "VIRTUAL_ENV=${Python_ROOT_DIR}" >> $GITHUB_ENV | ||
# if: steps.restore-dependencies.outputs.cache-hit != 'true' | ||
- run: | | ||
pip install uv | ||
uv venv | ||
source .venv/bin/activate | ||
echo ".venv/bin" >> $GITHUB_PATH | ||
# if: steps.restore-dependencies.outputs.cache-hit != 'true' | ||
- run: uv pip install -r requirements.txt | ||
# if: steps.restore-dependencies.outputs.cache-hit != 'true' | ||
- run: uv pip install ruff pylint pytest pytest-xdist black | ||
# if: steps.restore-dependencies.outputs.cache-hit != 'true' | ||
- name: Run Review Test | ||
env: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | ||
run: pytest tests/e2e/test_pr_review.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import datetime | ||
import json | ||
import os | ||
import sys | ||
import time | ||
import traceback | ||
|
||
from fastapi.testclient import TestClient | ||
from github import Github | ||
|
||
from sweepai.api import app, global_threads | ||
|
||
GITHUB_PAT = os.environ["GITHUB_PAT"] | ||
print( | ||
f"Using GITHUB_PAT: " | ||
+ GITHUB_PAT[:3] | ||
+ "*" * (len(GITHUB_PAT) - 4) | ||
+ GITHUB_PAT[-1:] | ||
) | ||
g = Github(GITHUB_PAT) | ||
repo_name = "sweepai/e2e" # for e2e test this is hardcoded | ||
repo = g.get_repo(repo_name) | ||
|
||
local_tz = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo | ||
# PR NUMBER is hardcoded for e2e test | ||
pr_number = 1349 | ||
|
||
|
||
def test_e2e_pr_review(): | ||
client = TestClient(app) | ||
try: | ||
issue_json = json.load(open("tests/jsons/e2e_pr_review.json", "r")) | ||
start_time = time.time() | ||
response = client.post( | ||
"/", | ||
json=issue_json, | ||
headers={"X-GitHub-Event": "pull_request"}, | ||
) | ||
print(f"Completed in {time.time() - start_time}s") | ||
assert response | ||
assert response.text | ||
response_text = json.loads(response.text) | ||
assert response.status_code == 200 | ||
assert "success" in response_text | ||
pr = repo.get_pull(pr_number) | ||
# poll github 20 times, waiting 1 minute between each poll, check if the pr has been updated or not | ||
for i in range(20): | ||
pr = repo.get_pull(pr_number) | ||
# iterate through the comments of the pr and check if a new comment got created the title Sweep: PR Review | ||
comments = pr.get_issue_comments() | ||
for comment in comments: | ||
# success if a new pr was made within i+1 minutes ago | ||
if ( | ||
"Sweep: PR Review" in comment.body | ||
): | ||
i = 1 | ||
for thread in global_threads: | ||
thread.join() | ||
print(f"joining thread {i} of {len(global_threads)}") | ||
i += 1 | ||
print(f"PR successfully updated: {pr.title}") | ||
print(f"PR object is: {pr}") | ||
# delete comment for next time around | ||
comment.delete() | ||
return | ||
|
||
time.sleep(60) | ||
raise AssertionError("PR was not updated!") | ||
except AssertionError as e: | ||
for thread in global_threads: | ||
thread.join() | ||
print(f"Assertions failed with error: {e}") | ||
sys.exit(1) | ||
except Exception as e: | ||
for thread in global_threads: | ||
thread.join() | ||
stack_trace = traceback.format_exc() | ||
print(f"Failed with error: {e}\nTraceback: {stack_trace}") | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_e2e_pr_review() |
Oops, something went wrong.