ci: Use labels for changelog rather than comments

This commit is contained in:
Jade Ellis
2026-04-12 17:14:47 +01:00
committed by Ellis Git
parent ab241f8f65
commit f02a08de57
+25 -32
View File
@@ -2,7 +2,7 @@ name: Check Changelog
on: on:
pull_request_target: pull_request_target:
types: [opened, synchronize, reopened, ready_for_review] types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
concurrency: concurrency:
@@ -54,7 +54,7 @@ jobs:
echo "src_changed=false" >> $GITHUB_OUTPUT echo "src_changed=false" >> $GITHUB_OUTPUT
fi fi
- name: Manage PR Comment - name: Manage PR Labels
uses: https://github.com/actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 uses: https://github.com/actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
env: env:
HAS_CHANGELOG: ${{ steps.check_files.outputs.has_changelog }} HAS_CHANGELOG: ${{ steps.check_files.outputs.has_changelog }}
@@ -63,41 +63,34 @@ jobs:
script: | script: |
const hasChangelog = process.env.HAS_CHANGELOG === 'true'; const hasChangelog = process.env.HAS_CHANGELOG === 'true';
const srcChanged = process.env.SRC_CHANGED === 'true'; const srcChanged = process.env.SRC_CHANGED === 'true';
const commentSignature = '<!-- changelog-check-action -->';
const commentBody = `${commentSignature}\nPlease add a changelog fragment to \`changelog.d/\` describing your changes.`;
const { data: currentUser } = await github.rest.users.getAuthenticated(); const { data: pullRequest } = await github.rest.pulls.get({
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, pull_number: context.issue.number,
}); });
const botComment = comments.find(comment => const currentLabels = pullRequest.labels.map(l => l.name);
comment.user.id === currentUser.id &&
comment.body.includes(commentSignature)
);
const shouldWarn = srcChanged && !hasChangelog; if (hasChangelog) {
console.log('PR has changelog');
if (!shouldWarn) { await github.rest.issues.addLabels({
if (botComment) { owner: context.repo.owner,
console.log('Changelog found or not required. Deleting existing warning comment.'); repo: context.repo.repo,
await github.rest.issues.deleteComment({ issue_number: context.issue.number,
owner: context.repo.owner, labels: ['Changelog/Added'],
repo: context.repo.repo, });
comment_id: botComment.id, } else if (currentLabels.includes('Changelog/None')) {
}); console.log('PR has Changelog/None label, skipping.');
} } else if (srcChanged) {
console.log('PR is missing changelog');
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['Changelog/Missing'],
});
} else { } else {
if (!botComment) { console.log('Changelog not needed');
console.log('Changelog missing and required. Creating warning comment.'); // Changelog is probably not needed
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody,
});
}
} }