Skip to content

Commit f2d655a

Browse files
Update codacy.yml
1 parent dbfcd89 commit f2d655a

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

.github/workflows/codacy.yml

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
name: Sync Codacy Issues
23

34
on:
@@ -10,7 +11,7 @@ on:
1011
push:
1112
# branches to consider in the event; optional, defaults to all
1213
branches:
13-
- master
14+
- main
1415
jobs:
1516
sync-codacy-issues:
1617
runs-on: ubuntu-latest
@@ -166,4 +167,69 @@ jobs:
166167
}
167168
}
168169
169-
170+
- name: Close Duplicate Codacy Issues
171+
uses: actions/github-script@v7
172+
with:
173+
script: |
174+
const dryRun = "${{ github.event.inputs.dry_run }}" === "true";
175+
176+
// Fetch all issues with the codacy label (open + closed)
177+
const allIssues = await github.paginate(
178+
github.rest.issues.listForRepo,
179+
{
180+
owner: context.repo.owner,
181+
repo: context.repo.repo,
182+
state: "all",
183+
labels: ["codacy"]
184+
}
185+
);
186+
187+
const grouped = {};
188+
189+
for (const issue of allIssues) {
190+
const matches = issue.body?.match(/codacy-issue-([a-f0-9]+)/g);
191+
if (!matches) continue;
192+
193+
for (const match of matches) {
194+
const issueId = match.replace("codacy-issue-", "");
195+
if (!grouped[issueId]) grouped[issueId] = [];
196+
grouped[issueId].push(issue);
197+
}
198+
}
199+
200+
for (const [issueId, issues] of Object.entries(grouped)) {
201+
if (issues.length <= 1) continue; // No duplicates
202+
203+
// Sort by creation date descending (newest first)
204+
issues.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
205+
206+
const [latest, ...duplicates] = issues;
207+
console.log(`Found ${issues.length} duplicates for Codacy issueId ${issueId}. Keeping #${latest.number}.`);
208+
209+
for (const dup of duplicates) {
210+
if (dup.state === "closed") continue;
211+
212+
if (dryRun) {
213+
console.log(`[DRY RUN] Would close duplicate issue #${dup.number} (Codacy issueId ${issueId})`);
214+
} else {
215+
await github.rest.issues.createComment({
216+
owner: context.repo.owner,
217+
repo: context.repo.repo,
218+
issue_number: dup.number,
219+
body: `Auto-closing as duplicate of newer Codacy issue #${latest.number} for ID \`${issueId}\`.`
220+
});
221+
222+
await github.rest.issues.update({
223+
owner: context.repo.owner,
224+
repo: context.repo.repo,
225+
issue_number: dup.number,
226+
state: "closed"
227+
});
228+
229+
console.log(`❌ Closed duplicate issue #${dup.number} (Codacy issueId ${issueId})`);
230+
}
231+
}
232+
}
233+
234+
235+

0 commit comments

Comments
 (0)