Skip to content

Commit

Permalink
Logic for handling more than one Topic assigned to an Issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
MobiTikula committed Nov 11, 2024
1 parent b6088b4 commit ecaffe0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
15 changes: 8 additions & 7 deletions living_documentation_generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,16 @@ def _generate_md_issue_page(self, issue_page_template: str, consolidated_issue:
issue_md_page_content = issue_page_template.format(**replacements)

# Create a directory structure path for the issue page
page_directory_path = consolidated_issue.generate_directory_path(issue_table)
os.makedirs(page_directory_path, exist_ok=True)
page_directory_paths: list[str] = consolidated_issue.generate_directory_path(issue_table)
for page_directory_path in page_directory_paths:
os.makedirs(page_directory_path, exist_ok=True)

# Save the single issue Markdown page
page_filename = consolidated_issue.generate_page_filename()
with open(os.path.join(page_directory_path, page_filename), "w", encoding="utf-8") as f:
f.write(issue_md_page_content)
# Save the single issue Markdown page
page_filename = consolidated_issue.generate_page_filename()
with open(os.path.join(page_directory_path, page_filename), "w", encoding="utf-8") as f:
f.write(issue_md_page_content)

logger.debug("Generated Markdown page: %s.", page_filename)
logger.debug("Generated Markdown page: %s.", page_filename)

def _generate_structured_index_pages(
self,
Expand Down
26 changes: 16 additions & 10 deletions living_documentation_generator/model/consolidated_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,13 @@ def generate_page_filename(self) -> str:

return page_filename

def generate_directory_path(self, issue_table: str) -> str:
def generate_directory_path(self, issue_table: str) -> list[str]:
"""
Generate a directory path based on enabled features.
Generate a list of directory paths based on enabled features.
An issue can be placed in multiple directories if it is associated with more than one topic.
@param issue_table: The consolidated issue summary table.
@return: The generated directory path.
@return: The list of generated directory paths.
"""
output_path = ActionInputs.get_output_directory()

Expand All @@ -185,13 +186,22 @@ def generate_directory_path(self, issue_table: str) -> str:

# If grouping by topics is enabled, create a directory path based on the issue topic
if ActionInputs.get_is_grouping_by_topics_enabled():
topic_paths = []

# Extract labels from the issue table
labels = re.findall(r"\| Labels \| (.*?) \|", issue_table)
if labels:
labels = labels[0].split(", ")

# Check for all labels ending with "Topic"
topic_labels = [label for label in labels if label.endswith("Topic")]

# If no label ends with "Topic", create a "NoTopic" issue directory path
if not topic_labels:
self.__topic = "NoTopic"
no_topic_path = os.path.join(output_path, "NoTopic")
return [no_topic_path]

if len(topic_labels) > 1:
logger.debug(
"Multiple Topic labels found for Issue #%s: %s (%s): %s",
Expand All @@ -205,11 +215,7 @@ def generate_directory_path(self, issue_table: str) -> str:
for topic_label in topic_labels:
self.__topic = topic_label
topic_path = os.path.join(output_path, topic_label)
return topic_path

# If no label ends with "Topic", create a "noTopic" issue directory path
self.__topic = "NoTopic"
no_topic_path = os.path.join(output_path, "NoTopic")
return no_topic_path
topic_paths.append(topic_path)
return topic_paths

return output_path
return [output_path]

0 comments on commit ecaffe0

Please sign in to comment.