diff --git a/.github/workflows/pr-comment.yml b/.github/workflows/pr-comment.yml index 455112c..44e6c33 100644 --- a/.github/workflows/pr-comment.yml +++ b/.github/workflows/pr-comment.yml @@ -26,7 +26,7 @@ jobs: run-id: ${{ github.event.workflow_run.id }} github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Post or update comment + - name: Post comment uses: actions/github-script@v7 with: github-token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} @@ -34,12 +34,20 @@ jobs: const fs = require('fs'); const marker = ''; + // Check if there are findings to post + const commentFile = 'pr-meta/comment.md'; + if (!fs.existsSync(commentFile)) { + console.log('No findings to post — skipping.'); + return; + } + // Determine the PR number let prNumber; const numberFile = 'pr-meta/number.txt'; if (fs.existsSync(numberFile)) { prNumber = parseInt(fs.readFileSync(numberFile, 'utf8').trim()); - } else { + } + if (!prNumber) { // workflow_run.pull_requests is empty for fork PRs, so // fall back to searching by head SHA if needed const prs = context.payload.workflow_run.pull_requests; @@ -53,48 +61,34 @@ jobs: state: 'open', sort: 'updated', direction: 'desc', - per_page: 10, + per_page: 100, }); const match = prList.find(pr => pr.head.sha === headSha); if (!match) { - console.log(`No open PR found for SHA ${headSha} — skipping comment.`); + console.log(`No open PR found for SHA ${headSha} — skipping.`); return; } prNumber = match.number; } } - // Find existing bot comment + // Skip if we already commented on this PR const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, + per_page: 100, }); - const existing = comments.find(c => c.body.includes(marker)); - - const commentFile = 'pr-meta/comment.md'; - if (fs.existsSync(commentFile)) { - const body = fs.readFileSync(commentFile, 'utf8').trim(); - if (existing) { - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: existing.id, - body, - }); - } else { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body, - }); - } - } else if (existing) { - // No findings — remove stale comment - await github.rest.issues.deleteComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: existing.id, - }); + if (comments.some(c => c.body.includes(marker))) { + console.log('Bot comment already exists — skipping.'); + return; } + + // Post the comment + const body = fs.readFileSync(commentFile, 'utf8').trim(); + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body, + }); diff --git a/lib/checks/__pycache__/check-links.cpython-310.pyc b/lib/checks/__pycache__/check-links.cpython-310.pyc deleted file mode 100644 index 4fc6b74..0000000 Binary files a/lib/checks/__pycache__/check-links.cpython-310.pyc and /dev/null differ diff --git a/lib/checks/__pycache__/check-readme-edits.cpython-310.pyc b/lib/checks/__pycache__/check-readme-edits.cpython-310.pyc deleted file mode 100644 index 6eb4ca8..0000000 Binary files a/lib/checks/__pycache__/check-readme-edits.cpython-310.pyc and /dev/null differ diff --git a/lib/checks/__pycache__/check-template.cpython-310.pyc b/lib/checks/__pycache__/check-template.cpython-310.pyc deleted file mode 100644 index d49b256..0000000 Binary files a/lib/checks/__pycache__/check-template.cpython-310.pyc and /dev/null differ diff --git a/lib/checks/__pycache__/check-yaml-diff.cpython-310.pyc b/lib/checks/__pycache__/check-yaml-diff.cpython-310.pyc deleted file mode 100644 index 51c91bf..0000000 Binary files a/lib/checks/__pycache__/check-yaml-diff.cpython-310.pyc and /dev/null differ diff --git a/lib/checks/__pycache__/detect-changes.cpython-310.pyc b/lib/checks/__pycache__/detect-changes.cpython-310.pyc deleted file mode 100644 index 89c8601..0000000 Binary files a/lib/checks/__pycache__/detect-changes.cpython-310.pyc and /dev/null differ diff --git a/lib/checks/__pycache__/warn-non-yaml.cpython-310.pyc b/lib/checks/__pycache__/warn-non-yaml.cpython-310.pyc deleted file mode 100644 index 5329521..0000000 Binary files a/lib/checks/__pycache__/warn-non-yaml.cpython-310.pyc and /dev/null differ diff --git a/lib/checks/check-additions.py b/lib/checks/check-additions.py index 474c651..b637d89 100644 --- a/lib/checks/check-additions.py +++ b/lib/checks/check-additions.py @@ -86,12 +86,13 @@ def check_required_fields(diff, head): for svc in diff.get("services", {}).get("modified", []): if not head: continue + changed = svc.get("changed_fields", []) fields = find_service_fields( head, svc["category"], svc["section"], svc["service"] ) if fields: for f in REQUIRED_FIELDS: - if not fields.get(f): + if f in changed and not fields.get(f): missing.add(f) if missing: names = ", ".join(f"`{f}`" for f in sorted(missing)) @@ -120,16 +121,12 @@ def check_open_source(diff): def check_single_entry(diff): - """Return a finding if the diff contains multiple service or section changes.""" + """Return a finding if the diff adds multiple new services or sections.""" services = diff.get("services", {}) - svc_count = ( - len(services.get("added", [])) - + len(services.get("removed", [])) - + len(services.get("modified", [])) - ) - if svc_count > 1: + added_count = len(services.get("added", [])) + if added_count > 1: return MULTIPLE_MSG - if svc_count == 0: + if added_count == 0: sec_count = len(diff.get("sections", [])) if sec_count > 1: return MULTIPLE_MSG