Refactor Slack entity handlers to eliminate ~350 lines of duplicate code
- Dominant language
- Python
- Stars
- 451
- Forks
- 702
- Avg merge
- 22h 59m
- Merged PRs (30d)
- 91
Description
The project's Slack integration has multiple handler files that generate block presentations for different entity types (users, projects, chapters, committees). These handlers follow an identical pattern with significant code duplication.
Current State
Each entity handler independently implements the same logic for:
- Fetching search results from the index
- Displaying "no results" messages
- Building header blocks with search query context
- Iterating through results and formatting individual items
- Adding feedback/invite blocks
- Implementing pagination controls
Problem
The duplication causes several issues:
- Maintenance burden: Any bug fix or enhancement requires updating the same logic in multiple places
- Inconsistency risk: Changes may be applied inconsistently across handlers
- Testing overhead: Identical logic must be tested multiple times
- Code bloat: The codebase is unnecessarily larger
Proposed Solution
Create a shared base handler class that extracts the common patterns:
1. Create a BaseEntityHandler class with a generic get_blocks() method that accepts entity-specific parameters (search function, attributes, result formatting callback, etc.)
2. Implement helper methods for repeated logic:
- No results message generation
- Header block creation
- Feedback/invite block creation
- Pagination handling
3. Refactor each entity handler to inherit from or use the base handler .
Contributor guide
Assessment
This issue has not been assessed yet.