|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | const fs = require('fs').promises; |
11 | | -const path = require('path'); |
12 | 11 |
|
13 | 12 | const SPAM_LIST_PATH = '.github/spam-list.txt'; |
14 | 13 | const dryRun = (process.env.DRY_RUN || 'false').toString().toLowerCase() === 'true'; |
@@ -72,31 +71,12 @@ async function computeSpamListUpdates(spamUsers, rehabilitatedUsers) { |
72 | 71 | }; |
73 | 72 | } |
74 | 73 |
|
75 | | -// Write the updated spam list to file |
76 | | -async function updateSpamListFile(usernames) { |
77 | | - if (dryRun) { |
78 | | - console.log('[DRY RUN] Would write to spam list file:'); |
79 | | - console.log(usernames.join('\n')); |
80 | | - return; |
81 | | - } |
82 | | - |
83 | | - const content = usernames.join('\n') + (usernames.length > 0 ? '\n' : ''); |
84 | | - |
85 | | - // Ensure directory exists |
86 | | - const dir = path.dirname(SPAM_LIST_PATH); |
87 | | - await fs.mkdir(dir, { recursive: true }); |
88 | | - |
89 | | - await fs.writeFile(SPAM_LIST_PATH, content, 'utf8'); |
90 | | - |
91 | | -} |
92 | | - |
93 | | -// Generate PR title and body with summary of changes |
94 | 74 |
|
95 | 75 | function generateSummary(additions, removals) { |
96 | | - const title = `chore: Update spam list (${additions.length} additions, ${removals.length} removals)`; |
| 76 | + const title = `Update spam list (${additions.length} additions, ${removals.length} removals)`; |
97 | 77 |
|
98 | 78 | let body = '## Automated Spam List Update\n\n'; |
99 | | - body += 'This PR automatically updates the spam list based on recent PR activity.\n\n'; |
| 79 | + body += 'This issue details the updates to the spam list based on recent PR activity.\n\n'; |
100 | 80 |
|
101 | 81 | if (additions.length > 0) { |
102 | 82 | body += `### ➕ Additions (${additions.length})\n\n`; |
@@ -206,37 +186,49 @@ module.exports = async ({github, context, core}) => { |
206 | 186 | } |
207 | 187 | } |
208 | 188 |
|
209 | | - // ... rest remains the same |
210 | | - const { additions, removals, finalSpamList } = await computeSpamListUpdates( |
| 189 | + // After processing all PRs, compute the final spam list updates |
| 190 | + const { additions, removals } = await computeSpamListUpdates( |
211 | 191 | spamUsers, |
212 | 192 | rehabilitatedUsers |
213 | 193 | ); |
214 | 194 |
|
215 | 195 | console.log(`Additions: ${additions.length}`); |
216 | 196 | console.log(`Removals: ${removals.length}`); |
217 | 197 |
|
218 | | - if (additions.length > 0 || removals.length > 0) { |
219 | | - await updateSpamListFile(finalSpamList); |
220 | | - } |
221 | | - |
222 | 198 | const { title, body } = generateSummary(additions, removals); |
223 | 199 | const hasChanges = additions.length > 0 || removals.length > 0; |
224 | 200 |
|
225 | | - const branchName = hasChanges |
226 | | - ? `spam-list-update-${new Date().toISOString().split('T')[0]}` |
227 | | - : ''; |
228 | | - |
229 | | - core.setOutput('has-changes', hasChanges.toString()); |
230 | | - core.setOutput('pr-title', title); |
231 | | - core.setOutput('pr-body', body); |
232 | | - core.setOutput('branch-name', branchName); |
| 201 | + if (hasChanges) { |
| 202 | + if (dryRun) { |
| 203 | + console.log('[DRY RUN] Would create issue with:'); |
| 204 | + console.log(`Title: ${title}`); |
| 205 | + console.log(`Body: ${body}`); |
| 206 | + } else { |
| 207 | + // Check for existing open issue to avoid duplicates |
| 208 | + const { data: existing } = await github.rest.issues.listForRepo({ |
| 209 | + owner, |
| 210 | + repo, |
| 211 | + labels: 'spam-list-update', |
| 212 | + state: 'open', |
| 213 | + per_page: 1 |
| 214 | + }); |
| 215 | + if (existing.length > 0) { |
| 216 | + console.log(`Skipping issue creation: open issue #${existing[0].number} already exists`); |
| 217 | + return; |
| 218 | + } |
| 219 | + await github.rest.issues.create({ |
| 220 | + owner, |
| 221 | + repo, |
| 222 | + title, |
| 223 | + body, |
| 224 | + labels: ['spam-list-update', 'automated'] |
| 225 | + }); |
| 226 | + console.log('Issue created successfully'); |
| 227 | + } |
| 228 | + } else { |
| 229 | + console.log('No changes needed, skipping issue creation'); |
| 230 | + } |
233 | 231 |
|
234 | | - return { |
235 | | - hasChanges, |
236 | | - title, |
237 | | - body, |
238 | | - branchName |
239 | | - }; |
240 | 232 | } catch (error) { |
241 | 233 | core.setFailed(`Failed to update spam list: ${error.message}`); |
242 | 234 | throw error; |
|
0 commit comments