Skip to content

Comment on PR (Generated VRL Docs) #1

Comment on PR (Generated VRL Docs)

Comment on PR (Generated VRL Docs) #1

name: Comment on PR (Generated VRL Docs)
on:
workflow_run:
workflows: ["Check Generated VRL Docs Freshness"]
types:
- completed
permissions:
contents: read
jobs:
comment:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.conclusion == 'failure'
&& github.event.workflow_run.event == 'pull_request'
permissions:
pull-requests: write
steps:
- name: Download PR metadata
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: vrl-docs-check-pr
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Comment on PR
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const fs = require('fs');
const prNumber = parseInt(fs.readFileSync('pr-number', 'utf8').trim(), 10);
if (isNaN(prNumber)) {
core.setFailed('Invalid PR number');
return;
}
const marker = '<!-- generated-vrl-docs-check -->';
const body = marker + '\nThe `docs/generated/` folder is out of date but I was unable to push the fix automatically.\n\nPlease run the following and commit the result:\n\n```\nmake generate-vector-vrl-docs\n```';
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c => c.body.startsWith(marker));
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,
});
}