From 95eca2471cffefa84131c1e4eb6b8d9d58ebcaad Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Sun, 5 Oct 2025 10:08:54 +0100 Subject: [PATCH] workflow update --- .github/workflows/codacy.yml | 70 +++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml index a00e01a..faa8443 100644 --- a/.github/workflows/codacy.yml +++ b/.github/workflows/codacy.yml @@ -1,4 +1,4 @@ -name: Codacy Bootstrap Issues +name: Sync Codacy Issues on: workflow_dispatch: @@ -99,3 +99,71 @@ jobs: await new Promise(resolve => setTimeout(resolve, 2000)); } } + + - name: Close Resolved GitHub Issues + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const dryRun = "${{ github.event.inputs.dry_run }}" === "true"; + const rawIssues = JSON.parse(fs.readFileSync('filtered_issues.json', 'utf8')); + + // Build current Codacy set (only *active* issues, not ignored) + const currentCodacyIds = new Set( + rawIssues.filter(i => !i.ignored).map(i => i.issueId) + ); + + // Build ignored Codacy set + const ignoredCodacyIds = new Set( + rawIssues.filter(i => i.ignored).map(i => i.issueId) + ); + + // Fetch ALL GitHub issues with codacy label + const allIssues = await github.paginate( + github.rest.issues.listForRepo, + { + owner: context.repo.owner, + repo: context.repo.repo, + state: "all", + labels: ["codacy"] + } + ); + + for (const ghIssue of allIssues) { + const matches = ghIssue.body?.match(/codacy-issue-([a-f0-9]+)/g); + if (!matches) continue; + + for (const match of matches) { + const issueId = match.replace("codacy-issue-", ""); + + // Close if not active OR explicitly ignored + if ((!currentCodacyIds.has(issueId) || ignoredCodacyIds.has(issueId)) + && ghIssue.state === "open") { + if (dryRun) { + console.log(`[DRY RUN] Would close issue #${ghIssue.number} (Codacy issueId ${issueId})`); + } else { + // Add comment before closing + const reason = ignoredCodacyIds.has(issueId) + ? "Auto closed because Codacy issue is marked as *ignored*" + : "Auto closed as not found in last analysis"; + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ghIssue.number, + body: reason + }); + + await github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ghIssue.number, + state: "closed" + }); + console.log(`❌ Closed GitHub issue #${ghIssue.number} for Codacy issueId ${issueId}`); + } + } + } + } + + \ No newline at end of file