Commit f564947c20

f564947c20efbceb24fc280a6e5ce9e5f2621fb8

parent: f1b012efb2

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-03-07 16:54 UTC

Implements the anti-spam check

Layout: unified · split

.github/workflows/pr-check.yml +2
@@ -32,6 +32,7 @@ jobs:
3232 PR_TITLE: ${{ github.event.pull_request.title }}
3333 PR_BODY: ${{ github.event.pull_request.body }}
3434 PR_DRAFT: ${{ github.event.pull_request.draft }}
35 BASE_REF: ${{ github.event.pull_request.base.sha }}
3536 README_FAILED: ${{ steps.readme.outcome == 'failure' && 'true' || 'false' }}
3637 run: python lib/checks/check-pr-meta.py
3738 - name: Upload findings
@@ -117,6 +118,7 @@ jobs:
117118 - name: Check project health
118119 env:
119120 PR_USER: ${{ github.event.pull_request.user.login }}
121 PR_BODY: ${{ github.event.pull_request.body }}
120122 GITHUB_TOKEN: ${{ github.token }}
121123 run: python lib/checks/check-project.py
122124 - name: Upload findings
lib/checks/check-pr-meta.py +33
@@ -3,6 +3,7 @@
33import json
44import os
55import re
6import subprocess
67import sys
78
89FINDINGS_PATH = "/tmp/findings-compliance.json"
@@ -32,6 +33,15 @@ README_MSG = (
3233 " content in `awesome-privacy.yml`, and so your changes will be overridden!"
3334 " Instead, only modify the YAML file, and be sure to follow our Contributing Guidelines."
3435)
36BOT_MSG = (
37 "Submissions are only accepted from humans."
38 " This PR appears to have been authored by a bot or AI assistant."
39)
40
41_BOT_AUTHOR_RE = re.compile(
42 r"(?:noreply@anthropic\.com|devin-ai-integration|copilot-swe-agent|noreply@cursor\.com)",
43 re.IGNORECASE,
44)
3545
3646
3747def extract_section(body, header):
@@ -83,6 +93,24 @@ def check_checkboxes(body):
8393 return None
8494
8595
96def check_bot_coauthors(base_ref):
97 """Return a finding if any commit in the PR has a bot author or co-author."""
98 if not base_ref:
99 return None
100 try:
101 result = subprocess.run(
102 ["git", "log", f"{base_ref}..HEAD", "--format=%aN <%aE>%n%B"],
103 capture_output=True, text=True, timeout=30,
104 )
105 if result.returncode != 0:
106 return None
107 if _BOT_AUTHOR_RE.search(result.stdout):
108 return BOT_MSG
109 except Exception:
110 pass
111 return None
112
113
86114def check_readme(readme_failed):
87115 """Return a finding if the README check reported a failure."""
88116 if readme_failed == "true":
@@ -104,6 +132,11 @@ def main():
104132 body = os.environ.get("PR_BODY", "")
105133 draft = os.environ.get("PR_DRAFT", "false")
106134 readme_failed = os.environ.get("README_FAILED", "false")
135 base_ref = os.environ.get("BASE_REF", "")
136
137 finding = check_bot_coauthors(base_ref)
138 if finding:
139 findings.append(finding)
107140
108141 finding = check_title(title)
109142 if finding:
lib/checks/check-project.py +83 −13
@@ -2,8 +2,9 @@
22
33import json
44import os
5import re
56import sys
6from datetime import datetime, timezone
7from datetime import datetime, timedelta, timezone
78
89import requests
910import yaml
@@ -18,11 +19,14 @@ USER_AGENT = "awesome-privacy-ci/1.0"
1819MIN_STARS = 100
1920INACTIVE_DAYS = 90
2021MIN_AGE_DAYS = 120
21AI_COMMIT_THRESHOLD = 5
22AI_COMMIT_RATIO = 0.2
2223AI_BOT_AUTHORS = [
2324 "noreply@anthropic.com",
2425 "devin-ai-integration[bot]",
26 "copilot-swe-agent.github.com",
27 "noreply@cursor.com",
2528]
29SPAM_PR_THRESHOLD = 5
2630
2731LINK_MSG = (
2832 "Our automated checks were unable to verify the link(s) you included"
@@ -33,7 +37,7 @@ AUTHOR_MSG = (
3337 " have clearly disclosed this in your PR body for transparency"
3438)
3539STARS_MSG = (
36 "It looks like your submission is adding a quite small project."
40 "It looks like your submission is quite a small project without a lot of users yet."
3741 " In some circumstances we may ask you to resubmit this once the project"
3842 " is more mature and has a proven track record of good practices and maintenance."
3943)
@@ -64,6 +68,10 @@ SECURITY_MSG = (
6468 "This project has open security vulnerabilities (critical or high severity)"
6569 " flagged by GitHub Dependabot. Please verify these have been addressed"
6670)
71SPAM_MSG = (
72 "This user has opened up a large number of PRs to other awesome-* repos"
73 " in the past 24 hours, and appears to be spamming"
74)
6775
6876
6977def load_diff(path):
@@ -183,6 +191,21 @@ def check_links(diff, head):
183191 return None
184192
185193
194def _commit_has_bot(commit, bot_set):
195 """Check if a commit was authored or co-authored by a known AI bot."""
196 author = commit.get("commit", {}).get("author", {})
197 email = (author.get("email") or "").lower()
198 name = (author.get("name") or "").lower()
199 if email in bot_set or name in bot_set:
200 return True
201 message = (commit.get("commit", {}).get("message") or "").lower()
202 for line in message.splitlines():
203 if line.strip().startswith("co-authored-by:"):
204 if any(bot in line for bot in bot_set):
205 return True
206 return False
207
208
186209def check_ai_commits(owner, repo, token):
187210 """Return AI_CODE_MSG if recent commits contain significant AI bot activity."""
188211 try:
@@ -195,15 +218,12 @@ def check_ai_commits(owner, repo, token):
195218 )
196219 if resp.status_code != 200:
197220 return None
221 commits = resp.json()
222 if not commits:
223 return None
198224 bot_set = {a.lower() for a in AI_BOT_AUTHORS}
199 count = 0
200 for commit in resp.json():
201 author = commit.get("commit", {}).get("author", {})
202 email = (author.get("email") or "").lower()
203 name = (author.get("name") or "").lower()
204 if email in bot_set or name in bot_set:
205 count += 1
206 if count >= AI_COMMIT_THRESHOLD:
225 count = sum(1 for c in commits if _commit_has_bot(c, bot_set))
226 if count / len(commits) >= AI_COMMIT_RATIO:
207227 return AI_CODE_MSG
208228 except Exception:
209229 pass
@@ -228,7 +248,51 @@ def check_security_alerts(owner, repo, token):
228248 return None
229249
230250
231def check_repo_signals(diff, pr_user, token):
251def check_spam_prs(pr_user, token):
252 """Return SPAM_MSG if the user has opened many PRs to other awesome-* repos recently."""
253 if not pr_user or not token:
254 return None
255 try:
256 since = (datetime.now(timezone.utc) - timedelta(days=1)).strftime("%Y-%m-%d")
257 headers = {"Accept": "application/vnd.github.v3+json", "User-Agent": USER_AGENT}
258 headers["Authorization"] = f"token {token}"
259 resp = requests.get(
260 "https://api.github.com/search/issues",
261 headers=headers, timeout=TIMEOUT,
262 params={"q": f"type:pr author:{pr_user} created:>={since}"},
263 )
264 if resp.status_code != 200:
265 return None
266 items = resp.json().get("items", [])
267 this_repo = os.environ.get("GITHUB_REPOSITORY", "Lissy93/awesome-privacy").lower()
268 count = 0
269 for item in items:
270 repo_url = item.get("repository_url", "")
271 # repository_url looks like https://api.github.com/repos/owner/repo-name
272 repo_full = "/".join(repo_url.rstrip("/").split("/")[-2:]).lower()
273 repo_name = repo_url.rstrip("/").split("/")[-1].lower()
274 if repo_name.startswith("awesome-") and repo_full != this_repo:
275 count += 1
276 if count >= SPAM_PR_THRESHOLD:
277 return SPAM_MSG
278 except Exception:
279 pass
280 return None
281
282
283_DISCLOSURE_RE = re.compile(
284 r"i am the author|i'm the author|my project|i created|i develop"
285 r"|i maintain|i built|my own project|i made|author of|maintainer of",
286 re.IGNORECASE,
287)
288
289
290def _pr_discloses_authorship(pr_body):
291 """Return True if the PR body already discloses the submitter is the author."""
292 return bool(pr_body and _DISCLOSURE_RE.search(pr_body))
293
294
295def check_repo_signals(diff, pr_user, token, pr_body=""):
232296 """Check GitHub repo author match, stars, and activity for added services."""
233297 findings = []
234298 if not token:
@@ -252,6 +316,7 @@ def check_repo_signals(diff, pr_user, token):
252316 and repo_owner.get("type") == "User"
253317 and repo_owner.get("login", "").lower() == pr_user.lower()
254318 and AUTHOR_MSG not in findings
319 and not _pr_discloses_authorship(pr_body)
255320 ):
256321 findings.append(AUTHOR_MSG)
257322
@@ -316,8 +381,13 @@ def main():
316381 findings.append(finding)
317382
318383 pr_user = os.environ.get("PR_USER", "")
384 pr_body = os.environ.get("PR_BODY", "")
319385 token = os.environ.get("GITHUB_TOKEN", "")
320 findings.extend(check_repo_signals(diff, pr_user, token))
386 findings.extend(check_repo_signals(diff, pr_user, token, pr_body))
387
388 finding = check_spam_prs(pr_user, token)
389 if finding:
390 findings.append(finding)
321391 except Exception:
322392 pass
323393