def markdown_report()

in privaterelay/cleaner_task.py [0:0]


    def markdown_report(self) -> str:
        """Return Markdown-formatted report of issues found and (maybe) fixed."""

        lines: list[str] = []
        report_entries = self.get_report_entries()

        # Get the maximum length of children for each entry with children
        max_len_children: dict[str, int] = {}
        for key, entry in report_entries.items():
            if entry.child_keys:
                children = [report_entries[subkey] for subkey in entry.child_keys]
                max_len_children[key] = max(
                    len(child.item.report_name or "") for child in children
                )

        # Output the markdown lines
        for key, entry in report_entries.items():
            if isinstance(entry.item, DataModelItem):
                lines.append(f"{entry.item.report_name}:")
                lines.append(f"  All: {entry.count}")
            else:
                parent_key, _ = key.rsplit(_KEY_SEP, 1)
                parent_entry = report_entries[parent_key]
                if parent_entry.count <= 0:
                    continue
                indent = "  " * entry.depth
                max_len = max_len_children[parent_key]
                lines.append(
                    f"{indent}{entry.item.report_name:<{max_len}}:"
                    f" {self._as_percent(entry.count, parent_entry.count)}"
                )
        return "\n".join(lines)