From 7c6a5a32f7c8b2d4902ccb17c2a410865f9f0994 Mon Sep 17 00:00:00 2001 From: RepoDynamicsBot <80158628+AAriam@users.noreply.github.com> Date: Wed, 25 Oct 2023 10:44:08 +0200 Subject: [PATCH] fix --- pyproject.toml | 2 +- src/repodynamics/actions/init.py | 33 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 01cd0f43..ba577350 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ namespaces = true # ----------------------------------------- Project Metadata ------------------------------------- # [project] -version = "0.0.0.dev165" +version = "0.0.0.dev166" name = "RepoDynamics" dependencies = [ "packaging >= 23.2, < 24", diff --git a/src/repodynamics/actions/init.py b/src/repodynamics/actions/init.py index 117252bb..25ab6ca0 100644 --- a/src/repodynamics/actions/init.py +++ b/src/repodynamics/actions/init.py @@ -1056,22 +1056,27 @@ def action_post_process_issue(self): return def _extract_entries_from_issue_body(self, body_elems: list[dict]): - def create_pattern(titles): - escaped_titles = [re.escape(title) for title in titles] - pattern_parts = [rf'### {escaped_titles[0]}\n(.*?)'] - for title in escaped_titles[1:]: - pattern_parts.append(rf'\n### {title}\n(.*?)') - return ''.join(pattern_parts) - titles = [] - ids = [] + def create_pattern(parts): + pattern_sections = [] + for idx, part in enumerate(parts): + pattern_section = rf"### {re.escape(part['title'])}\n(?P<{part['id']}>.*?)" + if idx != 0: + pattern_section = f"\n{pattern_section}" + if part['optional']: + pattern_section = f"(?:{pattern_section})?" + pattern_sections.append(pattern_section) + return ''.join(pattern_sections) + parts = [] for elem in body_elems: if elem.get("id"): pre_process = elem.get("pre_process") if not pre_process or FormGenerator._pre_process_existence(pre_process): - ids.append(elem["id"]) - titles.append(elem["attributes"]["label"]) - self.logger.success("Extract titles from issue form", titles) - pattern = create_pattern(titles) + optional = False + else: + optional = True + parts.append({"id": elem["id"], "title": elem["attributes"]["label"], "optional": optional}) + self.logger.success("Extract titles from issue form", parts) + pattern = create_pattern(parts) self.logger.success("Generate regex pattern for issue body", pattern) compiled_pattern = re.compile(pattern, re.S) # Search for the pattern in the markdown @@ -1082,7 +1087,9 @@ def create_pattern(titles): "Could not match the issue body to pattern defined in metadata.", ) # Create a dictionary with titles as keys and matched content as values - sections = {id_: content.strip() for id_, content in zip(ids, match.groups())} + sections = { + section_id: content.strip() if content else None for section_id, content in match.groupdict() + } return sections def write_website_announcement(self, announcement: str):