Add commented-out GitHub issue creation functionality for test failures

pull/948/head
harshalmore31 3 days ago
parent 46606b487c
commit 3653d1fcbb

@ -37,6 +37,16 @@ load_dotenv()
# --- Constants and Configuration ---
API_KEY = os.getenv("OPENAI_API_KEY")
# GitHub Issue Creation (commented out for later use)
# GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
# GITHUB_REPO_OWNER = os.getenv("GITHUB_REPO_OWNER", "kyegomez")
# GITHUB_REPO_NAME = os.getenv("GITHUB_REPO_NAME", "swarms")
# BASE_URL = "https://api.github.com"
# GITHUB_HEADERS = {
# "Authorization": f"token {GITHUB_TOKEN}",
# "Accept": "application/vnd.github.v3+json",
# }
# --- Helper Functions ---
def generate_timestamp() -> str:
@ -80,6 +90,57 @@ def write_markdown_report(results: List[Dict[str, Any]], filename: str):
f.write(f"**Error:**\n```\n{result['error']}\n```\n\n")
f.write("---\n\n")
# def create_github_issue(test_result: Dict[str, Any]) -> Dict[str, Any]:
# """Create a GitHub issue for a failed test"""
# if not all([GITHUB_TOKEN, GITHUB_REPO_OWNER, GITHUB_REPO_NAME]):
# logger.warning("GitHub credentials not configured. Skipping issue creation.")
# return None
# if test_result["status"] != "failed":
# return None
# issue_title = f"Automated Test Failure: {test_result['test_name']}"
# issue_body = f"""
# ## Test Failure Report
# - **Test Name**: `{test_result['test_name']}`
# - **Timestamp**: `{datetime.now().isoformat()}`
# - **Status**: {test_result['status']}
# ### Error Information
# ```
# {test_result.get('error', 'No error message available')}
# ```
# ### Response (if available)
# ```json
# {json.dumps(test_result.get('response', {}), indent=2)}
# ```
# ---
# *This issue was automatically generated by the Swarms testing workflow.*
# """
# payload = {
# "title": issue_title,
# "body": issue_body,
# "labels": ["bug", "test-failure", "automated-report"],
# }
# try:
# response = requests.post(
# f"{BASE_URL}/repos/{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}/issues",
# headers=GITHUB_HEADERS,
# json=payload,
# )
# response.raise_for_status()
# logger.info(f"Created GitHub issue for {test_result['test_name']}")
# return response.json()
# except requests.exceptions.RequestException as e:
# logger.error(f"Failed to create GitHub issue: {e.response.text if e.response else str(e)}")
# return None
def create_test_agent(name: str, system_prompt: str = None, model_name: str = "gpt-4o-mini", tools: List[Callable] = None, **kwargs) -> Agent:
"""Create a properly configured test agent with error handling"""
try:
@ -581,6 +642,7 @@ def run_all_tests():
"response": "Test execution failed"
}
results.append(error_details)
# create_github_issue(error_details) # Uncomment to enable GitHub issue creation
timestamp = generate_timestamp()
write_markdown_report(results, f"comprehensive_test_report_{timestamp}")

Loading…
Cancel
Save