1- name : Codacy Bootstrap Issues
1+ name : Sync Codacy Issues
22
33on :
44 workflow_dispatch :
1010 push :
1111 # branches to consider in the event; optional, defaults to all
1212 branches :
13- - main
13+ - master
1414jobs :
1515 sync-codacy-issues :
1616 runs-on : ubuntu-latest
9999 await new Promise(resolve => setTimeout(resolve, 2000));
100100 }
101101 }
102+
103+ - name : Close Resolved GitHub Issues
104+ uses : actions/github-script@v7
105+ with :
106+ script : |
107+ const fs = require('fs');
108+ const dryRun = "${{ github.event.inputs.dry_run }}" === "true";
109+ const rawIssues = JSON.parse(fs.readFileSync('filtered_issues.json', 'utf8'));
110+
111+ // Build current Codacy set (only *active* issues, not ignored)
112+ const currentCodacyIds = new Set(
113+ rawIssues.filter(i => !i.ignored).map(i => i.issueId)
114+ );
115+
116+ // Build ignored Codacy set
117+ const ignoredCodacyIds = new Set(
118+ rawIssues.filter(i => i.ignored).map(i => i.issueId)
119+ );
120+
121+ // Fetch ALL GitHub issues with codacy label
122+ const allIssues = await github.paginate(
123+ github.rest.issues.listForRepo,
124+ {
125+ owner: context.repo.owner,
126+ repo: context.repo.repo,
127+ state: "all",
128+ labels: ["codacy"]
129+ }
130+ );
131+
132+ for (const ghIssue of allIssues) {
133+ const matches = ghIssue.body?.match(/codacy-issue-([a-f0-9]+)/g);
134+ if (!matches) continue;
135+
136+ for (const match of matches) {
137+ const issueId = match.replace("codacy-issue-", "");
138+
139+ // Close if not active OR explicitly ignored
140+ if ((!currentCodacyIds.has(issueId) || ignoredCodacyIds.has(issueId))
141+ && ghIssue.state === "open") {
142+ if (dryRun) {
143+ console.log(`[DRY RUN] Would close issue #${ghIssue.number} (Codacy issueId ${issueId})`);
144+ } else {
145+ // Add comment before closing
146+ const reason = ignoredCodacyIds.has(issueId)
147+ ? "Auto closed because Codacy issue is marked as *ignored*"
148+ : "Auto closed as not found in last analysis";
149+
150+ await github.rest.issues.createComment({
151+ owner: context.repo.owner,
152+ repo: context.repo.repo,
153+ issue_number: ghIssue.number,
154+ body: reason
155+ });
156+
157+ await github.rest.issues.update({
158+ owner: context.repo.owner,
159+ repo: context.repo.repo,
160+ issue_number: ghIssue.number,
161+ state: "closed"
162+ });
163+ console.log(`❌ Closed GitHub issue #${ghIssue.number} for Codacy issueId ${issueId}`);
164+ }
165+ }
166+ }
167+ }
168+
169+
0 commit comments