Skip to content

Commit 5724aba

Browse files
committed
spam-report.js
Signed-off-by: Harsh Kumar <[email protected]>
1 parent 0c0c502 commit 5724aba

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

public/spam-report/spam-report.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const fs = require("fs");
2+
const fetch = require("node-fetch");
3+
4+
require('dotenv').config();
5+
6+
// Use this one
7+
const GITHUB_TOKEN = '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';
8+
9+
// Or create your own token
10+
// Set up a fine-grained personal access token (PAT) with the Juice Shop repository and metadata permission set to read-only
11+
// const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
12+
13+
const REPO_OWNER = "juice-shop";
14+
const REPO_NAME = "juice-shop";
15+
const LABEL = "spam";
16+
const GITHUB_API_URL = `https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/issues`;
17+
18+
const thirtyDaysAgo = new Date();
19+
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
20+
const sinceDate = thirtyDaysAgo.toISOString();
21+
22+
async function fetchSpamData() {
23+
let spamIssues = [];
24+
let spamPRs = [];
25+
let page = 1;
26+
27+
try {
28+
while (true) {
29+
const response = await fetch(
30+
`${GITHUB_API_URL}?labels=${LABEL}&state=closed&since=${sinceDate}&per_page=100&page=${page}`,
31+
{
32+
headers: {
33+
Authorization: `Bearer ${GITHUB_TOKEN}`,
34+
Accept: "application/vnd.github.v3+json",
35+
},
36+
}
37+
);
38+
39+
if (!response.ok) {
40+
throw new Error(`GitHub API Error: ${response.statusText}`);
41+
}
42+
43+
const data = await response.json();
44+
if (data.length === 0) break;
45+
46+
data.forEach((item) => {
47+
if (item.pull_request) {
48+
spamPRs.push(item);
49+
} else {
50+
spamIssues.push(item);
51+
}
52+
});
53+
54+
page++;
55+
}
56+
57+
const totalSpamPRs = spamPRs.length;
58+
const totalSpamIssues = spamIssues.length;
59+
60+
fs.writeFileSync("spam-prs.json", JSON.stringify(spamPRs, null, 2));
61+
fs.writeFileSync("spam-issues.json", JSON.stringify(spamIssues, null, 2));
62+
63+
console.log(`✅ Found ${totalSpamPRs} spam PRs and ${totalSpamIssues} spam issues in the last 30 days.`);
64+
return { totalSpamPRs, totalSpamIssues };
65+
} catch (error) {
66+
console.error("❌ Error fetching spam data:", error.message);
67+
process.exit(1);
68+
}
69+
}
70+
71+
fetchSpamData();

0 commit comments

Comments
 (0)