Commit 63bdb10b41
Unsigned
Layout: unified · split
.github/workflows/pr-check.yml +18 −18
| @@ -18,9 +18,9 @@ jobs: | ||
| 18 | 18 | name: PR Compliance |
| 19 | 19 | runs-on: ubuntu-latest |
| 20 | 20 | steps: |
| 21 | - uses: actions/checkout@v4 | |
| 21 | - uses: actions/checkout@v5 | |
| 22 | 22 | - run: git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }} |
| 23 | - uses: actions/setup-python@v5 | |
| 23 | - uses: actions/setup-python@v6 | |
| 24 | 24 | with: |
| 25 | 25 | python-version: "3.12" |
| 26 | 26 | - name: Check README edits |
| @@ -38,7 +38,7 @@ jobs: | ||
| 38 | 38 | run: python lib/checks/check-pr-meta.py |
| 39 | 39 | - name: Upload findings |
| 40 | 40 | if: always() |
| 41 | uses: actions/upload-artifact@v4 | |
| 41 | uses: actions/upload-artifact@v5 | |
| 42 | 42 | with: |
| 43 | 43 | name: findings-compliance |
| 44 | 44 | path: /tmp/findings-compliance.json |
| @@ -53,9 +53,9 @@ jobs: | ||
| 53 | 53 | outputs: |
| 54 | 54 | yaml_changed: ${{ steps.changes.outputs.yaml_changed }} |
| 55 | 55 | steps: |
| 56 | - uses: actions/checkout@v4 | |
| 56 | - uses: actions/checkout@v5 | |
| 57 | 57 | - run: git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }} |
| 58 | - uses: actions/setup-python@v5 | |
| 58 | - uses: actions/setup-python@v6 | |
| 59 | 59 | with: |
| 60 | 60 | python-version: "3.12" |
| 61 | 61 | - name: Detect changes |
| @@ -83,7 +83,7 @@ jobs: | ||
| 83 | 83 | run: python lib/checks/check-additions.py |
| 84 | 84 | - name: Upload diff data |
| 85 | 85 | if: always() |
| 86 | uses: actions/upload-artifact@v4 | |
| 86 | uses: actions/upload-artifact@v5 | |
| 87 | 87 | with: |
| 88 | 88 | name: pr-diff |
| 89 | 89 | path: | |
| @@ -92,7 +92,7 @@ jobs: | ||
| 92 | 92 | if-no-files-found: ignore |
| 93 | 93 | - name: Upload findings |
| 94 | 94 | if: always() |
| 95 | uses: actions/upload-artifact@v4 | |
| 95 | uses: actions/upload-artifact@v5 | |
| 96 | 96 | with: |
| 97 | 97 | name: findings-data |
| 98 | 98 | path: /tmp/findings-data.json |
| @@ -107,13 +107,13 @@ jobs: | ||
| 107 | 107 | if: "!cancelled() && needs.data-validation.outputs.yaml_changed == 'true'" |
| 108 | 108 | runs-on: ubuntu-latest |
| 109 | 109 | steps: |
| 110 | - uses: actions/checkout@v4 | |
| 111 | - uses: actions/setup-python@v5 | |
| 110 | - uses: actions/checkout@v5 | |
| 111 | - uses: actions/setup-python@v6 | |
| 112 | 112 | with: |
| 113 | 113 | python-version: "3.12" |
| 114 | 114 | - run: pip install -q -r lib/requirements.txt |
| 115 | 115 | - name: Download diff data |
| 116 | uses: actions/download-artifact@v4 | |
| 116 | uses: actions/download-artifact@v5 | |
| 117 | 117 | with: |
| 118 | 118 | name: pr-diff |
| 119 | 119 | path: /tmp |
| @@ -131,14 +131,14 @@ jobs: | ||
| 131 | 131 | run: python lib/checks/make-info-stats.py |
| 132 | 132 | - name: Upload repo stats |
| 133 | 133 | if: always() |
| 134 | uses: actions/upload-artifact@v4 | |
| 134 | uses: actions/upload-artifact@v5 | |
| 135 | 135 | with: |
| 136 | 136 | name: repo-stats |
| 137 | 137 | path: /tmp/repo-stats.md |
| 138 | 138 | if-no-files-found: ignore |
| 139 | 139 | - name: Upload findings |
| 140 | 140 | if: always() |
| 141 | uses: actions/upload-artifact@v4 | |
| 141 | uses: actions/upload-artifact@v5 | |
| 142 | 142 | with: |
| 143 | 143 | name: findings-project |
| 144 | 144 | path: /tmp/findings-project.json |
| @@ -150,25 +150,25 @@ jobs: | ||
| 150 | 150 | needs: [pr-compliance, data-validation, submission-eligibility] |
| 151 | 151 | runs-on: ubuntu-latest |
| 152 | 152 | steps: |
| 153 | - uses: actions/checkout@v4 | |
| 154 | - uses: actions/setup-python@v5 | |
| 153 | - uses: actions/checkout@v5 | |
| 154 | - uses: actions/setup-python@v6 | |
| 155 | 155 | with: |
| 156 | 156 | python-version: "3.12" |
| 157 | 157 | - name: Download all findings |
| 158 | uses: actions/download-artifact@v4 | |
| 158 | uses: actions/download-artifact@v5 | |
| 159 | 159 | with: |
| 160 | 160 | pattern: findings-* |
| 161 | 161 | path: /tmp/artifacts |
| 162 | 162 | merge-multiple: true |
| 163 | 163 | continue-on-error: true |
| 164 | 164 | - name: Download diff data |
| 165 | uses: actions/download-artifact@v4 | |
| 165 | uses: actions/download-artifact@v5 | |
| 166 | 166 | with: |
| 167 | 167 | name: pr-diff |
| 168 | 168 | path: /tmp/artifacts |
| 169 | 169 | continue-on-error: true |
| 170 | 170 | - name: Download repo stats |
| 171 | uses: actions/download-artifact@v4 | |
| 171 | uses: actions/download-artifact@v5 | |
| 172 | 172 | with: |
| 173 | 173 | name: repo-stats |
| 174 | 174 | path: /tmp/artifacts |
| @@ -181,7 +181,7 @@ jobs: | ||
| 181 | 181 | run: python lib/checks/format-comment.py |
| 182 | 182 | - name: Upload PR metadata |
| 183 | 183 | if: always() |
| 184 | uses: actions/upload-artifact@v4 | |
| 184 | uses: actions/upload-artifact@v5 | |
| 185 | 185 | with: |
| 186 | 186 | name: pr-meta |
| 187 | 187 | path: /tmp/pr-meta/ |
.github/workflows/pr-comment.yml +43 −9
| @@ -20,12 +20,12 @@ jobs: | ||
| 20 | 20 | if: github.event.workflow_run.event == 'pull_request' |
| 21 | 21 | |
| 22 | 22 | steps: |
| 23 | - uses: actions/checkout@v4 | |
| 23 | - uses: actions/checkout@v5 | |
| 24 | 24 | |
| 25 | 25 | - name: Download PR metadata |
| 26 | 26 | id: download |
| 27 | 27 | continue-on-error: true |
| 28 | uses: actions/download-artifact@v4 | |
| 28 | uses: actions/download-artifact@v5 | |
| 29 | 29 | with: |
| 30 | 30 | name: pr-meta |
| 31 | 31 | path: pr-meta |
| @@ -34,7 +34,7 @@ jobs: | ||
| 34 | 34 | |
| 35 | 35 | - name: Resolve PR context |
| 36 | 36 | id: context |
| 37 | uses: actions/github-script@v7 | |
| 37 | uses: actions/github-script@v8 | |
| 38 | 38 | with: |
| 39 | 39 | github-token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} |
| 40 | 40 | script: | |
| @@ -95,7 +95,7 @@ jobs: | ||
| 95 | 95 | |
| 96 | 96 | - name: Post or update comment |
| 97 | 97 | if: steps.context.outputs.pr_number |
| 98 | uses: actions/github-script@v7 | |
| 98 | uses: actions/github-script@v8 | |
| 99 | 99 | with: |
| 100 | 100 | github-token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} |
| 101 | 101 | script: | |
| @@ -136,17 +136,38 @@ jobs: | ||
| 136 | 136 | console.log('Updated bot comment.'); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | // Auto-assign Lissy93 for review when appropriate (non-critical) | |
| 140 | try { | |
| 141 | const readInt = (f) => fs.existsSync(f) ? parseInt(fs.readFileSync(f, 'utf8').trim()) : NaN; | |
| 142 | const errors = readInt('pr-meta/error-count.txt'); | |
| 143 | const total = readInt('pr-meta/findings-count.txt'); | |
| 144 | const shouldAssign = | |
| 145 | (action === 'create' && errors === 0 && total === 0) || | |
| 146 | (action === 'update' && errors === 0); | |
| 147 | if (shouldAssign) { | |
| 148 | await github.rest.issues.addAssignees({ | |
| 149 | owner: context.repo.owner, | |
| 150 | repo: context.repo.repo, | |
| 151 | issue_number: prNumber, | |
| 152 | assignees: ['Lissy93'], | |
| 153 | }); | |
| 154 | console.log('Assigned Lissy93 for review.'); | |
| 155 | } | |
| 156 | } catch (err) { | |
| 157 | console.log(`Failed to auto-assign: ${err.message}`); | |
| 158 | } | |
| 159 | ||
| 139 | 160 | review-notify: |
| 140 | 161 | name: Notify maintainer |
| 141 | 162 | runs-on: ubuntu-latest |
| 142 | 163 | if: github.event_name == 'pull_request_review' |
| 143 | 164 | |
| 144 | 165 | steps: |
| 145 | - uses: actions/checkout@v4 | |
| 166 | - uses: actions/checkout@v5 | |
| 146 | 167 | |
| 147 | 168 | - name: Fetch review and CI context |
| 148 | 169 | id: context |
| 149 | uses: actions/github-script@v7 | |
| 170 | uses: actions/github-script@v8 | |
| 150 | 171 | with: |
| 151 | 172 | github-token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} |
| 152 | 173 | script: | |
| @@ -191,7 +212,7 @@ jobs: | ||
| 191 | 212 | run: python lib/checks/check-review-ready.py |
| 192 | 213 | |
| 193 | 214 | - name: Post notification |
| 194 | uses: actions/github-script@v7 | |
| 215 | uses: actions/github-script@v8 | |
| 195 | 216 | with: |
| 196 | 217 | github-token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} |
| 197 | 218 | script: | |
| @@ -212,10 +233,23 @@ jobs: | ||
| 212 | 233 | '@Lissy93 - Please evaluate, and either merge or leave feedback.', |
| 213 | 234 | ].join('\n'); |
| 214 | 235 | |
| 236 | const prNumber = parseInt('${{ steps.context.outputs.pr_number }}'); | |
| 237 | ||
| 215 | 238 | await github.rest.issues.createComment({ |
| 216 | 239 | owner: context.repo.owner, |
| 217 | 240 | repo: context.repo.repo, |
| 218 | issue_number: parseInt('${{ steps.context.outputs.pr_number }}'), | |
| 241 | issue_number: prNumber, | |
| 219 | 242 | body, |
| 220 | 243 | }); |
| 221 | console.log('Posted maintainer notification.'); | |
| 244 | ||
| 245 | // Once all checks pass, assign the PR to myself, so i get notiifcation to review | |
| 246 | try { | |
| 247 | await github.rest.issues.addAssignees({ | |
| 248 | owner: context.repo.owner, | |
| 249 | repo: context.repo.repo, | |
| 250 | issue_number: prNumber, | |
| 251 | assignees: ['Lissy93'], | |
| 252 | }); | |
| 253 | } catch (err) { | |
| 254 | console.log(`Failed to assign Lissy93: ${err.message}`); | |
| 255 | } | |
lib/checks/check-project.py +96 −19
| @@ -26,7 +26,10 @@ AI_BOT_AUTHORS = [ | ||
| 26 | 26 | "copilot-swe-agent.github.com", |
| 27 | 27 | "noreply@cursor.com", |
| 28 | 28 | ] |
| 29 | SPAM_PR_THRESHOLD = 5 | |
| 29 | SPAM_AWESOME_THRESHOLD = 3 | |
| 30 | SPAM_DISTINCT_REPO_THRESHOLD = 7 | |
| 31 | SPAM_WINDOW_DAYS = 2 | |
| 32 | NEW_ACCOUNT_DAYS = 14 | |
| 30 | 33 | |
| 31 | 34 | LINK_MSG = ( |
| 32 | 35 | "The link(s) you included seem to be returning a 404." |
| @@ -47,7 +50,8 @@ ACTIVITY_MSG = ( | ||
| 47 | 50 | ) |
| 48 | 51 | MATURITY_MSG = ( |
| 49 | 52 | "This project appears to be quite new (created less than 4 months ago)." |
| 50 | " Repositories should have a proven track record before listing." | |
| 53 | " Repositories should have a proven track record before listing," | |
| 54 | " and at least 16 weeks since first stable release." | |
| 51 | 55 | ) |
| 52 | 56 | AI_CODE_MSG = ( |
| 53 | 57 | "This project appears to contain AI-generated code." |
| @@ -62,15 +66,27 @@ LICENSE_MSG = ( | ||
| 62 | 66 | ) |
| 63 | 67 | ARCHIVED_MSG = ( |
| 64 | 68 | "The GitHub project linked has been archived." |
| 65 | " Additions must be actively maintained." | |
| 69 | " Additions must be actively maintained" | |
| 66 | 70 | ) |
| 67 | 71 | SECURITY_MSG = ( |
| 68 | 72 | "This project has open security vulnerabilities (critical or high severity)" |
| 69 | 73 | " flagged by GitHub Dependabot. Please verify these have been addressed" |
| 70 | 74 | ) |
| 71 | SPAM_MSG = ( | |
| 72 | "This user has opened up a large number of PRs to other awesome-* repos" | |
| 73 | " in the past 24 hours, and appears to be spamming" | |
| 75 | SPAM_AWESOME_MSG = ( | |
| 76 | "You have made many similar submissions on other awesome-* repos today." | |
| 77 | " Please ensure that your submission is actually a good fit for awesome-privacy" | |
| 78 | ) | |
| 79 | SPAM_MANY_MSG = ( | |
| 80 | "The submitter of this PR appears to have been previously flagged as a spammer." | |
| 81 | " Caution is needed when reviewing this PR" | |
| 82 | ) | |
| 83 | NEW_ACCOUNT_MSG = ( | |
| 84 | "This user has only just joined GitHub." | |
| 85 | " New accounts submitting to awesome lists can be a spam signal, careful review needed" | |
| 86 | ) | |
| 87 | DUPLICATE_URL_MSG = ( | |
| 88 | "The URL for this submission already exists in another listing." | |
| 89 | " Please check that this is not a duplicate entry" | |
| 74 | 90 | ) |
| 75 | 91 | |
| 76 | 92 | |
| @@ -249,37 +265,91 @@ def check_security_alerts(owner, repo, token): | ||
| 249 | 265 | |
| 250 | 266 | |
| 251 | 267 | def check_spam_prs(pr_user, token): |
| 252 | """Return SPAM_MSG if the user has opened many PRs to other awesome-* repos recently.""" | |
| 268 | """Return list of spam findings based on recent PR activity.""" | |
| 253 | 269 | if not pr_user or not token: |
| 254 | return None | |
| 270 | return [] | |
| 255 | 271 | try: |
| 256 | since = (datetime.now(timezone.utc) - timedelta(days=1)).strftime("%Y-%m-%d") | |
| 257 | headers = {"Accept": "application/vnd.github.v3+json", "User-Agent": USER_AGENT} | |
| 258 | headers["Authorization"] = f"token {token}" | |
| 272 | since = (datetime.now(timezone.utc) - timedelta(days=SPAM_WINDOW_DAYS)).strftime("%Y-%m-%d") | |
| 273 | headers = { | |
| 274 | "Accept": "application/vnd.github.v3+json", | |
| 275 | "User-Agent": USER_AGENT, | |
| 276 | "Authorization": f"token {token}", | |
| 277 | } | |
| 259 | 278 | resp = requests.get( |
| 260 | 279 | "https://api.github.com/search/issues", |
| 261 | 280 | headers=headers, timeout=TIMEOUT, |
| 262 | 281 | params={"q": f"type:pr author:{pr_user} created:>={since}"}, |
| 263 | 282 | ) |
| 264 | 283 | if resp.status_code != 200: |
| 265 | return None | |
| 284 | return [] | |
| 266 | 285 | items = resp.json().get("items", []) |
| 267 | 286 | this_repo = os.environ.get("GITHUB_REPOSITORY", "Lissy93/awesome-privacy").lower() |
| 268 | count = 0 | |
| 287 | awesome_count = 0 | |
| 288 | distinct_repos = set() | |
| 269 | 289 | for item in items: |
| 270 | 290 | repo_url = item.get("repository_url", "") |
| 271 | 291 | # repository_url looks like https://api.github.com/repos/owner/repo-name |
| 272 | 292 | repo_full = "/".join(repo_url.rstrip("/").split("/")[-2:]).lower() |
| 293 | if repo_full == this_repo: | |
| 294 | continue | |
| 295 | distinct_repos.add(repo_full) | |
| 273 | 296 | repo_name = repo_url.rstrip("/").split("/")[-1].lower() |
| 274 | if repo_name.startswith("awesome-") and repo_full != this_repo: | |
| 275 | count += 1 | |
| 276 | if count >= SPAM_PR_THRESHOLD: | |
| 277 | return SPAM_MSG | |
| 297 | if repo_name.startswith("awesome-"): | |
| 298 | awesome_count += 1 | |
| 299 | findings = [] | |
| 300 | if awesome_count >= SPAM_AWESOME_THRESHOLD: | |
| 301 | findings.append(SPAM_AWESOME_MSG) | |
| 302 | if len(distinct_repos) >= SPAM_DISTINCT_REPO_THRESHOLD: | |
| 303 | findings.append(SPAM_MANY_MSG) | |
| 304 | return findings | |
| 305 | except Exception: | |
| 306 | return [] | |
| 307 | ||
| 308 | ||
| 309 | def check_new_account(pr_user, token): | |
| 310 | """Return NEW_ACCOUNT_MSG if the PR author's GitHub account is very new.""" | |
| 311 | if not pr_user or not token: | |
| 312 | return None | |
| 313 | try: | |
| 314 | headers = {"Accept": "application/vnd.github.v3+json", "User-Agent": USER_AGENT} | |
| 315 | headers["Authorization"] = f"token {token}" | |
| 316 | resp = requests.get( | |
| 317 | f"https://api.github.com/users/{pr_user}", | |
| 318 | headers=headers, timeout=TIMEOUT, | |
| 319 | ) | |
| 320 | if resp.status_code != 200: | |
| 321 | return None | |
| 322 | created = resp.json().get("created_at") | |
| 323 | if not created: | |
| 324 | return None | |
| 325 | created_dt = datetime.fromisoformat(created.replace("Z", "+00:00")) | |
| 326 | if (datetime.now(timezone.utc) - created_dt).days < NEW_ACCOUNT_DAYS: | |
| 327 | return NEW_ACCOUNT_MSG | |
| 278 | 328 | except Exception: |
| 279 | 329 | pass |
| 280 | 330 | return None |
| 281 | 331 | |
| 282 | 332 | |
| 333 | def check_duplicate_urls(diff, head): | |
| 334 | """Return DUPLICATE_URL_MSG if an added service's URL already exists in the YAML.""" | |
| 335 | if not head: | |
| 336 | return None | |
| 337 | # Count how many times each URL appears in the head YAML | |
| 338 | url_counts = {} | |
| 339 | for cat in head.get("categories", []): | |
| 340 | for sec in cat.get("sections", []): | |
| 341 | for svc in sec.get("services", []): | |
| 342 | url = svc.get("url", "").rstrip("/").lower() | |
| 343 | if url: | |
| 344 | url_counts[url] = url_counts.get(url, 0) + 1 | |
| 345 | # The added service is in head already, so a count > 1 means a duplicate exists | |
| 346 | for svc in get_services(diff, "added"): | |
| 347 | url = svc.get("fields", {}).get("url", "").rstrip("/").lower() | |
| 348 | if url and url_counts.get(url, 0) > 1: | |
| 349 | return DUPLICATE_URL_MSG | |
| 350 | return None | |
| 351 | ||
| 352 | ||
| 283 | 353 | _DISCLOSURE_RE = re.compile( |
| 284 | 354 | r"i am the author|i'm the author|my project|i created|i develop" |
| 285 | 355 | r"|i maintain|i built|my own project|i made|author of|maintainer of", |
| @@ -383,11 +453,18 @@ def main(): | ||
| 383 | 453 | pr_user = os.environ.get("PR_USER", "") |
| 384 | 454 | pr_body = os.environ.get("PR_BODY", "") |
| 385 | 455 | token = os.environ.get("GITHUB_TOKEN", "") |
| 386 | findings.extend(check_repo_signals(diff, pr_user, token, pr_body)) | |
| 387 | 456 | |
| 388 | finding = check_spam_prs(pr_user, token) | |
| 457 | findings.extend(check_spam_prs(pr_user, token)) | |
| 458 | ||
| 459 | finding = check_new_account(pr_user, token) | |
| 389 | 460 | if finding: |
| 390 | 461 | findings.append(finding) |
| 462 | ||
| 463 | finding = check_duplicate_urls(diff, head) | |
| 464 | if finding: | |
| 465 | findings.append(finding) | |
| 466 | ||
| 467 | findings.extend(check_repo_signals(diff, pr_user, token, pr_body)) | |
| 391 | 468 | except Exception: |
| 392 | 469 | pass |
| 393 | 470 | |
lib/checks/check-yaml-diff.py −17
| @@ -156,22 +156,6 @@ def write_diff_summary(diff_result): | ||
| 156 | 156 | f.write("\n".join(bullets) + "\n") |
| 157 | 157 | |
| 158 | 158 | |
| 159 | def write_step_summary(diff_result): | |
| 160 | """Write a bullet-point Markdown summary to $GITHUB_STEP_SUMMARY.""" | |
| 161 | summary_file = os.environ.get("GITHUB_STEP_SUMMARY") | |
| 162 | if not summary_file: | |
| 163 | return | |
| 164 | ||
| 165 | bullets = format_diff_bullets(diff_result) | |
| 166 | lines = ["## YAML Diff Analysis\n"] | |
| 167 | if bullets: | |
| 168 | lines.extend(bullets) | |
| 169 | else: | |
| 170 | lines.append("No changes detected in `awesome-privacy.yml`.") | |
| 171 | ||
| 172 | with open(summary_file, "a") as f: | |
| 173 | f.write("\n".join(lines) + "\n") | |
| 174 | ||
| 175 | 159 | |
| 176 | 160 | def main(): |
| 177 | 161 | parser = argparse.ArgumentParser() |
| @@ -227,7 +211,6 @@ def main(): | ||
| 227 | 211 | json.dump(diff_result, f, indent=2) |
| 228 | 212 | |
| 229 | 213 | write_github_output("has_service_changes", str(bool(added or removed or modified)).lower()) |
| 230 | write_step_summary(diff_result) | |
| 231 | 214 | write_diff_summary(diff_result) |
| 232 | 215 | |
| 233 | 216 | added_count = len(added) |
lib/checks/format-comment.py +5 −2
| @@ -179,7 +179,8 @@ def write_step_summary(errors, warnings, user, pr_number, run_id, changes_summar | ||
| 179 | 179 | if pr_number: |
| 180 | 180 | lines.append( |
| 181 | 181 | f"This workflow run was triggered at {timestamp}" |
| 182 | f" for PR #{pr_number} which was opened by @{user}\n" | |
| 182 | f" for PR [#{pr_number}](https://github.com/Lissy93/awesome-privacy/pull/{pr_number})" | |
| 183 | f" which was opened by @{user}\n" | |
| 183 | 184 | ) |
| 184 | 185 | else: |
| 185 | 186 | lines.append( |
| @@ -191,7 +192,7 @@ def write_step_summary(errors, warnings, user, pr_number, run_id, changes_summar | ||
| 191 | 192 | lines.append(f"{changes_summary}\n") |
| 192 | 193 | |
| 193 | 194 | if repo_stats: |
| 194 | lines.append("#### Submission Info\n") | |
| 195 | lines.append("### Submission Info\n") | |
| 195 | 196 | lines.append(f"{repo_stats}\n") |
| 196 | 197 | |
| 197 | 198 | with open(summary_file, "a") as f: |
| @@ -217,6 +218,8 @@ def main(): | ||
| 217 | 218 | all_findings = errors + warnings |
| 218 | 219 | with open(os.path.join(OUTPUT_DIR, "findings-count.txt"), "w") as f: |
| 219 | 220 | f.write(str(len(all_findings))) |
| 221 | with open(os.path.join(OUTPUT_DIR, "error-count.txt"), "w") as f: | |
| 222 | f.write(str(len(errors))) | |
| 220 | 223 | changes_summary = load_diff_summary() |
| 221 | 224 | changes_bullets = _extract_changes_bullets(changes_summary) |
| 222 | 225 | repo_stats = load_repo_stats() |
lib/checks/make-info-stats.py +10 −4
| @@ -591,11 +591,17 @@ def main(): | ||
| 591 | 591 | print(f"Failed to fetch repo data for {args['owner']}/{args['repo']}", file=sys.stderr) |
| 592 | 592 | |
| 593 | 593 | if args["url"]: |
| 594 | site_data = fetch_website_data(args["url"]) | |
| 595 | has_sec_txt = check_security_txt(args["url"]) | |
| 596 | if site_data or has_sec_txt is not None: | |
| 594 | parsed_url = urlparse(args["url"]) | |
| 595 | if parsed_url.hostname and parsed_url.hostname.rstrip(".").endswith("github.com"): | |
| 596 | print(f"Skipped website checks, since github repo was specified: {args['url']}", file=sys.stderr) | |
| 597 | 597 | sections.append(("Website Checks", |
| 598 | format_markdown(grade_website_stats(site_data, args["url"], has_sec_txt)))) | |
| 598 | f"- {ORANGE} **Skipped** web checks, since repo URL was submitted instead of a website")) | |
| 599 | else: | |
| 600 | site_data = fetch_website_data(args["url"]) | |
| 601 | has_sec_txt = check_security_txt(args["url"]) | |
| 602 | if site_data or has_sec_txt is not None: | |
| 603 | sections.append(("Website Checks", | |
| 604 | format_markdown(grade_website_stats(site_data, args["url"], has_sec_txt)))) | |
| 599 | 605 | |
| 600 | 606 | if args["android"]: |
| 601 | 607 | data = fetch_android_data(args["android"]) |
lib/checks/prepare-comment.py +40 −5
| @@ -70,6 +70,35 @@ def _extract_pr_author(existing_body): | ||
| 70 | 70 | return match.group(1) if match else None |
| 71 | 71 | |
| 72 | 72 | |
| 73 | _SUBMISSION_INFO_RE = re.compile( | |
| 74 | r"<details><summary>Submission Info</summary>\s*\n.*?</details>", | |
| 75 | re.DOTALL, | |
| 76 | ) | |
| 77 | ||
| 78 | ||
| 79 | def _extract_submission_info(body): | |
| 80 | """Extract the Submission Info <details> block, or None if absent.""" | |
| 81 | match = _SUBMISSION_INFO_RE.search(body) | |
| 82 | return match.group(0) if match else None | |
| 83 | ||
| 84 | ||
| 85 | def _refresh_submission_info(existing_body, new_body): | |
| 86 | """Replace or insert the Submission Info block from new_body into existing_body.""" | |
| 87 | new_block = _extract_submission_info(new_body) | |
| 88 | if not new_block: | |
| 89 | return existing_body | |
| 90 | old_block = _extract_submission_info(existing_body) | |
| 91 | if old_block: | |
| 92 | if old_block == new_block: | |
| 93 | return existing_body | |
| 94 | return existing_body.replace(old_block, new_block) | |
| 95 | # No existing block — insert before Updates section or workflow run link | |
| 96 | for anchor in ("---\n\n### Updates", "<sup>For full details"): | |
| 97 | if anchor in existing_body: | |
| 98 | return existing_body.replace(anchor, new_block + "\n\n" + anchor, 1) | |
| 99 | return existing_body.rstrip() + "\n\n" + new_block | |
| 100 | ||
| 101 | ||
| 73 | 102 | def build_edit_line(existing_body, findings_count, check_run_id, repo): |
| 74 | 103 | """Build the edit line to append, or None if nothing to do.""" |
| 75 | 104 | run_tag = f"<!-- run:{check_run_id} -->" |
| @@ -154,14 +183,20 @@ def main(): | ||
| 154 | 183 | findings_count = read_findings_count(new_body) |
| 155 | 184 | edit_line = build_edit_line(existing_body, findings_count, check_run_id, repo) |
| 156 | 185 | |
| 157 | if not edit_line: | |
| 186 | # Refresh the Submission Info block even if findings haven't changed | |
| 187 | refreshed_body = _refresh_submission_info(existing_body, new_body) | |
| 188 | info_changed = refreshed_body != existing_body | |
| 189 | ||
| 190 | if not edit_line and not info_changed: | |
| 158 | 191 | write_output("skip") |
| 159 | 192 | return |
| 160 | 193 | |
| 161 | if "### Updates" in existing_body: | |
| 162 | updated = existing_body.rstrip() + "\n" + edit_line | |
| 163 | else: | |
| 164 | updated = existing_body.rstrip() + "\n\n---\n\n### Updates\n\n" + edit_line | |
| 194 | updated = refreshed_body | |
| 195 | if edit_line: | |
| 196 | if "### Updates" in updated: | |
| 197 | updated = updated.rstrip() + "\n" + edit_line | |
| 198 | else: | |
| 199 | updated = updated.rstrip() + "\n\n---\n\n### Updates\n\n" + edit_line | |
| 165 | 200 | write_output("update", updated) |
| 166 | 201 | |
| 167 | 202 | |