Skip to content

Add code duplication analysis workflow#7874

Open
Evangelink wants to merge 4 commits intomainfrom
dev/amauryleve/dedup-analysis-workflow
Open

Add code duplication analysis workflow#7874
Evangelink wants to merge 4 commits intomainfrom
dev/amauryleve/dedup-analysis-workflow

Conversation

@Evangelink
Copy link
Copy Markdown
Member

Summary

Adds an agentic GitHub Actions workflow that automatically detects and analyzes code duplication in the \src/\ directory.

How it works

  1. Scan — Runs jscpd (Rabin-Karp algorithm) on C# source files to find duplicated code blocks
  2. Analyze — Feeds the top findings (with full source context) to GitHub Models API for classification
  3. Report — Creates/updates a GitHub issue with a prioritized table of refactoring recommendations

Each finding is classified as:

  • Extract Method — identical logic that can become a shared helper
  • Extract Base Class — duplicated across classes with shared behavior
  • Template Method — same structure with minor variations to parameterize
  • Intentional — polyfills, cross-project isolation, or design choices to keep

Trigger

  • Weekly on Monday at 8:00 UTC (scheduled)
  • On-demand via \workflow_dispatch\ with configurable parameters: path, thresholds, model, top N

Files

File Purpose
.github/workflows/dedup-analysis.yml\ GitHub Actions workflow
.github/scripts/analyze-duplicates.py\ Python script: reads jscpd report, calls GitHub Models API, creates issue
.github/scripts/scan-duplicates.ps1\ PowerShell helper for local scanning
.jscpd.json\ jscpd configuration tuned for the repo

Initial local scan results

A local scan found 304 clones at 5.58% duplication across 1013 source files. Top findings include:

  • 87 lines: \UnicodeCharacterUtilities.cs\ duplicated between Analyzers and Platform.MSBuild
  • 73 lines: \ITypeSymbolExtensions.cs\ duplicated between Analyzers and SourceGeneration
  • 53 lines: \ObjectPool.cs\ duplicated between Analyzers and Platform

STA (Single Threaded Apartment) is a Windows-only COM threading concept.
On non-Windows platforms, STATestMethodAttribute now:
- Runs the test without STA context (unchanged behaviour)
- Appends a warning to the test output explaining STA was not applied
- Documents the design decision with a clear code comment

Removes the ambiguous '// TODO: Throw?' comment.
STATestMethodAttribute now throws PlatformNotSupportedException on
non-Windows platforms since STA is a Windows-only COM concept.
The error message guides users to use [OSCondition(OperatingSystems.Windows)]
to skip the test on non-Windows platforms.
Add NETFRAMEWORK-compatible OS check using Environment.OSVersion.Platform
so that STATestMethodAttribute throws PlatformNotSupportedException
on Mono running on non-Windows, not just on .NET Core/5+.
Adds an agentic GitHub Actions workflow that:
- Scans C# source code for duplicated blocks using jscpd (Rabin-Karp)
- Feeds top findings (with source context) to GitHub Models API for analysis
- Classifies each duplicate: Extract Method, Template Method, Intentional, etc.
- Creates/updates a GitHub issue with prioritized refactoring recommendations
- Runs weekly on schedule or on-demand via workflow_dispatch

Files:
- .github/workflows/dedup-analysis.yml: Main workflow definition
- .github/scripts/analyze-duplicates.py: LLM-powered analysis script
- .github/scripts/scan-duplicates.ps1: Local scan helper (PowerShell)
- .jscpd.json: jscpd configuration tuned for the repo
Copilot AI review requested due to automatic review settings April 27, 2026 16:29
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.

1 participant