Skip to content

Eliminate duplicated _escape_markdown method#1

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/refactor-duplicated-code
Draft

Eliminate duplicated _escape_markdown method#1
Copilot wants to merge 4 commits intomasterfrom
copilot/refactor-duplicated-code

Conversation

Copy link

Copilot AI commented Nov 6, 2025

Closes: #(issue number)

Description

The _escape_markdown method had identical implementations in both TelegramNotifier and TelegramEmailNotifier classes.

Changes:

  • Removed duplicate method from TelegramEmailNotifier (36 lines)
  • Renamed _escape_markdown to escape_markdown in TelegramNotifier (now public API)
  • Updated TelegramEmailNotifier to delegate to self.notifier.escape_markdown()
  • Added comprehensive docstring with Args/Returns sections

Before:

class TelegramEmailNotifier:
    def _format_email_notification(...):
        return f"*From:* {self._escape_markdown(email.sender)}"
    
    def _escape_markdown(self, text: str) -> str:
        # 24 lines of duplication...

After:

class TelegramEmailNotifier:
    def _format_email_notification(...):
        return f"*From:* {self.notifier.escape_markdown(email.sender)}"
    
    # Method removed - delegates to TelegramNotifier

Net -26 lines. Single source of truth for Telegram markdown escaping.

Tradeoffs

Made escape_markdown public to maintain proper encapsulation rather than accessing a private method across classes. This is the correct design but expands the public API surface.

Alternatives

Considered creating a shared utility module, but the method is Telegram-specific and belongs in TelegramNotifier. Current solution leverages existing composition relationship between the classes.

Original prompt

Find and refactor duplicated code


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 6, 2025 10:01
Co-authored-by: pmxi <64939659+pmxi@users.noreply.github.com>
Co-authored-by: pmxi <64939659+pmxi@users.noreply.github.com>
Co-authored-by: pmxi <64939659+pmxi@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for better maintainability Eliminate duplicated _escape_markdown method Nov 6, 2025
Copilot AI requested a review from pmxi November 6, 2025 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants