Commit addd5eb797

addd5eb79763e5fb20fedac77f5fad07ca8fadf8

parent: a6be80622e

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-03-17 13:04 UTC

Small updates to lib

Layout: unified · split

.github/workflows/pr-check.yml +8 −3
@@ -108,6 +108,8 @@ jobs:
108108 needs: data-validation
109109 if: "!cancelled() && needs.data-validation.outputs.yaml_changed == 'true'"
110110 runs-on: ubuntu-latest
111 outputs:
112 has_repo_stats: ${{ steps.repo-stats.outputs.exists }}
111113 steps:
112114 - uses: actions/checkout@v5
113115 - uses: actions/setup-python@v6
@@ -131,13 +133,16 @@ jobs:
131133 env:
132134 GITHUB_TOKEN: ${{ github.token }}
133135 run: python lib/checks/make-info-stats.py
134 - name: Upload repo stats
136 - name: Check for repo stats
135137 if: always()
138 id: repo-stats
139 run: test -f /tmp/repo-stats.md && echo "exists=true" >> "$GITHUB_OUTPUT" || echo "exists=false" >> "$GITHUB_OUTPUT"
140 - name: Upload repo stats
141 if: steps.repo-stats.outputs.exists == 'true'
136142 uses: actions/upload-artifact@v6
137143 with:
138144 name: repo-stats
139145 path: /tmp/repo-stats.md
140 if-no-files-found: ignore
141146 - name: Upload findings
142147 if: always()
143148 uses: actions/upload-artifact@v6
@@ -170,7 +175,7 @@ jobs:
170175 path: /tmp/artifacts
171176 continue-on-error: true
172177 - name: Download repo stats
173 if: needs.submission-eligibility.result == 'success'
178 if: needs.submission-eligibility.outputs.has_repo_stats == 'true'
174179 uses: actions/download-artifact@v7
175180 with:
176181 name: repo-stats
lib/checks/format-comment.py +18 −16
@@ -95,10 +95,17 @@ def format_comment(findings, user, changes_summary, run_id, repo_stats=None):
9595 f"correct and inline with our [Contributing Requirements]({CONTRIBUTING}).\n",
9696 ]
9797
98 disclaimer = "> <sup> 🤖 I am a bot, and sometimes make mistakes. "
99 disclaimer += "If you feel that any info here is incorrect or inaccurate, "
100 disclaimer += "feel free to add a comment below with any corrections or justifications. "
101 disclaimer += "This bot does <b>not</b> use AI, and just runs preliminary validation "
102 disclaimer += "checks against submission requirements. Human review is still needed.</sup>"
103
98104 if findings:
99105 bullet_list = "\n".join(f"- {f}" for f in findings)
100106 parts.append(
101107 f"Our automated checks detected some issues:\n\n{bullet_list}\n\n"
108 f"{disclaimer}\n"
102109 )
103110 else:
104111 parts.append("> \u2705 All our automated checks have passed.")
@@ -126,7 +133,7 @@ def format_comment(findings, user, changes_summary, run_id, repo_stats=None):
126133
127134def write_step_summary(errors, warnings, user, pr_number, run_id, changes_summary,
128135 repo_stats=None):
129 """Write a structured summary to GITHUB_STEP_SUMMARY."""
136 """Creates a human-readable summary of all checks, and writes to GITHUB_STEP_SUMMARY."""
130137 summary_file = os.environ.get("GITHUB_STEP_SUMMARY")
131138 if not summary_file:
132139 return
@@ -144,12 +151,11 @@ def write_step_summary(errors, warnings, user, pr_number, run_id, changes_summar
144151 )
145152 elif ne:
146153 lines.append(
147 f"There are {ne} error(s) which must be resolved before this PR can be"
148 f" reviewed.\n"
154 f"There are {ne} error(s) which must be resolved before this PR can be reviewed.\n"
149155 )
150156 elif nw:
151157 lines.append(
152 f"There were no errors but {nw} warning(s) which need to be addressed"
158 f"There were no errors but {nw} warning(s) which should to be addressed"
153159 f" or justified before the PR can be merged.\n"
154160 )
155161 else:
@@ -178,27 +184,23 @@ def write_step_summary(errors, warnings, user, pr_number, run_id, changes_summar
178184
179185 # Meta Info
180186 lines.append("### Meta Info\n")
181 now = datetime.now(timezone.utc)
182 timestamp = now.strftime("%H:%M UTC on %d %b %Y")
183 if pr_number:
184 lines.append(
185 f"This workflow run was triggered at {timestamp}"
186 f" for PR [#{pr_number}](https://github.com/Lissy93/awesome-privacy/pull/{pr_number})"
187 f" which was opened by @{user}\n"
188 )
189 else:
190 lines.append(
191 f"This workflow run was triggered at {timestamp} by @{user}\n"
192 )
187 timestamp = datetime.now(timezone.utc).strftime("%H:%M UTC on %d %b %Y")
188 pr_ref = f" for PR [#{pr_number}](https://github.com/Lissy93/awesome-privacy/pull/{pr_number})" if pr_number else ""
189 attempt = os.environ.get("GITHUB_RUN_ATTEMPT", "")
190 attempt_ref = f" (Attempt {attempt})" if attempt and attempt != "1" else ""
191 lines.append(f"This workflow was triggered at {timestamp}{pr_ref} by @{user}{attempt_ref}\n")
193192
193 # Summary of changes (what was added/removed/edited in which sections)
194194 if changes_summary:
195195 lines.append("The PR introduces the following changes:\n")
196196 lines.append(f"{changes_summary}\n")
197197
198 # Submission info (like the automated info looked up about repo, web, app, etc)
198199 if repo_stats:
199200 lines.append("### Submission Info\n")
200201 lines.append(f"{repo_stats}\n")
201202
203 # All done, write to file for outputting to workflow summary
202204 with open(summary_file, "a") as f:
203205 f.write("\n".join(lines) + "\n")
204206
lib/checks/make-info-stats.py +80 −61
@@ -30,6 +30,7 @@ import requests
3030DIFF_PATH = "/tmp/pr-diff.json"
3131OUTPUT_PATH = "/tmp/repo-stats.md"
3232TIMEOUT = 10
33MAX_SUBMISSIONS = 5
3334USER_AGENT = "awesome-privacy-ci/1.0"
3435AI_BOT_AUTHORS = [
3536 "noreply@anthropic.com",
@@ -531,7 +532,7 @@ def grade_tosdr_stats(data):
531532
532533
533534def _resolve_args(argv):
534 """Return dict with keys: owner, repo, url, android, ios, tosdr. All optional."""
535 """Return list of dicts with keys: name, owner, repo, url, android, ios, tosdr."""
535536 parser = argparse.ArgumentParser(description="Generate submission info stats")
536537 parser.add_argument("--repo", default=None, help="owner/repo")
537538 parser.add_argument("--url", default=None, help="Website URL to check")
@@ -540,17 +541,16 @@ def _resolve_args(argv):
540541 parser.add_argument("--tosdr", default=None, help="ToS;DR service ID")
541542 args = parser.parse_args(argv[1:])
542543
543 result = {"owner": None, "repo": None, "url": args.url,
544 "android": args.android, "ios": args.ios, "tosdr": args.tosdr}
545
546544 if any(vars(args).values()):
545 result = {"name": None, "owner": None, "repo": None, "url": args.url,
546 "android": args.android, "ios": args.ios, "tosdr": args.tosdr}
547547 if args.repo:
548548 owner, repo = parse_github_field(args.repo)
549549 if not owner:
550550 print(f"Invalid repo format: {args.repo}", file=sys.stderr)
551551 sys.exit(1)
552552 result["owner"], result["repo"] = owner, repo
553 return result
553 return [result]
554554
555555 # CI mode: extract from diff file
556556 try:
@@ -562,79 +562,98 @@ def _resolve_args(argv):
562562
563563 field_map = {"github": "owner", "url": "url", "androidApp": "android",
564564 "iosApp": "ios", "tosdrId": "tosdr"}
565 for svc in diff.get("services", {}).get("added", []):
565 services = []
566 for svc in diff.get("services", {}).get("added", [])[:MAX_SUBMISSIONS]:
567 result = {"name": svc.get("service"), "owner": None, "repo": None,
568 "url": None, "android": None, "ios": None, "tosdr": None}
566569 fields = svc.get("fields", {})
567570 for yaml_key, result_key in field_map.items():
568 if not result.get(result_key) and fields.get(yaml_key):
571 if fields.get(yaml_key):
569572 if yaml_key == "github":
570573 result["owner"], result["repo"] = parse_github_field(fields[yaml_key])
571574 else:
572575 result[result_key] = str(fields[yaml_key])
573 break # only first added service
576 if any(v for k, v in result.items() if k != "name"):
577 services.append(result)
574578
575 if not any(result.values()):
579 if not services:
576580 print("No checkable fields found in diff", file=sys.stderr)
577581 sys.exit(0)
578582
579 return result
583 return services
584
585
586def _build_service_sections(args, token):
587 """Build (heading, body) section tuples for a single service."""
588 sections = []
589
590 if args["owner"] and args["repo"]:
591 data = fetch_all_data(args["owner"], args["repo"], token)
592 if data:
593 sections.append(("Repo Stats", format_markdown(grade_stats(data))))
594 else:
595 print(f"Failed to fetch repo data for {args['owner']}/{args['repo']}", file=sys.stderr)
596
597 if args["url"]:
598 parsed_url = urlparse(args["url"])
599 if parsed_url.hostname and parsed_url.hostname.rstrip(".").endswith("github.com"):
600 print(f"Skipped website checks, since github repo was specified: {args['url']}", file=sys.stderr)
601 sections.append(("Website Checks",
602 f"- {ORANGE} **Skipped** web checks, since repo URL was submitted instead of a website"))
603 else:
604 site_data = fetch_website_data(args["url"])
605 has_sec_txt = check_security_txt(args["url"])
606 if site_data or has_sec_txt is not None:
607 sections.append(("Website Checks",
608 format_markdown(grade_website_stats(site_data, args["url"], has_sec_txt))))
609
610 if args["android"]:
611 data = fetch_android_data(args["android"])
612 if data:
613 sections.append(("Android App", format_markdown(grade_android_stats(data))))
614 else:
615 print(f"Failed to fetch Android data for {args['android']}", file=sys.stderr)
616
617 if args["ios"]:
618 data = fetch_ios_data(args["ios"])
619 if data:
620 sections.append(("iOS App", format_markdown(grade_ios_stats(data))))
621 else:
622 print(f"Failed to fetch iOS data for {args['ios']}", file=sys.stderr)
623
624 if args["tosdr"]:
625 data = fetch_tosdr_data(args["tosdr"])
626 if data:
627 sections.append(("Privacy Policy", format_markdown(grade_tosdr_stats(data))))
628 else:
629 print(f"Failed to fetch ToS;DR data for {args['tosdr']}", file=sys.stderr)
630
631 return sections
580632
581633
582634def main():
583635 try:
584 args = _resolve_args(sys.argv)
636 all_services = _resolve_args(sys.argv)
585637 cli_mode = len(sys.argv) > 1
586 sections = []
587
588 if args["owner"] and args["repo"]:
589 token = os.environ.get("GITHUB_TOKEN", "")
590 data = fetch_all_data(args["owner"], args["repo"], token)
591 if data:
592 sections.append(("Repo Stats", format_markdown(grade_stats(data))))
593 else:
594 print(f"Failed to fetch repo data for {args['owner']}/{args['repo']}", file=sys.stderr)
595
596 if args["url"]:
597 parsed_url = urlparse(args["url"])
598 if parsed_url.hostname and parsed_url.hostname.rstrip(".").endswith("github.com"):
599 print(f"Skipped website checks, since github repo was specified: {args['url']}", file=sys.stderr)
600 sections.append(("Website Checks",
601 f"- {ORANGE} **Skipped** web checks, since repo URL was submitted instead of a website"))
602 else:
603 site_data = fetch_website_data(args["url"])
604 has_sec_txt = check_security_txt(args["url"])
605 if site_data or has_sec_txt is not None:
606 sections.append(("Website Checks",
607 format_markdown(grade_website_stats(site_data, args["url"], has_sec_txt))))
608
609 if args["android"]:
610 data = fetch_android_data(args["android"])
611 if data:
612 sections.append(("Android App", format_markdown(grade_android_stats(data))))
613 else:
614 print(f"Failed to fetch Android data for {args['android']}", file=sys.stderr)
615
616 if args["ios"]:
617 data = fetch_ios_data(args["ios"])
618 if data:
619 sections.append(("iOS App", format_markdown(grade_ios_stats(data))))
620 else:
621 print(f"Failed to fetch iOS data for {args['ios']}", file=sys.stderr)
622
623 if args["tosdr"]:
624 data = fetch_tosdr_data(args["tosdr"])
625 if data:
626 sections.append(("Privacy Policy", format_markdown(grade_tosdr_stats(data))))
627 else:
628 print(f"Failed to fetch ToS;DR data for {args['tosdr']}", file=sys.stderr)
629
630 if not sections:
631 sys.exit(0)
638 multi = len(all_services) > 1
639 token = os.environ.get("GITHUB_TOKEN", "")
640 all_md_parts = []
632641
633 md_parts = []
634 for heading, body in sections:
635 md_parts.append(f"#### {heading}\n{body}")
636 md = "\n\n".join(md_parts)
642 for svc_args in all_services:
643 sections = _build_service_sections(svc_args, token)
644 if not sections:
645 continue
646 md_parts = []
647 if multi and svc_args.get("name"):
648 md_parts.append(f"### {svc_args['name']}")
649 for heading, body in sections:
650 md_parts.append(f"#### {heading}\n{body}")
651 all_md_parts.append("\n\n".join(md_parts))
652
653 if not all_md_parts:
654 sys.exit(0)
637655
656 md = "\n\n---\n\n".join(all_md_parts)
638657 md += "\n\n<sup>The above data does not determine a submissions eligibility. Human review is still needed.</sup>\n"
639658 md += "<sup><b>Key:</b> 🟢 = good. 🟠 = warning. 🔴 = attention required. 🔵 = info. ⚪ = unknown. </sup>\n\n"
640659
lib/readme.txt added +58
@@ -0,0 +1,58 @@
1This directory contains all the core logic and automations for awesome-privacy.
2Primarily used to process awesome-privacy, build the readme, and validate PRs.
3
4For some background, all listing data lives in awesome-privacy.yml.
5This file is the single source of truth, used to:
6- Populate the list in the readme
7- Build the pages in the website
8- Power the database for the API
9
10
11Usage
12-----
13From the root of this project, run:
14- `make install_lib_deps` for pip install
15- `make validate` to validate all data
16- `make gen_readme` to build the readme
17
18
19Scripts and Files Listing
20-------------------------
21awesome-privacy-readme-gen.py
22 > Generates and inserts readme content for all listings into the readme
23validate-awesome-privacy.py
24 > Validates awesome-privacy.yml against schema.json
25schema.json
26 > The JSON Schema defining the structure and data types of awesome-privacy.yml.
27requirements.txt
28 > Python dependencies (Just PyYAML, jsonschema and requests)
29checks/
30 > Scripts which run via GH Actions, when PRs are opened to validate submissions
31
32File listing for lib/checks/
33 detect-changes.py
34 > Checks if and what was changed in awesome-privacy.yml
35 check-readme-edits.py
36 > Sanity check to fail PRs modifying parts of the readme directly
37 check-pr-meta.py
38 > Validates PR title and body to ensure required info is specified
39 check-yaml-diff.py
40 > Diffs the base and head versions of awesome-privacy.yml, and builds an index
41 check-additions.py
42 > Validates additions against data quality rules / requirements
43 check-project.py
44 > Checks project health (URL reachability, repo health, security alerts, etc)
45 make-info-stats.py
46 > Fetches contextual info about submitted services for reviewer convenience.
47 format-comment.py
48 > Collects all findings from the three check jobs, and assembles the PR comment
49 prepare-comment.py
50 > Decides whether to create, update, or skip the bot comment on the PR.
51 check-review-ready.py
52 > Assigns maintainers to review, once all essential checks pass
53
54
55License
56-------
57Licensed under MIT © Alicia Sykes <alicia@omg.lol> 2026
58https://github.com/Lissy93/awesome-privacy/blob/main/LICENSE
\ No newline at end of file