Commit 965d8c5826
Unsigned
Layout: unified · split
.github/workflows/health-check.yml +2
| @@ -12,6 +12,8 @@ on: | ||
| 12 | 12 | service: |
| 13 | 13 | description: Just run for a specific entry (optional) |
| 14 | 14 | type: string |
| 15 | schedule: | |
| 16 | - cron: '0 17 * * 5' # Weekly drift check. 5PM on a Friday, in time for weekend updates | |
| 15 | 17 | |
| 16 | 18 | permissions: |
| 17 | 19 | contents: read |
lib/awesome-privacy-readme-gen.py +31 −29
| @@ -20,11 +20,6 @@ app_list_file_path = os.path.join(project_root, 'awesome-privacy.yml') | ||
| 20 | 20 | readme_path = os.path.join(project_root, '.github/README.md') |
| 21 | 21 | icon_size=14 |
| 22 | 22 | |
| 23 | # Read the main YAML file, where all data lives | |
| 24 | logger.info("Reading the awesome-privacy file...") | |
| 25 | with open(app_list_file_path, 'r') as file: | |
| 26 | data = yaml.safe_load(file) | |
| 27 | ||
| 28 | 23 | def iconElement(serviceUrl, serviceIcon): |
| 29 | 24 | path = serviceIcon or f"https://icon.horse/icon/{urlparse(serviceUrl).netloc}" |
| 30 | 25 | return f"<img src='{path}' width='{icon_size}' alt='' />" |
| @@ -73,7 +68,7 @@ def makeHref(text): | ||
| 73 | 68 | if not text: return "#" |
| 74 | 69 | return re.sub(r'[^\w\s-]', '', text.lower()).replace(" ", "-") |
| 75 | 70 | |
| 76 | def makeContents(): | |
| 71 | def makeContents(data): | |
| 77 | 72 | contents = "<blockquote><details open>\n" |
| 78 | 73 | contents += "<summary>📋 <b>Contents</b></summary>\n" |
| 79 | 74 | |
| @@ -88,7 +83,7 @@ def makeContents(): | ||
| 88 | 83 | contents += "\n</details></blockquote>\n\n" |
| 89 | 84 | return contents |
| 90 | 85 | |
| 91 | def makeAwesomePrivacy(): | |
| 86 | def makeAwesomePrivacy(data): | |
| 92 | 87 | markdown = "" |
| 93 | 88 | for category in data.get('categories'): |
| 94 | 89 | markdown += f"## {category.get('name')}\n\n" |
| @@ -145,13 +140,6 @@ def makeAwesomePrivacy(): | ||
| 145 | 140 | markdown += "\n---\n\n" |
| 146 | 141 | return markdown |
| 147 | 142 | |
| 148 | awesome_privacy_results = makeContents() + makeAwesomePrivacy() | |
| 149 | ||
| 150 | # Update the README.md between markers | |
| 151 | logger.info("Reading README.md file...") | |
| 152 | with open(readme_path, 'r') as file: | |
| 153 | readme_content = file.read() | |
| 154 | ||
| 155 | 143 | def update_content_between_markers(content, start_marker, end_marker, new_content): |
| 156 | 144 | logger.info(f"Updating content between {start_marker} and {end_marker} markers...") |
| 157 | 145 | start_index = content.find(start_marker) |
| @@ -166,18 +154,32 @@ def update_content_between_markers(content, start_marker, end_marker, new_conten | ||
| 166 | 154 | logger.error(f"Markers {start_marker} and {end_marker} not found.") |
| 167 | 155 | return content |
| 168 | 156 | |
| 169 | # Update guides and resources in README.md | |
| 170 | readme_content = update_content_between_markers( | |
| 171 | readme_content, | |
| 172 | "<!-- awesome-privacy-start -->", | |
| 173 | "<!-- awesome-privacy-end -->", | |
| 174 | awesome_privacy_results | |
| 175 | ) | |
| 176 | ||
| 177 | # Write back the updated content to README.md | |
| 178 | logger.info("Writing back to README.md...") | |
| 179 | with open(readme_path, 'w') as file: | |
| 180 | file.write(readme_content) | |
| 181 | ||
| 182 | # All done. Time to go home for tea and medals. | |
| 183 | logger.info("Script completed successfully!") | |
| 157 | ||
| 158 | def main(): | |
| 159 | logger.info("Reading the awesome-privacy file...") | |
| 160 | with open(app_list_file_path, 'r') as file: | |
| 161 | data = yaml.safe_load(file) | |
| 162 | ||
| 163 | awesome_privacy_results = makeContents(data) + makeAwesomePrivacy(data) | |
| 164 | ||
| 165 | logger.info("Reading README.md file...") | |
| 166 | with open(readme_path, 'r') as file: | |
| 167 | readme_content = file.read() | |
| 168 | ||
| 169 | readme_content = update_content_between_markers( | |
| 170 | readme_content, | |
| 171 | "<!-- awesome-privacy-start -->", | |
| 172 | "<!-- awesome-privacy-end -->", | |
| 173 | awesome_privacy_results, | |
| 174 | ) | |
| 175 | ||
| 176 | logger.info("Writing back to README.md...") | |
| 177 | with open(readme_path, 'w') as file: | |
| 178 | file.write(readme_content) | |
| 179 | ||
| 180 | # All done. Time to go home for tea and medals. | |
| 181 | logger.info("Script completed successfully!") | |
| 182 | ||
| 183 | ||
| 184 | if __name__ == "__main__": | |
| 185 | main() | |
lib/checks/make-info-stats.py +14 −67
| @@ -25,23 +25,20 @@ import sys | ||
| 25 | 25 | from datetime import datetime, timezone |
| 26 | 26 | from urllib.parse import urlparse |
| 27 | 27 | |
| 28 | import requests | |
| 28 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| 29 | import utils | |
| 29 | 30 | |
| 30 | 31 | DIFF_PATH = "/tmp/pr-diff.json" |
| 31 | 32 | OUTPUT_PATH = "/tmp/repo-stats.md" |
| 32 | 33 | TIMEOUT = 10 |
| 33 | 34 | MAX_SUBMISSIONS = 5 |
| 34 | 35 | USER_AGENT = "awesome-privacy-ci/1.0" |
| 35 | AI_BOT_AUTHORS = [ | |
| 36 | "noreply@anthropic.com", | |
| 37 | "devin-ai-integration[bot]", | |
| 38 | "copilot-swe-agent.github.com", | |
| 39 | "noreply@cursor.com", | |
| 40 | ] | |
| 41 | 36 | RESTRICTIVE_LICENSES = { |
| 42 | 37 | "AGPL-3.0-only", "AGPL-3.0-or-later", "SSPL-1.0", "BSL-1.0", "BUSL-1.1", |
| 43 | 38 | } |
| 44 | 39 | |
| 40 | SESSION = utils.make_session(user_agent=USER_AGENT) | |
| 41 | ||
| 45 | 42 | SITE_INFO_URL = "https://site-info-fetch.as93.workers.dev" |
| 46 | 43 | ANDROID_API_URL = "https://android-app-privacy.as93.net" |
| 47 | 44 | IOS_API_URL = "https://ios-app-info.as93.net" |
| @@ -52,11 +49,8 @@ GREEN, ORANGE, RED, BLUE, WHITE = "\U0001f7e2", "\U0001f7e0", "\U0001f534", "\U0 | ||
| 52 | 49 | |
| 53 | 50 | def _api_get(url, params=None, timeout=TIMEOUT, headers=None): |
| 54 | 51 | """GET a URL, return parsed JSON on 200, else None.""" |
| 55 | hdrs = {"User-Agent": USER_AGENT} | |
| 56 | if headers: | |
| 57 | hdrs.update(headers) | |
| 58 | 52 | try: |
| 59 | resp = requests.get(url, headers=hdrs, timeout=timeout, params=params) | |
| 53 | resp = SESSION.get(url, headers=headers, timeout=timeout, params=params) | |
| 60 | 54 | if resp.status_code == 200: |
| 61 | 55 | return resp.json() |
| 62 | 56 | except Exception as e: |
| @@ -88,17 +82,6 @@ def relative_time(iso_str): | ||
| 88 | 82 | return None |
| 89 | 83 | |
| 90 | 84 | |
| 91 | def _days_since(iso_str): | |
| 92 | """Return number of days since an ISO timestamp, or None.""" | |
| 93 | if not iso_str: | |
| 94 | return None | |
| 95 | try: | |
| 96 | dt = datetime.fromisoformat(iso_str.replace("Z", "+00:00")) | |
| 97 | return (datetime.now(timezone.utc) - dt).days | |
| 98 | except Exception: | |
| 99 | return None | |
| 100 | ||
| 101 | ||
| 102 | 85 | def _friendly_date(iso_str): |
| 103 | 86 | """Return relative time string with 'ago' suffix, falling back to raw string.""" |
| 104 | 87 | if not iso_str: |
| @@ -131,28 +114,9 @@ def format_markdown(stats): | ||
| 131 | 114 | return "\n".join(f"- {emoji} **{label}:** {value}" for emoji, label, value in stats) |
| 132 | 115 | |
| 133 | 116 | |
| 134 | def parse_github_field(value): | |
| 135 | """Parse 'owner/repo' or full URL into (owner, repo) or (None, None).""" | |
| 136 | if not value: | |
| 137 | return None, None | |
| 138 | if value.startswith("https://github.com/"): | |
| 139 | parts = value.removeprefix("https://github.com/").strip("/").split("/") | |
| 140 | if len(parts) >= 2: | |
| 141 | return parts[0], parts[1] | |
| 142 | return None, None | |
| 143 | if "/" in value: | |
| 144 | parts = value.split("/") | |
| 145 | if len(parts) == 2: | |
| 146 | return parts[0], parts[1] | |
| 147 | return None, None | |
| 148 | ||
| 149 | ||
| 150 | 117 | def gh_get(path, token, params=None): |
| 151 | 118 | """GET a GitHub API endpoint. Returns JSON on 200, else None.""" |
| 152 | headers = {"Accept": "application/vnd.github.v3+json"} | |
| 153 | if token: | |
| 154 | headers["Authorization"] = f"token {token}" | |
| 155 | return _api_get(f"https://api.github.com{path}", params=params, headers=headers) | |
| 119 | return utils.gh_get(path, token, session=SESSION, params=params, timeout=TIMEOUT, label="repos") | |
| 156 | 120 | |
| 157 | 121 | |
| 158 | 122 | def fetch_all_data(owner, repo, token): |
| @@ -183,23 +147,9 @@ def fetch_all_data(owner, repo, token): | ||
| 183 | 147 | |
| 184 | 148 | commits = gh_get(f"/repos/{owner}/{repo}/commits", token, {"per_page": 100}) |
| 185 | 149 | if commits is not None: |
| 186 | bot_set = {a.lower() for a in AI_BOT_AUTHORS} | |
| 187 | ai_count = 0 | |
| 188 | for c in commits: | |
| 189 | author = c.get("commit", {}).get("author", {}) | |
| 190 | email = (author.get("email") or "").lower() | |
| 191 | name = (author.get("name") or "").lower() | |
| 192 | if email in bot_set or name in bot_set: | |
| 193 | ai_count += 1 | |
| 194 | continue | |
| 195 | message = (c.get("commit", {}).get("message") or "").lower() | |
| 196 | for line in message.splitlines(): | |
| 197 | if line.strip().startswith("co-authored-by:"): | |
| 198 | if any(bot in line for bot in bot_set): | |
| 199 | ai_count += 1 | |
| 200 | break | |
| 150 | bot_set = {a.lower() for a in utils.AI_BOT_AUTHORS} | |
| 201 | 151 | data["commit_count"] = len(commits) |
| 202 | data["ai_commit_count"] = ai_count | |
| 152 | data["ai_commit_count"] = sum(1 for c in commits if utils.commit_has_bot(c, bot_set)) | |
| 203 | 153 | else: |
| 204 | 154 | data["commit_count"] = None |
| 205 | 155 | data["ai_commit_count"] = None |
| @@ -232,7 +182,7 @@ def grade_stats(data): | ||
| 232 | 182 | else: |
| 233 | 183 | stats.append((GREEN, "License", lic.get("name") or spdx or "Present")) |
| 234 | 184 | |
| 235 | age_days = _days_since(data.get("created_at")) | |
| 185 | age_days = utils.repo_age_days(data) | |
| 236 | 186 | age_str = relative_time(data.get("created_at")) |
| 237 | 187 | if age_days is None: |
| 238 | 188 | stats.append((WHITE, "Repo Age", "Unknown")) |
| @@ -243,7 +193,7 @@ def grade_stats(data): | ||
| 243 | 193 | else: |
| 244 | 194 | stats.append((RED, "Repo Age", age_str)) |
| 245 | 195 | |
| 246 | updated_days = _days_since(data.get("pushed_at")) | |
| 196 | updated_days = utils.repo_pushed_days_ago(data) | |
| 247 | 197 | updated_str = _friendly_date(data.get("pushed_at")) |
| 248 | 198 | if updated_days is None: |
| 249 | 199 | stats.append((WHITE, "Last Updated", "Unknown")) |
| @@ -343,16 +293,13 @@ def check_security_txt(url): | ||
| 343 | 293 | base = f"{parsed.scheme}://{parsed.netloc}" |
| 344 | 294 | for path in ("/.well-known/security.txt", "/security.txt"): |
| 345 | 295 | try: |
| 346 | resp = requests.get( | |
| 347 | base + path, headers={"User-Agent": USER_AGENT}, | |
| 348 | timeout=TIMEOUT, allow_redirects=True, | |
| 349 | ) | |
| 296 | resp = SESSION.get(base + path, timeout=TIMEOUT, allow_redirects=True) | |
| 350 | 297 | if resp.status_code == 200 and "contact:" in resp.text.lower(): |
| 351 | 298 | return True |
| 352 | 299 | except Exception: |
| 353 | 300 | continue |
| 354 | 301 | try: |
| 355 | requests.head(base, headers={"User-Agent": USER_AGENT}, timeout=TIMEOUT) | |
| 302 | SESSION.head(base, timeout=TIMEOUT) | |
| 356 | 303 | return False |
| 357 | 304 | except Exception: |
| 358 | 305 | return None |
| @@ -545,7 +492,7 @@ def _resolve_args(argv): | ||
| 545 | 492 | result = {"name": None, "owner": None, "repo": None, "url": args.url, |
| 546 | 493 | "android": args.android, "ios": args.ios, "tosdr": args.tosdr} |
| 547 | 494 | if args.repo: |
| 548 | owner, repo = parse_github_field(args.repo) | |
| 495 | owner, repo = utils.parse_github_field(args.repo) | |
| 549 | 496 | if not owner: |
| 550 | 497 | print(f"Invalid repo format: {args.repo}", file=sys.stderr) |
| 551 | 498 | sys.exit(1) |
| @@ -570,7 +517,7 @@ def _resolve_args(argv): | ||
| 570 | 517 | for yaml_key, result_key in field_map.items(): |
| 571 | 518 | if fields.get(yaml_key): |
| 572 | 519 | if yaml_key == "github": |
| 573 | result["owner"], result["repo"] = parse_github_field(fields[yaml_key]) | |
| 520 | result["owner"], result["repo"] = utils.parse_github_field(fields[yaml_key]) | |
| 574 | 521 | else: |
| 575 | 522 | result[result_key] = str(fields[yaml_key]) |
| 576 | 523 | if any(v for k, v in result.items() if k != "name"): |
lib/review-listings.py +19 −5
| @@ -20,7 +20,13 @@ Checks: | ||
| 20 | 20 | - github-fork: github repo is not a fork (needs token) |
| 21 | 21 | |
| 22 | 22 | Findings have three severities: error (must fix), warn (should review), info (FYI). |
| 23 | HTTP 403/429 on reachability checks is demoted from error to warn (bot-blocking). | |
| 23 | HTTP 403/406/429 (and 404 on known bot-blocking hosts such as play.google.com) on | |
| 24 | reachability checks is demoted from error to warn. | |
| 25 | ||
| 26 | Exit codes: | |
| 27 | 1 when pass rate drops below FAIL_PASS_RATE or errors exceed FAIL_MAX_ERRORS (5) | |
| 28 | 2 you didn't run the script right / something else fucked up | |
| 29 | 0 everything is amazing | |
| 24 | 30 | |
| 25 | 31 | Flags: |
| 26 | 32 | - --save-json PATH: save a JSON report to this file |
| @@ -49,6 +55,7 @@ from datetime import datetime, timezone | ||
| 49 | 55 | from threading import Lock |
| 50 | 56 | from time import monotonic |
| 51 | 57 | from typing import Callable, Iterable |
| 58 | from urllib.parse import urlparse | |
| 52 | 59 | |
| 53 | 60 | sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| 54 | 61 | try: |
| @@ -73,9 +80,13 @@ ACTIVITY_BANDS = ( | ||
| 73 | 80 | SEVERITIES = ("error", "warn", "info") |
| 74 | 81 | _SEV_COLOR = {"error": "red", "warn": "yellow", "info": "cyan"} |
| 75 | 82 | _SEV_EMOJI = {"error": "🔴", "warn": "🟠", "info": "🟡"} |
| 76 | _SOFT_HTTP = {403, 429} | |
| 83 | _SOFT_HTTP = {403, 406, 429} | |
| 84 | _SOFT_404_HOSTS = {"play.google.com"} | |
| 77 | 85 | _PKG_RE = re.compile(r"^[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)+$") |
| 78 | 86 | |
| 87 | FAIL_PASS_RATE = 95.0 | |
| 88 | FAIL_MAX_ERRORS = 5 | |
| 89 | ||
| 79 | 90 | |
| 80 | 91 | @dataclass |
| 81 | 92 | class Entry: |
| @@ -150,8 +161,10 @@ def _get_repo(entry: Entry, ctx: Context): | ||
| 150 | 161 | |
| 151 | 162 | |
| 152 | 163 | def _unreachable(field, url, status, default_sev): |
| 153 | """Return (severity, message). 403/429 demote error to warn.""" | |
| 154 | sev = "warn" if default_sev == "error" and status in _SOFT_HTTP else default_sev | |
| 164 | """Return (severity, message). Bot-blocking signatures demote error to warn.""" | |
| 165 | host = urlparse(url).netloc.lower() | |
| 166 | soft = status in _SOFT_HTTP or (status == 404 and host in _SOFT_404_HOSTS) | |
| 167 | sev = "warn" if default_sev == "error" and soft else default_sev | |
| 155 | 168 | detail = f"{url} returned HTTP {status}" if status else f"{url} could not be reached" |
| 156 | 169 | return sev, f"{field} is unreachable, {detail}" |
| 157 | 170 | |
| @@ -701,7 +714,8 @@ def main(): | ||
| 701 | 714 | except OSError as exc: |
| 702 | 715 | logging.warning("Could not write %s: %s", path, exc) |
| 703 | 716 | |
| 704 | sys.exit(1 if any(f.severity == "error" for f in findings) else 0) | |
| 717 | fail = summary["pass_rate"] < FAIL_PASS_RATE or summary["errors"] > FAIL_MAX_ERRORS | |
| 718 | sys.exit(1 if fail else 0) | |
| 705 | 719 | |
| 706 | 720 | |
| 707 | 721 | if __name__ == "__main__": |
lib/utils/data.py +4 −3
| @@ -30,6 +30,7 @@ def slugify(title): | ||
| 30 | 30 | """Match the slug format used by awesome-privacy.xyz and the README generator.""" |
| 31 | 31 | if not title: |
| 32 | 32 | return "" |
| 33 | title = re.sub(r"[+&]", "and", title.lower()) | |
| 34 | title = re.sub(r"\s+", "-", title) | |
| 35 | return re.sub(r"[^a-z0-9-]", "", title) | |
| 33 | title = title.lower() | |
| 34 | title = re.sub(r"\s", "-", title) | |
| 35 | title = re.sub(r"[+&]", "and", title) | |
| 36 | return title.replace("?", "") | |
lib/utils/http.py +19 −9
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | """HTTP session and URL reachability helpers.""" |
| 2 | 2 | |
| 3 | 3 | import logging |
| 4 | import time | |
| 4 | 5 | |
| 5 | 6 | import requests |
| 6 | 7 | |
| @@ -8,6 +9,7 @@ DEFAULT_TIMEOUT = 10 | ||
| 8 | 9 | DEFAULT_USER_AGENT = ( |
| 9 | 10 | "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" |
| 10 | 11 | ) |
| 12 | _RETRY_BACKOFF = 1.0 # in seconds. one retry attempt on transient failures | |
| 11 | 13 | |
| 12 | 14 | |
| 13 | 15 | def make_session(user_agent=DEFAULT_USER_AGENT): |
| @@ -19,12 +21,20 @@ def make_session(user_agent=DEFAULT_USER_AGENT): | ||
| 19 | 21 | def check_url(url, session=None, timeout=DEFAULT_TIMEOUT): |
| 20 | 22 | """Return (ok, status_code). ok=True for 2xx/3xx; returns (True, None) on transport error.""" |
| 21 | 23 | session = session or make_session() |
| 22 | try: | |
| 23 | resp = session.head(url, timeout=timeout, allow_redirects=True) | |
| 24 | if resp.status_code >= 400: | |
| 25 | resp = session.get(url, timeout=timeout, allow_redirects=True, stream=True) | |
| 26 | resp.close() | |
| 27 | return resp.status_code < 400, resp.status_code | |
| 28 | except requests.RequestException as exc: | |
| 29 | logging.debug("URL check error for %s: %s", url, exc) | |
| 30 | return True, None | |
| 24 | for attempt in range(2): | |
| 25 | try: | |
| 26 | resp = session.head(url, timeout=timeout, allow_redirects=True) | |
| 27 | if resp.status_code >= 400: | |
| 28 | resp = session.get(url, timeout=timeout, allow_redirects=True, stream=True) | |
| 29 | resp.close() | |
| 30 | status = resp.status_code | |
| 31 | if 500 <= status < 600 and attempt == 0: | |
| 32 | time.sleep(_RETRY_BACKOFF) | |
| 33 | continue | |
| 34 | return status < 400, status | |
| 35 | except requests.RequestException as exc: | |
| 36 | logging.debug("URL check error for %s (attempt %d): %s", url, attempt + 1, exc) | |
| 37 | if attempt == 0: | |
| 38 | time.sleep(_RETRY_BACKOFF) | |
| 39 | continue | |
| 40 | return True, None | |