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