Skip to content

Commit d229125

Browse files
authored
Merge pull request #1724 from codeflash-ai/fix-duplicate-detector-concurrency
fix: merge duplicate detector into claude workflow and add concurrency
2 parents d805c6e + ad4ebdb commit d229125

2 files changed

Lines changed: 46 additions & 133 deletions

File tree

.github/workflows/claude.yml

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Claude Code
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
types: [opened, synchronize, ready_for_review, reopened]
67
issue_comment:
@@ -16,10 +17,16 @@ jobs:
1617
# Automatic PR review (can fix linting issues and push)
1718
# Blocked for fork PRs to prevent malicious code execution
1819
pr-review:
20+
concurrency:
21+
group: pr-review-${{ github.head_ref || github.run_id }}
22+
cancel-in-progress: true
1923
if: |
20-
github.event_name == 'pull_request' &&
21-
github.actor != 'claude[bot]' &&
22-
github.event.pull_request.head.repo.full_name == github.repository
24+
(
25+
github.event_name == 'pull_request' &&
26+
github.actor != 'claude[bot]' &&
27+
github.event.pull_request.head.repo.full_name == github.repository
28+
) ||
29+
github.event_name == 'workflow_dispatch'
2330
runs-on: ubuntu-latest
2431
permissions:
2532
contents: write
@@ -32,7 +39,7 @@ jobs:
3239
uses: actions/checkout@v4
3340
with:
3441
fetch-depth: 0
35-
ref: ${{ github.event.pull_request.head.ref }}
42+
ref: ${{ github.event.pull_request.head.ref || github.ref }}
3643

3744
- name: Install uv
3845
uses: astral-sh/setup-uv@v6
@@ -54,7 +61,9 @@ jobs:
5461
with:
5562
use_bedrock: "true"
5663
use_sticky_comment: true
64+
track_progress: true
5765
allowed_bots: "claude[bot],codeflash-ai[bot]"
66+
exclude_comments_by_actor: "*[bot]"
5867
prompt: |
5968
<context>
6069
repo: ${{ github.repository }}
@@ -109,6 +118,33 @@ jobs:
109118
Record findings for the summary comment. Refer to CLAUDE.md for project conventions.
110119
</step>
111120
121+
<step name="duplicate_detection">
122+
Check whether this PR introduces code that duplicates logic already present elsewhere in the repository — including across languages. Focus on finding true duplicates, not just similar-looking code.
123+
124+
1. Get changed source files (excluding tests and config):
125+
`git diff --name-only origin/main...HEAD -- '*.py' '*.js' '*.ts' '*.java' | grep -v -E '(test_|_test\.(py|js|ts)|\.test\.(js|ts)|\.spec\.(js|ts)|conftest\.py|/tests/|/test/|/__tests__/)' | grep -v -E '^(\.github/|code_to_optimize/|\.tessl/|node_modules/)'`
126+
127+
2. For each changed file, read it and identify functions/methods added or substantially modified (longer than 5 lines).
128+
129+
3. Search for duplicates using Grep:
130+
- Same function name defined elsewhere
131+
- 2-3 distinctive operations from the body (specific API calls, algorithm patterns, string literals)
132+
133+
4. Cross-module check: this codebase has parallel modules under `languages/python/`, `languages/javascript/`, and `languages/java/` plus runtimes under `packages/codeflash/runtime/` and `codeflash-java-runtime/`. When a changed file is under one of these areas, search the others for equivalent logic. Only flag cases where the logic is genuinely shared or one module could import from the other.
134+
135+
5. When a Grep hit looks promising, read the full function and compare semantics. Flag only:
136+
- Same function with same/very similar body in another module
137+
- Same helper logic repeated in sibling files
138+
- Same logic implemented inline across multiple classes
139+
- Same algorithm reimplemented across language modules (Python code, not target-language differences)
140+
141+
Report at most 5 findings with confidence (HIGH/MEDIUM), locations, what's duplicated, and suggestion.
142+
143+
DO NOT report: boilerplate, functions under 5 lines, config/setup, intentional polymorphism, test files, imports, code that must differ due to target-language semantics.
144+
145+
If no duplicates found, include "No duplicates detected" in the summary.
146+
</step>
147+
112148
<step name="coverage">
113149
Analyze test coverage for changed files:
114150
@@ -120,19 +156,12 @@ jobs:
120156
</step>
121157
122158
<step name="summary_comment">
123-
Post exactly one summary comment containing all results from previous steps.
124-
125-
To ensure one comment: find an existing claude[bot] comment and update it, or create one if none exists.
126-
Delete any duplicate claude[bot] comments.
127-
128-
```
129-
gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments --jq '.[] | select(.user.login == "claude[bot]") | .id' | head -1
130-
```
159+
Post exactly one summary comment containing all results from previous steps using this format:
131160
132-
Format:
133161
## PR Review Summary
134162
### Prek Checks
135163
### Code Review
164+
### Duplicate Detection
136165
### Test Coverage
137166
---
138167
*Last updated: <timestamp>*
@@ -165,12 +194,15 @@ jobs:
165194
- All findings are in a single summary comment (no inline review comments were created)
166195
- If fixes were made, they were verified with prek
167196
</verification>
168-
claude_args: '--model us.anthropic.claude-opus-4-6-v1 --allowedTools "Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(gh pr checks:*),Bash(gh pr merge:*),Bash(gh issue view:*),Bash(gh issue list:*),Bash(gh api:*),Bash(uv run prek *),Bash(uv run mypy *),Bash(uv run coverage *),Bash(uv run pytest *),Bash(git status*),Bash(git add *),Bash(git commit *),Bash(git push*),Bash(git diff *),Bash(git checkout *),Read,Glob,Grep,Edit,Skill"'
197+
claude_args: '--model us.anthropic.claude-opus-4-6-v1 --max-turns 25 --allowedTools "Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(gh pr checks:*),Bash(gh pr merge:*),Bash(gh issue view:*),Bash(gh issue list:*),Bash(gh api:*),Bash(uv run prek *),Bash(uv run mypy *),Bash(uv run coverage *),Bash(uv run pytest *),Bash(git status*),Bash(git add *),Bash(git commit *),Bash(git push*),Bash(git diff *),Bash(git checkout *),Read,Glob,Grep,Edit,Skill"'
169198
additional_permissions: |
170199
actions: read
171200
172201
# @claude mentions (can edit and push) - restricted to maintainers only
173202
claude-mention:
203+
concurrency:
204+
group: claude-mention-${{ github.event.issue.number || github.event.pull_request.number || github.run_id }}
205+
cancel-in-progress: false
174206
if: |
175207
(
176208
github.event_name == 'issue_comment' &&

.github/workflows/duplicate-code-detector.yml

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)