Coverage for / opt / hostedtoolcache / Python / 3.11.14 / x64 / lib / python3.11 / site-packages / rattlesnake / cicd / reports_main_page.py: 97%
37 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-27 18:22 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-27 18:22 +0000
1"""
2Generates the main landing page for the code quality reports.
3"""
5import argparse
6import sys
7from typing import Final
9from rattlesnake.cicd.utilities import get_timestamp
11HTML_TEMPLATE: Final[str] = """
12<!DOCTYPE html>
13<html lang="en">
14<head>
15 <meta charset="UTF-8">
16 <meta name="viewport" content="width=device-width, initial-scale=1.0">
17 <title>Rattlesnake Code Quality Reports</title>
18 <style>
19 body {{
20 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
21 margin: 0; padding: 20px; background: #f6f8fa;
22 }}
23 .container {{
24 max-width: 800px; margin: 0 auto;
25 }}
26 .header {{
27 background: white; padding: 30px; border-radius: 8px;
28 box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 30px; text-align: center;
29 }}
30 .report-card {{
31 background: white; padding: 20px; border-radius: 8px;
32 box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 20px;
33 }}
34 .report-card h3 {{
35 margin-top: 0; color: #0366d6;
36 }}
37 .report-link {{
38 background: #0366d6; color: white; padding: 10px 20px;
39 text-decoration: none; border-radius: 6px; display: inline-block;
40 }}
41 .report-link:hover {{
42 background: #0256cc;
43 }}
44 .badge {{
45 margin: 10px 5px;
46 }}
47 </style>
48</head>
49<body>
50 <div class="container">
51 <div class="header">
52 <h1>Rattlesnake Code Quality</h1>
53 <!--
54 <p>Automated code quality analysis for the Rattlesnake vibration controller</p>
55 <div class="badge">
56 <img src="https://github.com/{github_repo}/raw/dev/badges/pylint.svg" alt="Pylint Score">
57 </div>
58 <div class="badge">
59 <img src="https://github.com/{github_repo}/raw/dev/badges/coverage.svg" alt="Coverage">
60 </div>
61 -->
62 </div>
64 <div class="report-card">
65 <h3>📊 Pylint Report</h3>
66 <p>Static code analysis results showing code quality metrics, style compliance, and potential issues.</p>
67 <p><strong>Latest Score:</strong> {pylint_score}/10</p>
68 <p><strong>Last Updated:</strong> {formatted_time}</p>
69 <a href="./reports/pylint/" class="report-link">Pylint Report</a>
70 </div>
72 <div class="report-card">
73 <h3>🔗 Quick Links</h3>
74 <p>
75 <a href="https://github.com/{github_repo}" class="report-link">GitHub Repository</a>
76 <a href="https://github.com/{github_repo}/actions" class="report-link">GitHub Actions</a>
77 <a href="https://github.com/{github_repo}/releases" class="report-link">Releases</a>
78 </p>
79 </div>
80 </div>
81</body>
82</html>
83"""
86def get_report_html(github_repo: str, pylint_score: str) -> str:
87 """Generates the HTML for the reports landing page.
89 Args:
90 github_repo: The name of the GitHub repository (e.g., 'user/repo').
91 pylint_score: The pylint score.
93 Returns:
94 The generated HTML content as a string.
95 """
96 formatted_time: str = get_timestamp()
98 return HTML_TEMPLATE.format(
99 github_repo=github_repo,
100 pylint_score=pylint_score,
101 formatted_time=formatted_time,
102 )
105def write_report(html_content: str, output_file: str) -> None:
106 """
107 Write HTML content to file.
109 Args:
110 html_content: The HTML content to write
111 output_file: Path for the output HTML file
113 Raises:
114 IOError: If the file cannot be written.
115 """
116 try:
117 with open(output_file, "w", encoding="utf-8") as f:
118 f.write(html_content)
119 except IOError as e:
120 raise IOError(f'Error writing output file "{output_file}": {e}') from e
123def run_reports_main_page(
124 github_repo: str, pylint_score: str, output_file: str
125) -> None:
126 """
127 Main function to create HTML report.
129 Args:
130 github_repo: The name of the GitHub repository (e.g., 'user/repo').
131 pylint_score: The pylint score.
132 output_file: Path for the generated HTML report
133 """
134 html_content: str = get_report_html(
135 github_repo=github_repo, pylint_score=pylint_score
136 )
137 write_report(html_content, output_file)
140def parse_arguments() -> argparse.Namespace:
141 """
142 Parse command line arguments.
144 Returns:
145 Parsed arguments namespace
146 """
147 parser = argparse.ArgumentParser(description="Generate the main reports page.")
148 parser.add_argument(
149 "--github_repo",
150 type=str,
151 required=True,
152 help="The GitHub repository in the format 'owner/repo-name'.",
153 )
154 parser.add_argument(
155 "--pylint_score",
156 type=str,
157 required=True,
158 help="The Pylint score.",
159 )
160 parser.add_argument(
161 "--output_file",
162 type=str,
163 required=True,
164 help="The path to the output HTML file.",
165 )
166 return parser.parse_args()
169def main() -> int:
170 """
171 Main entry point for the script.
173 Returns:
174 Exit code (0 for success, 1 for failure)
175 """
176 args: argparse.Namespace = parse_arguments()
177 try:
178 run_reports_main_page(
179 github_repo=args.github_repo,
180 pylint_score=args.pylint_score,
181 output_file=args.output_file,
182 )
183 print(f"✅ GitHub Pages reports main page generated: {args.output_file}")
184 except IOError as e:
185 print(f"❌ I/O error occurred: {e}", file=sys.stderr)
186 return 1
187 except Exception as e:
188 print(f"❌ An unexpected error occurred: {e}", file=sys.stderr)
189 return 1
190 return 0
193if __name__ == "__main__":
194 sys.exit(main())