| @@ -2,8 +2,9 @@ |
| 2 | |
2 | |
| 3 | import json |
3 | import json |
| 4 | import os |
4 | import os |
| |
5 | import re |
| 5 | import sys |
6 | import sys |
| 6 | from datetime import datetime, timezone |
7 | from datetime import datetime, timedelta, timezone |
| 7 | |
8 | |
| 8 | import requests |
9 | import requests |
| 9 | import yaml |
10 | import yaml |
| @@ -18,11 +19,14 @@ USER_AGENT = "awesome-privacy-ci/1.0" |
| 18 | MIN_STARS = 100 |
19 | MIN_STARS = 100 |
| 19 | INACTIVE_DAYS = 90 |
20 | INACTIVE_DAYS = 90 |
| 20 | MIN_AGE_DAYS = 120 |
21 | MIN_AGE_DAYS = 120 |
| 21 | AI_COMMIT_THRESHOLD = 5 |
22 | AI_COMMIT_RATIO = 0.2 |
| 22 | AI_BOT_AUTHORS = [ |
23 | AI_BOT_AUTHORS = [ |
| 23 | "noreply@anthropic.com", |
24 | "noreply@anthropic.com", |
| 24 | "devin-ai-integration[bot]", |
25 | "devin-ai-integration[bot]", |
| |
26 | "copilot-swe-agent.github.com", |
| |
27 | "noreply@cursor.com", |
| 25 | ] |
28 | ] |
| |
29 | SPAM_PR_THRESHOLD = 5 |
| 26 | |
30 | |
| 27 | LINK_MSG = ( |
31 | LINK_MSG = ( |
| 28 | "Our automated checks were unable to verify the link(s) you included" |
32 | "Our automated checks were unable to verify the link(s) you included" |
| @@ -33,7 +37,7 @@ AUTHOR_MSG = ( |
| 33 | " have clearly disclosed this in your PR body for transparency" |
37 | " have clearly disclosed this in your PR body for transparency" |
| 34 | ) |
38 | ) |
| 35 | STARS_MSG = ( |
39 | STARS_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." |
| 37 | " In some circumstances we may ask you to resubmit this once the project" |
41 | " In some circumstances we may ask you to resubmit this once the project" |
| 38 | " is more mature and has a proven track record of good practices and maintenance." |
42 | " is more mature and has a proven track record of good practices and maintenance." |
| 39 | ) |
43 | ) |
| @@ -64,6 +68,10 @@ SECURITY_MSG = ( |
| 64 | "This project has open security vulnerabilities (critical or high severity)" |
68 | "This project has open security vulnerabilities (critical or high severity)" |
| 65 | " flagged by GitHub Dependabot. Please verify these have been addressed" |
69 | " flagged by GitHub Dependabot. Please verify these have been addressed" |
| 66 | ) |
70 | ) |
| |
71 | SPAM_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 | ) |
| 67 | |
75 | |
| 68 | |
76 | |
| 69 | def load_diff(path): |
77 | def load_diff(path): |
| @@ -183,6 +191,21 @@ def check_links(diff, head): |
| 183 | return None |
191 | return None |
| 184 | |
192 | |
| 185 | |
193 | |
| |
194 | def _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 | |
| 186 | def check_ai_commits(owner, repo, token): |
209 | def check_ai_commits(owner, repo, token): |
| 187 | """Return AI_CODE_MSG if recent commits contain significant AI bot activity.""" |
210 | """Return AI_CODE_MSG if recent commits contain significant AI bot activity.""" |
| 188 | try: |
211 | try: |
| @@ -195,15 +218,12 @@ def check_ai_commits(owner, repo, token): |
| 195 | ) |
218 | ) |
| 196 | if resp.status_code != 200: |
219 | if resp.status_code != 200: |
| 197 | return None |
220 | return None |
| |
221 | commits = resp.json() |
| |
222 | if not commits: |
| |
223 | return None |
| 198 | bot_set = {a.lower() for a in AI_BOT_AUTHORS} |
224 | bot_set = {a.lower() for a in AI_BOT_AUTHORS} |
| 199 | count = 0 |
225 | count = sum(1 for c in commits if _commit_has_bot(c, bot_set)) |
| 200 | for commit in resp.json(): |
226 | if count / len(commits) >= AI_COMMIT_RATIO: |
| 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: |
| |
| 207 | return AI_CODE_MSG |
227 | return AI_CODE_MSG |
| 208 | except Exception: |
228 | except Exception: |
| 209 | pass |
229 | pass |
| @@ -228,7 +248,51 @@ def check_security_alerts(owner, repo, token): |
| 228 | return None |
248 | return None |
| 229 | |
249 | |
| 230 | |
250 | |
| 231 | def check_repo_signals(diff, pr_user, token): |
251 | def 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 | |
| |
290 | def _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 | |
| |
295 | def check_repo_signals(diff, pr_user, token, pr_body=""): |
| 232 | """Check GitHub repo author match, stars, and activity for added services.""" |
296 | """Check GitHub repo author match, stars, and activity for added services.""" |
| 233 | findings = [] |
297 | findings = [] |
| 234 | if not token: |
298 | if not token: |
| @@ -252,6 +316,7 @@ def check_repo_signals(diff, pr_user, token): |
| 252 | and repo_owner.get("type") == "User" |
316 | and repo_owner.get("type") == "User" |
| 253 | and repo_owner.get("login", "").lower() == pr_user.lower() |
317 | and repo_owner.get("login", "").lower() == pr_user.lower() |
| 254 | and AUTHOR_MSG not in findings |
318 | and AUTHOR_MSG not in findings |
| |
319 | and not _pr_discloses_authorship(pr_body) |
| 255 | ): |
320 | ): |
| 256 | findings.append(AUTHOR_MSG) |
321 | findings.append(AUTHOR_MSG) |
| 257 | |
322 | |
| @@ -316,8 +381,13 @@ def main(): |
| 316 | findings.append(finding) |
381 | findings.append(finding) |
| 317 | |
382 | |
| 318 | pr_user = os.environ.get("PR_USER", "") |
383 | pr_user = os.environ.get("PR_USER", "") |
| |
384 | pr_body = os.environ.get("PR_BODY", "") |
| 319 | token = os.environ.get("GITHUB_TOKEN", "") |
385 | 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) |
| 321 | except Exception: |
391 | except Exception: |
| 322 | pass |
392 | pass |
| 323 | |
393 | |