| @@ -540,6 +540,17 @@ def build_context(args, data, token, api_token): |
| 540 | 540 | return ctx |
| 541 | 541 | |
| 542 | 542 | |
| 543 | def 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 | |
| 543 | 554 | def filter_entries(data, args): |
| 544 | 555 | for cat, sec, svc in utils.iter_services(data): |
| 545 | 556 | if args.category and args.category.lower() != cat.lower(): |
| @@ -654,7 +665,7 @@ def _markdown_summary(s): |
| 654 | 665 | |
| 655 | 666 | |
| 656 | 667 | def render_list(findings, colors, summary): |
| 657 | | lines = [] |
| 668 | lines = ["", colors["bold"]("Findings"), "--------"] |
| 658 | 669 | if not findings: |
| 659 | 670 | lines.append(colors["green"]("✓ All services passed.")) |
| 660 | 671 | grouped: dict = {} |
| @@ -766,6 +777,8 @@ def parse_args(): |
| 766 | 777 | p.add_argument("--category", help="filter to a single category") |
| 767 | 778 | p.add_argument("--section", help="filter to a single section") |
| 768 | 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 | 782 | p.add_argument("--only", type=_csv, default=[], help="comma-separated checks to run") |
| 770 | 783 | p.add_argument("--skip", type=_csv, default=[], help="comma-separated checks to skip") |
| 771 | 784 | p.add_argument("--severity", choices=["all", "warn", "error"], default="all") |
| @@ -814,25 +827,34 @@ def main(): |
| 814 | 827 | token = args.token or os.environ.get("GITHUB_TOKEN", "") |
| 815 | 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 | 835 | if not token: |
| 818 | 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 | 838 | logging.warning( |
| 821 | | "GITHUB_TOKEN not set, skipping GitHub checks (%s). " |
| 822 | | "Export GITHUB_TOKEN to enable them.", |
| 839 | "GITHUB_TOKEN not set, skipping GitHub checks (%s) for a full review. " |
| 840 | "Export GITHUB_TOKEN, or narrow with --service/--category/--changed-since.", |
| 823 | 841 | ", ".join(gh_checks), |
| 824 | 842 | ) |
| 825 | 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 | 847 | if not api_token: |
| 828 | 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 | 850 | logging.warning( |
| 831 | | "API_TOKEN not set, skipping API checks (%s). " |
| 832 | | "Export API_TOKEN to enable them.", |
| 851 | "API_TOKEN not set, skipping API checks (%s) for a full review. " |
| 852 | "Export API_TOKEN, or narrow the review to run them.", |
| 833 | 853 | ", ".join(api_checks), |
| 834 | 854 | ) |
| 835 | 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 | 859 | if not enabled: |
| 838 | 860 | logging.error("No checks to run after filters.") |
| @@ -848,6 +870,13 @@ def main(): |
| 848 | 870 | sys.exit(2) |
| 849 | 871 | |
| 850 | 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 | 880 | if not entries: |
| 852 | 881 | logging.error("No services matched filters (category=%s, section=%s, service=%s)", |
| 853 | 882 | args.category, args.section, args.service) |