diff --git a/summary.py b/summary.py index f3e25c5..4304454 100644 --- a/summary.py +++ b/summary.py @@ -35,7 +35,9 @@ def get_job_logs(job_id): # Function to analyze logs for meaningful issues def analyze_logs(log_content): issues = [] - + python_version = None + pip_packages = [] + # Improved patterns with context to capture meaningful lines error_patterns = [ re.compile(r'.*error.*', re.IGNORECASE), @@ -44,16 +46,27 @@ def analyze_logs(log_content): re.compile(r'.*exception.*', re.IGNORECASE), re.compile(r'.*critical.*', re.IGNORECASE), ] - + + # Patterns to capture Python version and pip packages + python_version_pattern = re.compile(r'Python \d+\.\d+\.\d+') + pip_list_pattern = re.compile(r'^\s*\S+\s+\S+\s*$') + log_lines = log_content.splitlines() - + for line in log_lines: + if not python_version and python_version_pattern.search(line): + python_version = line.strip() + elif pip_list_pattern.search(line): + pip_packages.append(line.strip()) + for pattern in error_patterns: if pattern.search(line): issues.append(line.strip()) - + # Deduplicate the issues for clarity - return list(set(issues)) + issues = list(set(issues)) + + return issues, python_version, pip_packages # Function to summarize the issues based on the jobs def summarize_issues(jobs): @@ -70,9 +83,11 @@ def summarize_issues(jobs): if job_status != "success": logs = get_job_logs(job_id) if logs: - issues = analyze_logs(logs) + issues, python_version, pip_packages = analyze_logs(logs) summary[job_name] = { "status": job_status, + "python_version": python_version, + "pip_packages": pip_packages, "issues": issues or ["No specific issues found, general failure."] } else: @@ -90,20 +105,28 @@ def summarize_issues(jobs): # Function to generate the summary report def generate_summary_report(summary): report_lines = ["Test Summary Report:\n"] - + for job, details in summary.items(): report_lines.append(f"Job: {job}") report_lines.append(f"Status: {details['status']}") - + + if 'python_version' in details and details['python_version']: + report_lines.append(f"Python Version: {details['python_version']}") + + if 'pip_packages' in details and details['pip_packages']: + report_lines.append("Installed Pip Packages:") + for package in details['pip_packages']: + report_lines.append(f"- {package}") + if details['status'] != "success": report_lines.append("Issues Found:") for issue in details['issues']: report_lines.append(f"- {issue}") else: report_lines.append(details['issues'][0]) - + report_lines.append("\n" + "-"*40 + "\n") - + return "\n".join(report_lines) # Main execution @@ -114,10 +137,10 @@ def generate_summary_report(summary): else: summary = summarize_issues(jobs) report = generate_summary_report(summary) - + # Save the report to a file with open("summary_report.txt", "w") as report_file: report_file.write(report) - + # Print the report to the console print(report)