Commit 559b7f831a

559b7f831a41e082644cb48cbaca0cd51af9d376

parent: 9307f56d4d

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-06-17 08:19 UTC

Adds make review_diff script for easier running local checks on just diff

Layout: unified · split

Makefile +4 −1
@@ -22,7 +22,7 @@
22 22
23# Targets 23# Targets
24.PHONY: all \ 24.PHONY: all \
25 install_lib_deps gen_readme gen_changelog validate review lib \ 25 install_lib_deps gen_readme gen_changelog validate review review_diff lib \
26 install_web_deps build_web start_web web 26 install_web_deps build_web start_web web
27 27
28# Get Python bin 28# Get Python bin
@@ -48,6 +48,9 @@ gen_changelog: install_lib_deps
48review: install_lib_deps 48review: install_lib_deps
49 $(PYTHON) $(LIB_DIR)/review-listings.py $(ARGS) 49 $(PYTHON) $(LIB_DIR)/review-listings.py $(ARGS)
50 50
51review_diff: install_lib_deps
52 $(PYTHON) $(LIB_DIR)/review-listings.py --changed-since $(or $(BASE),main) $(ARGS)
53
51lib: install_lib_deps validate gen_readme gen_changelog 54lib: install_lib_deps validate gen_readme gen_changelog
52 55
53# Targets for web/ 56# Targets for web/
lib/checks/check-project.py +3 −7
@@ -204,8 +204,8 @@ def check_security_alerts(owner, repo, token):
204 204
205def check_spam_prs(pr_user, token): 205def check_spam_prs(pr_user, token):
206 """Return list of spam findings based on recent PR activity.""" 206 """Return list of spam findings based on recent PR activity."""
207 if not pr_user or not token: 207 if not pr_user:
208 logger.warning("check_spam_prs skipped: %s", "no PR_USER" if not pr_user else "no GITHUB_TOKEN") 208 logger.warning("check_spam_prs skipped: no PR_USER")
209 return [] 209 return []
210 try: 210 try:
211 since = (datetime.now(timezone.utc) - timedelta(days=SPAM_WINDOW_DAYS)).strftime("%Y-%m-%d") 211 since = (datetime.now(timezone.utc) - timedelta(days=SPAM_WINDOW_DAYS)).strftime("%Y-%m-%d")
@@ -245,7 +245,7 @@ def check_spam_prs(pr_user, token):
245 245
246def check_new_account(pr_user, token): 246def check_new_account(pr_user, token):
247 """Return NEW_ACCOUNT_MSG if the PR author's GitHub account is very new.""" 247 """Return NEW_ACCOUNT_MSG if the PR author's GitHub account is very new."""
248 if not pr_user or not token: 248 if not pr_user:
249 return None 249 return None
250 data = _gh_get(f"/users/{pr_user}", token, label="user") 250 data = _gh_get(f"/users/{pr_user}", token, label="user")
251 if not data: 251 if not data:
@@ -296,8 +296,6 @@ def _pr_discloses_authorship(pr_body):
296 296
297def check_repo_exists(diff, token): 297def check_repo_exists(diff, token):
298 """Return REPO_404_MSG if an added service's GitHub repo returns a 404.""" 298 """Return REPO_404_MSG if an added service's GitHub repo returns a 404."""
299 if not token:
300 return None
301 seen = set() 299 seen = set()
302 for svc in get_services(diff, "added"): 300 for svc in get_services(diff, "added"):
303 owner, repo = utils.parse_github_field(svc.get("fields", {}).get("github")) 301 owner, repo = utils.parse_github_field(svc.get("fields", {}).get("github"))
@@ -312,8 +310,6 @@ def check_repo_exists(diff, token):
312def check_repo_signals(diff, pr_user, token, pr_body=""): 310def check_repo_signals(diff, pr_user, token, pr_body=""):
313 """Check GitHub repo author match, stars, and activity for added services.""" 311 """Check GitHub repo author match, stars, and activity for added services."""
314 findings = [] 312 findings = []
315 if not token:
316 return findings
317 cache = {} 313 cache = {}
318 for svc in get_services(diff, "added"): 314 for svc in get_services(diff, "added"):
319 gh = svc.get("fields", {}).get("github") 315 gh = svc.get("fields", {}).get("github")
lib/review-listings.py +36 −7
@@ -540,6 +540,17 @@ def build_context(args, data, token, api_token):
540 return ctx 540 return ctx
541 541
542 542
543def changed_service_keys(ref, head):
544 """Return {(category, section, name)} for services added or modified vs a git ref."""
545 from yaml_diff import build_index, diff_index, load_yaml_at_ref
546 base = load_yaml_at_ref(ref)
547 if base is None:
548 logging.error("Could not read awesome-privacy.yml at git ref %s", ref)
549 sys.exit(2)
550 added, _, modified = diff_index(build_index(base, 3), build_index(head, 3))
551 return set(added) | {k for k, _ in modified}
552
553
543def filter_entries(data, args): 554def filter_entries(data, args):
544 for cat, sec, svc in utils.iter_services(data): 555 for cat, sec, svc in utils.iter_services(data):
545 if args.category and args.category.lower() != cat.lower(): 556 if args.category and args.category.lower() != cat.lower():
@@ -654,7 +665,7 @@ def _markdown_summary(s):
654 665
655 666
656def render_list(findings, colors, summary): 667def render_list(findings, colors, summary):
657 lines = [] 668 lines = ["", colors["bold"]("Findings"), "--------"]
658 if not findings: 669 if not findings:
659 lines.append(colors["green"]("✓ All services passed.")) 670 lines.append(colors["green"]("✓ All services passed."))
660 grouped: dict = {} 671 grouped: dict = {}
@@ -766,6 +777,8 @@ def parse_args():
766 p.add_argument("--category", help="filter to a single category") 777 p.add_argument("--category", help="filter to a single category")
767 p.add_argument("--section", help="filter to a single section") 778 p.add_argument("--section", help="filter to a single section")
768 p.add_argument("--service", help="filter to a single service") 779 p.add_argument("--service", help="filter to a single service")
780 p.add_argument("--changed-since", metavar="REF",
781 help="only review services added or modified vs this git ref (e.g. main)")
769 p.add_argument("--only", type=_csv, default=[], help="comma-separated checks to run") 782 p.add_argument("--only", type=_csv, default=[], help="comma-separated checks to run")
770 p.add_argument("--skip", type=_csv, default=[], help="comma-separated checks to skip") 783 p.add_argument("--skip", type=_csv, default=[], help="comma-separated checks to skip")
771 p.add_argument("--severity", choices=["all", "warn", "error"], default="all") 784 p.add_argument("--severity", choices=["all", "warn", "error"], default="all")
@@ -814,25 +827,34 @@ def main():
814 token = args.token or os.environ.get("GITHUB_TOKEN", "") 827 token = args.token or os.environ.get("GITHUB_TOKEN", "")
815 api_token = os.environ.get("API_TOKEN", "") 828 api_token = os.environ.get("API_TOKEN", "")
816 829
830 # A targeted review (single entry/diff) runs token-gated checks unauthenticated, accepting
831 # rate limits. A full review skips them without a token, to avoid hammering the APIs across
832 # every listing once limits are hit.
833 targeted = bool(args.service or args.category or args.section or args.changed_since)
834
817 if not token: 835 if not token:
818 gh_checks = [n for n in enabled if CHECKS[n].needs_github] 836 gh_checks = [n for n in enabled if CHECKS[n].needs_github]
819 if gh_checks: 837 if gh_checks and not targeted:
820 logging.warning( 838 logging.warning(
821 "GITHUB_TOKEN not set, skipping GitHub checks (%s). " 839 "GITHUB_TOKEN not set, skipping GitHub checks (%s) for a full review. "
822 "Export GITHUB_TOKEN to enable them.", 840 "Export GITHUB_TOKEN, or narrow with --service/--category/--changed-since.",
823 ", ".join(gh_checks), 841 ", ".join(gh_checks),
824 ) 842 )
825 enabled = [n for n in enabled if not CHECKS[n].needs_github] 843 enabled = [n for n in enabled if not CHECKS[n].needs_github]
844 elif gh_checks:
845 logging.info("GITHUB_TOKEN not set, running GitHub checks unauthenticated (may be rate-limited)")
826 846
827 if not api_token: 847 if not api_token:
828 api_checks = [n for n in enabled if CHECKS[n].needs_api] 848 api_checks = [n for n in enabled if CHECKS[n].needs_api]
829 if api_checks: 849 if api_checks and not targeted:
830 logging.warning( 850 logging.warning(
831 "API_TOKEN not set, skipping API checks (%s). " 851 "API_TOKEN not set, skipping API checks (%s) for a full review. "
832 "Export API_TOKEN to enable them.", 852 "Export API_TOKEN, or narrow the review to run them.",
833 ", ".join(api_checks), 853 ", ".join(api_checks),
834 ) 854 )
835 enabled = [n for n in enabled if not CHECKS[n].needs_api] 855 enabled = [n for n in enabled if not CHECKS[n].needs_api]
856 elif api_checks:
857 logging.info("API_TOKEN not set, running API checks unauthenticated (may be rate-limited)")
836 858
837 if not enabled: 859 if not enabled:
838 logging.error("No checks to run after filters.") 860 logging.error("No checks to run after filters.")
@@ -848,6 +870,13 @@ def main():
848 sys.exit(2) 870 sys.exit(2)
849 871
850 entries = list(filter_entries(data, args)) 872 entries = list(filter_entries(data, args))
873 if args.changed_since:
874 keys = changed_service_keys(args.changed_since, data)
875 entries = [e for e in entries if (e.category, e.section, e.name) in keys]
876 if not entries:
877 logging.info("No added or modified services since %s, nothing to review",
878 args.changed_since)
879 return
851 if not entries: 880 if not entries:
852 logging.error("No services matched filters (category=%s, section=%s, service=%s)", 881 logging.error("No services matched filters (category=%s, section=%s, service=%s)",
853 args.category, args.section, args.service) 882 args.category, args.section, args.service)