From 421ae2ea68937fbc9fb75bff921ba0a159a002b8 Mon Sep 17 00:00:00 2001 From: Lee Date: Fri, 4 Oct 2024 23:27:51 +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=20(#448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/preview-pr-build.yaml | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/.github/workflows/preview-pr-build.yaml b/.github/workflows/preview-pr-build.yaml index b854dbf..391d13a 100644 --- a/.github/workflows/preview-pr-build.yaml +++ b/.github/workflows/preview-pr-build.yaml @@ -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, + }); + }