You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/tests/test_upload_tests_to_issues.py

65 lines
1.6 KiB

1 year ago
import os
import subprocess
11 months ago
1 year ago
import requests
from dotenv import load_dotenv
load_dotenv
# Constants
1 year ago
GITHUB_USERNAME = os.getenv("GITHUB_USERNAME")
REPO_NAME = os.getenv("GITHUB_REPO_NAME")
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
9 months ago
ISSUES_URL = (
f"https://api.github.com/repos/{GITHUB_USERNAME}/{REPO_NAME}/issues"
)
1 year ago
# Headers for authentication
headers = {
1 year ago
"Authorization": f"token {GITHUB_TOKEN}",
"Accept": "application/vnd.github.v3+json",
1 year ago
}
1 year ago
1 year ago
def run_pytest():
9 months ago
result = subprocess.run(["pytest"], capture_output=True, text=True)
1 year ago
return result.stdout + result.stderr
1 year ago
1 year ago
def parse_pytest_output(output):
errors = []
current_error = None
1 year ago
for line in output.split("\n"):
if line.startswith("_________________________"):
1 year ago
if current_error:
errors.append(current_error)
1 year ago
current_error = {"title": "", "body": ""}
1 year ago
elif current_error is not None:
1 year ago
if not current_error["title"]:
current_error["title"] = line.strip()
current_error["body"] += line + "\n"
1 year ago
if current_error:
errors.append(current_error)
return errors
1 year ago
1 year ago
def create_github_issue(title, body):
1 year ago
issue = {"title": title, "body": body}
1 year ago
response = requests.post(ISSUES_URL, headers=headers, json=issue)
return response.json()
1 year ago
1 year ago
def main():
pytest_output = run_pytest()
errors = parse_pytest_output(pytest_output)
1 year ago
1 year ago
for error in errors:
9 months ago
issue_response = create_github_issue(error["title"], error["body"])
1 year ago
print(f"Issue created: {issue_response.get('html_url')}")
1 year ago
if __name__ == "__main__":
1 year ago
main()