|
1 | | -name: Codacy Bootstrap Issues |
| 1 | +name: Sync Codacy Issues |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | workflow_dispatch: |
|
10 | 10 | push: |
11 | 11 | # branches to consider in the event; optional, defaults to all |
12 | 12 | branches: |
13 | | - - main |
| 13 | + - master |
14 | 14 | jobs: |
15 | 15 | sync-codacy-issues: |
16 | 16 | runs-on: ubuntu-latest |
|
99 | 99 | await new Promise(resolve => setTimeout(resolve, 2000)); |
100 | 100 | } |
101 | 101 | } |
| 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 | + } |
0 commit comments