| @@ -19,6 +19,8 @@ DIFF_PATH = "/tmp/pr-diff.json" |
| 19 | FINDINGS_PATH = "/tmp/findings-data.json" |
19 | FINDINGS_PATH = "/tmp/findings-data.json" |
| 20 | SCHEMA_ERRORS_PATH = "/tmp/schema-errors.json" |
20 | SCHEMA_ERRORS_PATH = "/tmp/schema-errors.json" |
| 21 | MAX_SCHEMA_ERRORS_SHOWN = 10 |
21 | MAX_SCHEMA_ERRORS_SHOWN = 10 |
| |
22 | MAX_REMOVED_LISTINGS = 5 |
| |
23 | MAX_MODIFIED_LISTINGS = 10 |
| 22 | |
24 | |
| 23 | REQUIRED_FIELDS = ("name", "description", "url", "icon") |
25 | REQUIRED_FIELDS = ("name", "description", "url", "icon") |
| 24 | REPO_FIELDS = ("github", "codeberg", "git") |
26 | REPO_FIELDS = ("github", "codeberg", "git") |
| @@ -31,6 +33,12 @@ SCHEMA_MSG = ( |
| 31 | " additional and that it is following valid YAML syntax" |
33 | " additional and that it is following valid YAML syntax" |
| 32 | ) |
34 | ) |
| 33 | MULTIPLE_MSG = "Please make just one addition per pull request" |
35 | MULTIPLE_MSG = "Please make just one addition per pull request" |
| |
36 | MASS_CHANGE_MSG = ( |
| |
37 | "This PR removes {removed} and modifies {modified} existing listings." |
| |
38 | " Please revert any changes which are unrelated to your submission." |
| |
39 | " This usually happens when `awesome-privacy.yml` has been accidentally" |
| |
40 | " truncated or overwritten with an outdated copy" |
| |
41 | ) |
| 34 | MISSING_TPL = ( |
42 | MISSING_TPL = ( |
| 35 | "Did you include all required fields? Looks like {fields} is missing or" |
43 | "Did you include all required fields? Looks like {fields} is missing or" |
| 36 | f" invalid. Please see the [required fields]({CONTRIBUTING}#service-fields)" |
44 | f" invalid. Please see the [required fields]({CONTRIBUTING}#service-fields)" |
| @@ -165,6 +173,16 @@ def check_single_entry(diff): |
| 165 | return None |
173 | return None |
| 166 | |
174 | |
| 167 | |
175 | |
| |
176 | def check_mass_changes(diff): |
| |
177 | """Return a finding if the diff removes or modifies too many existing services.""" |
| |
178 | services = diff.get("services", {}) |
| |
179 | removed = len(services.get("removed", [])) |
| |
180 | modified = len(services.get("modified", [])) |
| |
181 | if removed > MAX_REMOVED_LISTINGS or modified > MAX_MODIFIED_LISTINGS: |
| |
182 | return MASS_CHANGE_MSG.format(removed=removed, modified=modified) |
| |
183 | return None |
| |
184 | |
| |
185 | |
| 168 | def _added_keys(diff): |
186 | def _added_keys(diff): |
| 169 | """Build a set of (category, section, lowercase_name) for added services.""" |
187 | """Build a set of (category, section, lowercase_name) for added services.""" |
| 170 | keys = set() |
188 | keys = set() |
| @@ -297,6 +315,7 @@ def main(): |
| 297 | |
315 | |
| 298 | checks = [ |
316 | checks = [ |
| 299 | ("single-entry", check_single_entry(diff), False), |
317 | ("single-entry", check_single_entry(diff), False), |
| |
318 | ("mass-changes", check_mass_changes(diff), True), |
| 300 | ("required-fields", check_required_fields(diff, head), True), |
319 | ("required-fields", check_required_fields(diff, head), True), |
| 301 | ("position", check_position(diff, head), False), |
320 | ("position", check_position(diff, head), False), |
| 302 | ("open-source", check_open_source(diff), False), |
321 | ("open-source", check_open_source(diff), False), |