Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: node script that removes spam issues #15813

Merged
merged 12 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 15 additions & 39 deletions .github/workflows/close-spam-issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,19 @@ on:
jobs:
close_spam_issues:
runs-on: ubuntu-latest
defaults:
run:
working-directory: .github/workflows/spam-removal
permissions:
issues: write
steps:
- name: Check and Close Spam Issues
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
// ADD SPAM USERS TO THIS LIST
const spamUsers = ['Krakensu', 'Botakjelek', 'pemainlama', 'imyourmanposs', 'clav-code', 'sarahagus', 'teisanilan', 'jagat3131', 'sorenmoren6', 'SDGTAL', 'jedaymc', 'eztillieiium', 'danasatria89', 'puput212306'];
const issueCreator = context.payload.issue ? context.payload.issue.user.login : null;
async function closeSpamIssues() {
const issues = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});

for (const issue of issues) {
const issueCreator = issue.user.login;
if (spamUsers.includes(issueCreator)) {

await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});

await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['resolution: invalid', 'platform: all']
});

console.log(`Closed issue #${issue.number} created by spam user: ${issueCreator} and added labels.`);
}
}
}

closeSpamIssues();
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
- name: Install dependencies
run: npm install
- name: Run close spam issues script
run: node index.js
env:
GITHUB_TOKEN: ${{ github.token }}
53 changes: 53 additions & 0 deletions .github/workflows/spam-removal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Octokit } from '@octokit/rest';
import { context } from '@actions/github';
import { franc } from 'franc-min';

const spamWords = ['pemain'];

async function closeSpamIssues() {
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });

const issues = await octokit.paginate(octokit.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});

for (const issue of issues) {
const issueCreator = issue.user.login;
const issueContent = `${issue.title} ${issue.body || ''}`;
const detectedLanguage = franc(issueContent);

const spam = spamWords.find((word) => {
const wordWithSpace = ` ${word} `;

if (issueContent.includes(wordWithSpace)) return true;

return false;
});

if (spam || detectedLanguage === 'ind') {
await octokit.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
});

await octokit.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['resolution: invalid', 'platform: all'],
});

console.log(
`Closed issue #${issue.number} created by spam user: ${issueCreator} or detected as Indonesian language and added labels.`
);
}
}
}

closeSpamIssues().then(() => {
console.log('Successfully ran spam issue clean up');
});
8 changes: 8 additions & 0 deletions .github/workflows/spam-removal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "module",
"dependencies": {
"@actions/github": "^6.0.0",
"@octokit/rest": "^21.0.2",
"franc-min": "^6.2.0"
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ firebase-debug.log
firestore-debug.log
database-debug.log
ui-debug.log
**/.build/**/*
**/.build/**/*
.github/workflows/spam-removal/package-lock.json
Loading