From 34ae7aad5453f21ae0fac38afa8d6c507948a78e Mon Sep 17 00:00:00 2001 From: Lee Date: Fri, 4 Oct 2024 21:37:12 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E4=BC=98=E5=8C=96=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A7=BB=E9=99=A4=E6=B2=A1=E7=94=A8?= =?UTF-8?q?=E7=9A=84=20/zh-cn/=20=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/preview-pr-build.yaml | 28 +++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview-pr-build.yaml b/.github/workflows/preview-pr-build.yaml index a9b48cf629..6b6c197f30 100644 --- a/.github/workflows/preview-pr-build.yaml +++ b/.github/workflows/preview-pr-build.yaml @@ -58,11 +58,31 @@ jobs: with: script: | const prNumber = context.payload.pull_request.number; - const previewUrl = `${{ steps.deploy.outputs.url }}`; - const comment = `🚀 预览部署完成! 访问链接: ${previewUrl}/zh-cn/`; - github.rest.issues.createComment({ + const previewUrl = `{{ steps.deploy.outputs.url }}`; + 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, + }); + }