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:
108 needs: data-validation 108 needs: data-validation
109 if: "!cancelled() && needs.data-validation.outputs.yaml_changed == 'true'" 109 if: "!cancelled() && needs.data-validation.outputs.yaml_changed == 'true'"
110 runs-on: ubuntu-latest 110 runs-on: ubuntu-latest
111 outputs:
112 has_repo_stats: ${{ steps.repo-stats.outputs.exists }}
111 steps: 113 steps:
112 - uses: actions/checkout@v5 114 - uses: actions/checkout@v5
113 - uses: actions/setup-python@v6 115 - uses: actions/setup-python@v6
@@ -131,13 +133,16 @@ jobs:
131 env: 133 env:
132 GITHUB_TOKEN: ${{ github.token }} 134 GITHUB_TOKEN: ${{ github.token }}
133 run: python lib/checks/make-info-stats.py 135 run: python lib/checks/make-info-stats.py
134 - name: Upload repo stats 136 - name: Check for repo stats
135 if: always() 137 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'
136 uses: actions/upload-artifact@v6 142 uses: actions/upload-artifact@v6
137 with: 143 with:
138 name: repo-stats 144 name: repo-stats
139 path: /tmp/repo-stats.md 145 path: /tmp/repo-stats.md
140 if-no-files-found: ignore
141 - name: Upload findings 146 - name: Upload findings
142 if: always() 147 if: always()
143 uses: actions/upload-artifact@v6 148 uses: actions/upload-artifact@v6
@@ -170,7 +175,7 @@ jobs:
170 path: /tmp/artifacts 175 path: /tmp/artifacts
171 continue-on-error: true 176 continue-on-error: true
172 - name: Download repo stats 177 - name: Download repo stats
173 if: needs.submission-eligibility.result == 'success' 178 if: needs.submission-eligibility.outputs.has_repo_stats == 'true'
174 uses: actions/download-artifact@v7 179 uses: actions/download-artifact@v7
175 with: 180 with:
176 name: repo-stats 181 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):
95 f"correct and inline with our [Contributing Requirements]({CONTRIBUTING}).\n", 95 f"correct and inline with our [Contributing Requirements]({CONTRIBUTING}).\n",
96 ] 96 ]
97 97
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
98 if findings: 104 if findings:
99 bullet_list = "\n".join(f"- {f}" for f in findings) 105 bullet_list = "\n".join(f"- {f}" for f in findings)
100 parts.append( 106 parts.append(
101 f"Our automated checks detected some issues:\n\n{bullet_list}\n\n" 107 f"Our automated checks detected some issues:\n\n{bullet_list}\n\n"
108 f"{disclaimer}\n"
102 ) 109 )
103 else: 110 else:
104 parts.append("> \u2705 All our automated checks have passed.") 111 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):
126 133
127def write_step_summary(errors, warnings, user, pr_number, run_id, changes_summary, 134def write_step_summary(errors, warnings, user, pr_number, run_id, changes_summary,
128 repo_stats=None): 135 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."""
130 summary_file = os.environ.get("GITHUB_STEP_SUMMARY") 137 summary_file = os.environ.get("GITHUB_STEP_SUMMARY")
131 if not summary_file: 138 if not summary_file:
132 return 139 return
@@ -144,12 +151,11 @@ def write_step_summary(errors, warnings, user, pr_number, run_id, changes_summar
144 ) 151 )
145 elif ne: 152 elif ne:
146 lines.append( 153 lines.append(
147 f"There are {ne} error(s) which must be resolved before this PR can be" 154 f"There are {ne} error(s) which must be resolved before this PR can be reviewed.\n"
148 f" reviewed.\n"
149 ) 155 )
150 elif nw: 156 elif nw:
151 lines.append( 157 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"
153 f" or justified before the PR can be merged.\n" 159 f" or justified before the PR can be merged.\n"
154 ) 160 )
155 else: 161 else:
@@ -178,27 +184,23 @@ def write_step_summary(errors, warnings, user, pr_number, run_id, changes_summar
178 184
179 # Meta Info 185 # Meta Info
180 lines.append("### Meta Info\n") 186 lines.append("### Meta Info\n")
181 now = datetime.now(timezone.utc) 187 timestamp = datetime.now(timezone.utc).strftime("%H:%M UTC on %d %b %Y")
182 timestamp = now.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 ""
183 if pr_number: 189 attempt = os.environ.get("GITHUB_RUN_ATTEMPT", "")
184 lines.append( 190 attempt_ref = f" (Attempt {attempt})" if attempt and attempt != "1" else ""
185 f"This workflow run was triggered at {timestamp}" 191 lines.append(f"This workflow was triggered at {timestamp}{pr_ref} by @{user}{attempt_ref}\n")
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 )
193 192
193 # Summary of changes (what was added/removed/edited in which sections)
194 if changes_summary: 194 if changes_summary:
195 lines.append("The PR introduces the following changes:\n") 195 lines.append("The PR introduces the following changes:\n")
196 lines.append(f"{changes_summary}\n") 196 lines.append(f"{changes_summary}\n")
197 197
198 # Submission info (like the automated info looked up about repo, web, app, etc)
198 if repo_stats: 199 if repo_stats:
199 lines.append("### Submission Info\n") 200 lines.append("### Submission Info\n")
200 lines.append(f"{repo_stats}\n") 201 lines.append(f"{repo_stats}\n")
201 202
203 # All done, write to file for outputting to workflow summary
202 with open(summary_file, "a") as f: 204 with open(summary_file, "a") as f:
203 f.write("\n".join(lines) + "\n") 205 f.write("\n".join(lines) + "\n")
204 206
lib/checks/make-info-stats.py +80 −61
@@ -30,6 +30,7 @@ import requests
30DIFF_PATH = "/tmp/pr-diff.json" 30DIFF_PATH = "/tmp/pr-diff.json"
31OUTPUT_PATH = "/tmp/repo-stats.md" 31OUTPUT_PATH = "/tmp/repo-stats.md"
32TIMEOUT = 10 32TIMEOUT = 10
33MAX_SUBMISSIONS = 5
33USER_AGENT = "awesome-privacy-ci/1.0" 34USER_AGENT = "awesome-privacy-ci/1.0"
34AI_BOT_AUTHORS = [ 35AI_BOT_AUTHORS = [
35 "noreply@anthropic.com", 36 "noreply@anthropic.com",
@@ -531,7 +532,7 @@ def grade_tosdr_stats(data):
531 532
532 533
533def _resolve_args(argv): 534def _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."""
535 parser = argparse.ArgumentParser(description="Generate submission info stats") 536 parser = argparse.ArgumentParser(description="Generate submission info stats")
536 parser.add_argument("--repo", default=None, help="owner/repo") 537 parser.add_argument("--repo", default=None, help="owner/repo")
537 parser.add_argument("--url", default=None, help="Website URL to check") 538 parser.add_argument("--url", default=None, help="Website URL to check")
@@ -540,17 +541,16 @@ def _resolve_args(argv):
540 parser.add_argument("--tosdr", default=None, help="ToS;DR service ID") 541 parser.add_argument("--tosdr", default=None, help="ToS;DR service ID")
541 args = parser.parse_args(argv[1:]) 542 args = parser.parse_args(argv[1:])
542 543
543 result = {"owner": None, "repo": None, "url": args.url,
544 "android": args.android, "ios": args.ios, "tosdr": args.tosdr}
545
546 if any(vars(args).values()): 544 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}
547 if args.repo: 547 if args.repo:
548 owner, repo = parse_github_field(args.repo) 548 owner, repo = parse_github_field(args.repo)
549 if not owner: 549 if not owner:
550 print(f"Invalid repo format: {args.repo}", file=sys.stderr) 550 print(f"Invalid repo format: {args.repo}", file=sys.stderr)
551 sys.exit(1) 551 sys.exit(1)
552 result["owner"], result["repo"] = owner, repo 552 result["owner"], result["repo"] = owner, repo
553 return result 553 return [result]
554 554
555 # CI mode: extract from diff file 555 # CI mode: extract from diff file
556 try: 556 try:
@@ -562,79 +562,98 @@ def _resolve_args(argv):
562 562
563 field_map = {"github": "owner", "url": "url", "androidApp": "android", 563 field_map = {"github": "owner", "url": "url", "androidApp": "android",
564 "iosApp": "ios", "tosdrId": "tosdr"} 564 "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}
566 fields = svc.get("fields", {}) 569 fields = svc.get("fields", {})
567 for yaml_key, result_key in field_map.items(): 570 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):
569 if yaml_key == "github": 572 if yaml_key == "github":
570 result["owner"], result["repo"] = parse_github_field(fields[yaml_key]) 573 result["owner"], result["repo"] = parse_github_field(fields[yaml_key])
571 else: 574 else:
572 result[result_key] = str(fields[yaml_key]) 575 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)
574 578
575 if not any(result.values()): 579 if not services:
576 print("No checkable fields found in diff", file=sys.stderr) 580 print("No checkable fields found in diff", file=sys.stderr)
577 sys.exit(0) 581 sys.exit(0)
578 582
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
580 632
581 633
582def main(): 634def main():
583 try: 635 try:
584 args = _resolve_args(sys.argv) 636 all_services = _resolve_args(sys.argv)
585 cli_mode = len(sys.argv) > 1 637 cli_mode = len(sys.argv) > 1
586 sections = [] 638 multi = len(all_services) > 1
587 639 token = os.environ.get("GITHUB_TOKEN", "")
588 if args["owner"] and args["repo"]: 640 all_md_parts = []
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)
632 641
633 md_parts = [] 642 for svc_args in all_services:
634 for heading, body in sections: 643 sections = _build_service_sections(svc_args, token)
635 md_parts.append(f"#### {heading}\n{body}") 644 if not sections:
636 md = "\n\n".join(md_parts) 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)
637 655
656 md = "\n\n---\n\n".join(all_md_parts)
638 md += "\n\n<sup>The above data does not determine a submissions eligibility. Human review is still needed.</sup>\n" 657 md += "\n\n<sup>The above data does not determine a submissions eligibility. Human review is still needed.</sup>\n"
639 md += "<sup><b>Key:</b> 🟢 = good. 🟠 = warning. 🔴 = attention required. 🔵 = info. ⚪ = unknown. </sup>\n\n" 658 md += "<sup><b>Key:</b> 🟢 = good. 🟠 = warning. 🔴 = attention required. 🔵 = info. ⚪ = unknown. </sup>\n\n"
640 659
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