-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdiff_146.patch
More file actions
69 lines (65 loc) · 4.68 KB
/
Copy pathdiff_146.patch
File metadata and controls
69 lines (65 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
diff --git a/models/feedback_handler.py b/models/feedback_handler.py
index 50b7ea0..ef543c7 100644
--- a/models/feedback_handler.py
+++ b/models/feedback_handler.py
@@ -28,6 +28,17 @@
_logger = logging.getLogger(__name__)
+def _format_rating_stars(value: Any) -> str:
+ """Return a safe star rating string for feedback exports."""
+ if value is None or isinstance(value, bool):
+ return ""
+ try:
+ rating = int(float(value))
+ except (TypeError, ValueError):
+ return ""
+ return "Γ¡É" * max(rating, 0)
+
+
def _open_connection(db_path: str) -> sqlite3.Connection:
"""Create a brand-new SQLite connection with WAL mode and busy timeout."""
conn = sqlite3.connect(db_path, check_same_thread=False)
@@ -190,7 +201,7 @@ def export_to_github_issue(self, feedback_id: int) -> str:
## User Feedback
**Type:** {feedback.get("feedback_type", "Not specified")}
-**Rating:** {"Γ¡É" * feedback.get("rating", 0)}
+**Rating:** {_format_rating_stars(feedback.get("rating"))}
**Date:** {feedback.get("timestamp", "Not recorded")}
### Message:
diff --git a/tests/test_feedback_issue_export.py b/tests/test_feedback_issue_export.py
new file mode 100644
index 0000000..87ae9d0
--- /dev/null
+++ b/tests/test_feedback_issue_export.py
@@ -0,0 +1,32 @@
+"""Tests for feedback-to-issue markdown export."""
+
+from models.feedback_handler import FeedbackHandler, _format_rating_stars
+
+
+def test_format_rating_stars_accepts_numeric_strings():
+ assert _format_rating_stars("4") == "Γ¡ÉΓ¡ÉΓ¡ÉΓ¡É"
+ assert _format_rating_stars(2.8) == "Γ¡ÉΓ¡É"
+
+
+def test_format_rating_stars_ignores_invalid_values():
+ assert _format_rating_stars("bad") == ""
+ assert _format_rating_stars(None) == ""
+ assert _format_rating_stars(True) == ""
+
+
+def test_export_to_github_issue_handles_string_rating(tmp_path):
+ handler = FeedbackHandler(str(tmp_path / "feedback.json"))
+ assert handler.save_feedback(
+ {
+ "feedback_type": "bug",
+ "rating": "5",
+ "message": "Incorrect classification",
+ "email": "user@example.com",
+ }
+ )
+
+ body = handler.export_to_github_issue(0)
+
+ assert "**Rating:** Γ¡ÉΓ¡ÉΓ¡ÉΓ¡ÉΓ¡É" in body
+ assert "Incorrect classification" in body
+ assert "user@example.com" in body