mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-06-29 05:39:31 +00:00
improve CI commenter
This commit is contained in:
parent
456143185a
commit
686860b088
1 changed files with 35 additions and 34 deletions
69
.github/actions/lint-reporter/action.yml
vendored
69
.github/actions/lint-reporter/action.yml
vendored
|
|
@ -17,8 +17,18 @@ inputs:
|
|||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Create or Update PR Comment
|
||||
- name: Find Comment
|
||||
if: github.event_name == 'pull_request'
|
||||
uses: peter-evans/find-comment@v3
|
||||
id: fc
|
||||
with:
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
comment-author: 'github-actions[bot]'
|
||||
body-includes: '<!-- lint-results -->'
|
||||
|
||||
- name: Prepare Comment Body
|
||||
if: github.event_name == 'pull_request'
|
||||
id: prepare
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ inputs.github-token }}
|
||||
|
|
@ -26,6 +36,7 @@ runs:
|
|||
const title = ${{ toJSON(inputs.title) }};
|
||||
const result = ${{ toJSON(inputs.lint-result) }};
|
||||
const output = ${{ toJSON(inputs.lint-output) }};
|
||||
const existingCommentId = '${{ steps.fc.outputs.comment-id }}';
|
||||
|
||||
const icon = result === 'success' ? '✅' : '❌';
|
||||
const status = result === 'success' ? 'Passed' : 'Failed';
|
||||
|
|
@ -37,24 +48,16 @@ runs:
|
|||
sectionContent += `\n<details>\n<summary>Click to see details</summary>\n\n\`\`\`\n${output}\n\`\`\`\n\n</details>\n`;
|
||||
}
|
||||
|
||||
const commentMarker = '<!-- lint-results -->';
|
||||
const issue_number = context.issue.number;
|
||||
|
||||
// Find existing comment
|
||||
const comments = await github.rest.issues.listComments({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue_number,
|
||||
});
|
||||
|
||||
const botComment = comments.data.find(comment =>
|
||||
comment.user.type === 'Bot' && comment.body.includes(commentMarker)
|
||||
);
|
||||
|
||||
let body;
|
||||
if (botComment) {
|
||||
// Update existing comment
|
||||
const existingBody = botComment.body;
|
||||
if (existingCommentId) {
|
||||
// Get existing comment body
|
||||
const { data: comment } = await github.rest.issues.getComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: parseInt(existingCommentId),
|
||||
});
|
||||
|
||||
const existingBody = comment.body;
|
||||
const sectionHeader = `### ${title}`;
|
||||
const nextSectionRegex = /^###\s/m;
|
||||
|
||||
|
|
@ -86,21 +89,19 @@ runs:
|
|||
// Add new section at the end
|
||||
body = existingBody + '\n\n' + sectionContent;
|
||||
}
|
||||
|
||||
await github.rest.issues.updateComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: botComment.id,
|
||||
body: body,
|
||||
});
|
||||
} else {
|
||||
// Create new comment
|
||||
body = `## 🔍 Code Quality Report\n${commentMarker}\n\nThis comment is automatically updated with linting results from CI.\n\n${sectionContent}`;
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue_number,
|
||||
body: body,
|
||||
});
|
||||
}
|
||||
body = `## 🔍 Code Quality Report\n<!-- lint-results -->\n\nThis comment is automatically updated with linting results from CI.\n\n${sectionContent}`;
|
||||
}
|
||||
|
||||
// Store the body for the next step
|
||||
core.setOutput('comment_body', body);
|
||||
|
||||
- name: Create or Update Comment
|
||||
if: github.event_name == 'pull_request'
|
||||
uses: peter-evans/create-or-update-comment@v4
|
||||
with:
|
||||
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
body: ${{ steps.prepare.outputs.comment_body }}
|
||||
edit-mode: replace
|
||||
Loading…
Reference in a new issue