Commit acd153fd22
Unsigned
Layout: unified · split
.github/workflows/pr-comment.yml +26 −32
| @@ -26,7 +26,7 @@ jobs: | ||
| 26 | 26 | run-id: ${{ github.event.workflow_run.id }} |
| 27 | 27 | github-token: ${{ secrets.GITHUB_TOKEN }} |
| 28 | 28 | |
| 29 | - name: Post or update comment | |
| 29 | - name: Post comment | |
| 30 | 30 | uses: actions/github-script@v7 |
| 31 | 31 | with: |
| 32 | 32 | github-token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} |
| @@ -34,12 +34,20 @@ jobs: | ||
| 34 | 34 | const fs = require('fs'); |
| 35 | 35 | const marker = '<!-- pr-check-bot -->'; |
| 36 | 36 | |
| 37 | // Check if there are findings to post | |
| 38 | const commentFile = 'pr-meta/comment.md'; | |
| 39 | if (!fs.existsSync(commentFile)) { | |
| 40 | console.log('No findings to post — skipping.'); | |
| 41 | return; | |
| 42 | } | |
| 43 | ||
| 37 | 44 | // Determine the PR number |
| 38 | 45 | let prNumber; |
| 39 | 46 | const numberFile = 'pr-meta/number.txt'; |
| 40 | 47 | if (fs.existsSync(numberFile)) { |
| 41 | 48 | prNumber = parseInt(fs.readFileSync(numberFile, 'utf8').trim()); |
| 42 | } else { | |
| 49 | } | |
| 50 | if (!prNumber) { | |
| 43 | 51 | // workflow_run.pull_requests is empty for fork PRs, so |
| 44 | 52 | // fall back to searching by head SHA if needed |
| 45 | 53 | const prs = context.payload.workflow_run.pull_requests; |
| @@ -53,48 +61,34 @@ jobs: | ||
| 53 | 61 | state: 'open', |
| 54 | 62 | sort: 'updated', |
| 55 | 63 | direction: 'desc', |
| 56 | per_page: 10, | |
| 64 | per_page: 100, | |
| 57 | 65 | }); |
| 58 | 66 | const match = prList.find(pr => pr.head.sha === headSha); |
| 59 | 67 | if (!match) { |
| 60 | console.log(`No open PR found for SHA ${headSha} — skipping comment.`); | |
| 68 | console.log(`No open PR found for SHA ${headSha} — skipping.`); | |
| 61 | 69 | return; |
| 62 | 70 | } |
| 63 | 71 | prNumber = match.number; |
| 64 | 72 | } |
| 65 | 73 | } |
| 66 | 74 | |
| 67 | // Find existing bot comment | |
| 75 | // Skip if we already commented on this PR | |
| 68 | 76 | const { data: comments } = await github.rest.issues.listComments({ |
| 69 | 77 | owner: context.repo.owner, |
| 70 | 78 | repo: context.repo.repo, |
| 71 | 79 | issue_number: prNumber, |
| 80 | per_page: 100, | |
| 72 | 81 | }); |
| 73 | const existing = comments.find(c => c.body.includes(marker)); | |
| 74 | ||
| 75 | const commentFile = 'pr-meta/comment.md'; | |
| 76 | if (fs.existsSync(commentFile)) { | |
| 77 | const body = fs.readFileSync(commentFile, 'utf8').trim(); | |
| 78 | if (existing) { | |
| 79 | await github.rest.issues.updateComment({ | |
| 80 | owner: context.repo.owner, | |
| 81 | repo: context.repo.repo, | |
| 82 | comment_id: existing.id, | |
| 83 | body, | |
| 84 | }); | |
| 85 | } else { | |
| 86 | await github.rest.issues.createComment({ | |
| 87 | owner: context.repo.owner, | |
| 88 | repo: context.repo.repo, | |
| 89 | issue_number: prNumber, | |
| 90 | body, | |
| 91 | }); | |
| 92 | } | |
| 93 | } else if (existing) { | |
| 94 | // No findings — remove stale comment | |
| 95 | await github.rest.issues.deleteComment({ | |
| 96 | owner: context.repo.owner, | |
| 97 | repo: context.repo.repo, | |
| 98 | comment_id: existing.id, | |
| 99 | }); | |
| 82 | if (comments.some(c => c.body.includes(marker))) { | |
| 83 | console.log('Bot comment already exists — skipping.'); | |
| 84 | return; | |
| 100 | 85 | } |
| 86 | ||
| 87 | // Post the comment | |
| 88 | const body = fs.readFileSync(commentFile, 'utf8').trim(); | |
| 89 | await github.rest.issues.createComment({ | |
| 90 | owner: context.repo.owner, | |
| 91 | repo: context.repo.repo, | |
| 92 | issue_number: prNumber, | |
| 93 | body, | |
| 94 | }); | |
lib/checks/__pycache__/check-links.cpython-310.pyc deleted
Binary file not shown.
lib/checks/__pycache__/check-readme-edits.cpython-310.pyc deleted
Binary file not shown.
lib/checks/__pycache__/check-template.cpython-310.pyc deleted
Binary file not shown.
lib/checks/__pycache__/check-yaml-diff.cpython-310.pyc deleted
Binary file not shown.
lib/checks/__pycache__/detect-changes.cpython-310.pyc deleted
Binary file not shown.
lib/checks/__pycache__/warn-non-yaml.cpython-310.pyc deleted
Binary file not shown.
lib/checks/check-additions.py +6 −9
| @@ -86,12 +86,13 @@ def check_required_fields(diff, head): | ||
| 86 | 86 | for svc in diff.get("services", {}).get("modified", []): |
| 87 | 87 | if not head: |
| 88 | 88 | continue |
| 89 | changed = svc.get("changed_fields", []) | |
| 89 | 90 | fields = find_service_fields( |
| 90 | 91 | head, svc["category"], svc["section"], svc["service"] |
| 91 | 92 | ) |
| 92 | 93 | if fields: |
| 93 | 94 | for f in REQUIRED_FIELDS: |
| 94 | if not fields.get(f): | |
| 95 | if f in changed and not fields.get(f): | |
| 95 | 96 | missing.add(f) |
| 96 | 97 | if missing: |
| 97 | 98 | names = ", ".join(f"`{f}`" for f in sorted(missing)) |
| @@ -120,16 +121,12 @@ def check_open_source(diff): | ||
| 120 | 121 | |
| 121 | 122 | |
| 122 | 123 | def check_single_entry(diff): |
| 123 | """Return a finding if the diff contains multiple service or section changes.""" | |
| 124 | """Return a finding if the diff adds multiple new services or sections.""" | |
| 124 | 125 | services = diff.get("services", {}) |
| 125 | svc_count = ( | |
| 126 | len(services.get("added", [])) | |
| 127 | + len(services.get("removed", [])) | |
| 128 | + len(services.get("modified", [])) | |
| 129 | ) | |
| 130 | if svc_count > 1: | |
| 126 | added_count = len(services.get("added", [])) | |
| 127 | if added_count > 1: | |
| 131 | 128 | return MULTIPLE_MSG |
| 132 | if svc_count == 0: | |
| 129 | if added_count == 0: | |
| 133 | 130 | sec_count = len(diff.get("sections", [])) |
| 134 | 131 | if sec_count > 1: |
| 135 | 132 | return MULTIPLE_MSG |