summary refs log tree commit diff stats
path: root/gitlab/description_parser.py
diff options
context:
space:
mode:
authorChristian Krinitsin <mail@krinitsin.com>2025-05-18 16:17:59 +0200
committerChristian Krinitsin <mail@krinitsin.com>2025-05-18 16:17:59 +0200
commita9eb56beab0a66199b6fc7844132d28ba81174fa (patch)
treec918fe98b6fe49c20956646efa052fe7fb7b5889 /gitlab/description_parser.py
parent53d4922d51b6b40ed85367ec611773abe47421e5 (diff)
downloademulator-bug-study-a9eb56beab0a66199b6fc7844132d28ba81174fa.tar.gz
emulator-bug-study-a9eb56beab0a66199b6fc7844132d28ba81174fa.zip
move project to gitlab directory
Diffstat (limited to 'gitlab/description_parser.py')
-rwxr-xr-xgitlab/description_parser.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/gitlab/description_parser.py b/gitlab/description_parser.py
new file mode 100755
index 00000000..2615b636
--- /dev/null
+++ b/gitlab/description_parser.py
@@ -0,0 +1,39 @@
+import re
+from tomlkit import string
+
+def remove_comments(description):
+    return re.sub(r'<!--(.|\n)*?-->', '', description)
+
+def get_headline_content(description, headline):
+    pattern = rf'## {headline}\s+(.*?)(?=##\s|\Z)'
+
+    match = re.search(pattern, description, re.DOTALL)
+    if match:
+        return string(match.group(1).strip(), multiline=True)
+    else:
+        return "n/a"
+
+def get_bullet_point(description, headline, category):
+    pattern = rf'{headline}(?:(?:.|\n)+?){category}:\s+(?:`)?(.+?)(?:`)?(?=\s)(?:\n|$)'
+
+    match = re.search(pattern, description)
+    if match:
+        return match.group(1).strip()
+    else:
+        return "n/a"
+
+def parse_description(desc):
+    desc = remove_comments(desc)
+
+    result = {
+        "host-os": get_bullet_point(desc, "Host", "Operating system"),
+        "host-arch": get_bullet_point(desc, "Host", "Architecture"),
+        "qemu-version": get_bullet_point(desc, "Host", "QEMU version"),
+        "guest-os": get_bullet_point(desc, "Emulated", "Operating system"),
+        "guest-arch": get_bullet_point(desc, "Emulated", "Architecture"),
+        "description": get_headline_content(desc, "Description of problem"),
+        "reproduce": get_headline_content(desc, "Steps to reproduce"),
+        "additional": get_headline_content(desc, "Additional information")
+    }
+
+    return result