Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: 优化评论逻辑 #448

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions .github/workflows/preview-pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,30 @@ jobs:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `${{ steps.deploy.outputs.url }}`;
const comment = `🚀 预览部署完成! 访问链接: ${previewUrl}`;
github.rest.issues.createComment({
const commentBody = `🚀 预览部署完成! 访问链接: ${previewUrl}`;
// 获取现有评论
const { data: comments } = await github.rest.issues.listComments({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment,
});
// 查找评论的关键词
const existingComment = comments.find(comment =>
comment.body.includes('🚀 预览部署完成!'));
if (existingComment) {
// 如果已经有评论,更新评论
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody,
});
} else {
// 如果没有评论,创建新的评论
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody,
});
}
Loading