|
| 1 | +# Code Duplication Detection Bot - Experiments |
| 2 | + |
| 3 | +This directory contains experiments and examples for testing the code duplication detection functionality. |
| 4 | + |
| 5 | +## Features Implemented |
| 6 | + |
| 7 | +### 1. Code Duplication Detection Service |
| 8 | +- **Location**: `csharp/Platform.Bot/Services/CodeDuplicationAnalysisService.cs` |
| 9 | +- **Purpose**: Analyzes repositories for duplicate code fragments |
| 10 | +- **Features**: |
| 11 | + - Extracts code fragments from multiple programming languages (.cs, .js, .ts, .py, .java, etc.) |
| 12 | + - Computes normalized hashes for similarity detection |
| 13 | + - Groups duplicated code fragments |
| 14 | + - Suggests method names for refactoring |
| 15 | + |
| 16 | +### 2. Code Duplication Detection Trigger |
| 17 | +- **Location**: `csharp/Platform.Bot/Triggers/CodeDuplicationDetectionTrigger.cs` |
| 18 | +- **Purpose**: Responds to issues requesting code duplication analysis |
| 19 | +- **Features**: |
| 20 | + - Triggered by issues containing "find repeated code" |
| 21 | + - Creates pull requests for each significant duplication |
| 22 | + - Posts analysis results as issue comments |
| 23 | + - Asks reviewers for feedback on method names and placement |
| 24 | + |
| 25 | +### 3. Branch Monitoring Trigger |
| 26 | +- **Location**: `csharp/Platform.Bot/Triggers/CodeDuplicationBranchMonitorTrigger.cs` |
| 27 | +- **Purpose**: Monitors pull requests created for duplication fixes |
| 28 | +- **Features**: |
| 29 | + - Detects when the default branch is updated |
| 30 | + - Notifies about potential conflicts |
| 31 | + - Tracks pull request status |
| 32 | + |
| 33 | +### 4. Helper Service |
| 34 | +- **Location**: `csharp/Platform.Bot/Services/FileStorageHelperService.cs` |
| 35 | +- **Purpose**: Provides simple file storage for tracking bot state |
| 36 | +- **Features**: |
| 37 | + - Stores duplication information |
| 38 | + - Tracks branch update timestamps |
| 39 | + - Persists pull request metadata |
| 40 | + |
| 41 | +## How It Works |
| 42 | + |
| 43 | +1. **Issue Creation**: Create an issue with title containing "find repeated code" |
| 44 | +2. **Analysis**: Bot analyzes the repository for code duplications |
| 45 | +3. **Pull Request Creation**: Bot creates pull requests for top duplications |
| 46 | +4. **Monitoring**: Bot monitors pull requests for branch updates |
| 47 | +5. **Feedback**: Bot asks for reviewer input on refactoring decisions |
| 48 | + |
| 49 | +## Example Issue Title |
| 50 | +``` |
| 51 | +Find the most repeated code fragments code and AST snapshot of a repository |
| 52 | +``` |
| 53 | + |
| 54 | +## Integration Points |
| 55 | + |
| 56 | +The bot integrates with: |
| 57 | +- GitHub Issues API (for triggering analysis) |
| 58 | +- GitHub Pull Requests API (for creating fixes) |
| 59 | +- GitHub Repository Content API (for code analysis) |
| 60 | +- Local file storage (for state tracking) |
| 61 | + |
| 62 | +## Configuration |
| 63 | + |
| 64 | +The bot uses the existing Platform.Bot architecture and is automatically enabled when the bot starts with the new triggers included. |
0 commit comments