From 0f4759f02e303a4a0618b34782eaed6d6d9069c1 Mon Sep 17 00:00:00 2001 From: Yuqiang Wang Date: Tue, 23 Sep 2025 18:02:06 +0800 Subject: [PATCH 1/8] Update pr_format_bot.yml --- .github/workflows/pr_format_bot.yml | 43 +++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr_format_bot.yml b/.github/workflows/pr_format_bot.yml index b36cace603e..777c8483ce3 100644 --- a/.github/workflows/pr_format_bot.yml +++ b/.github/workflows/pr_format_bot.yml @@ -45,8 +45,12 @@ jobs: workflow_url="https://github.com/${fork_repo}/actions/workflows/clang-format.yml" direct_link="${workflow_url}?branch=${branch}" + # 唯一标识符 - 用于识别此工作流的评论 + COMMENT_IDENTIFIER="" + # 使用数组存储多行消息 message_lines=( + "$COMMENT_IDENTIFIER" "**👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!**" "" "为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流。" @@ -85,23 +89,46 @@ jobs: # 使用 jq 安全地构建 JSON 负载 json_payload=$(jq -n --arg body "$message" '{"body": $body}') - # 发送评论到 PR - response=$(curl -s -w "\n%{http_code}" \ - -X POST \ + # 首先检查是否已存在此工作流的评论 + existing_comments=$(curl -s \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ - "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ - -d "$json_payload") + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments") + + # 查找是否已存在带有标识符的评论 + existing_comment_id=$(echo "$existing_comments" | jq -r --arg identifier "$COMMENT_IDENTIFIER" '.[] | select(.body | contains($identifier)) | .id' | head -1) + + if [ -n "$existing_comment_id" ] && [ "$existing_comment_id" != "null" ]; then + echo "Updating existing format notification comment (ID: $existing_comment_id)" + + # 更新现有评论 + response=$(curl -s -w "\n%{http_code}" \ + -X PATCH \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + "https://api.github.com/repos/${{ github.repository }}/issues/comments/$existing_comment_id" \ + -d "$json_payload") + else + echo "Adding new format notification comment" + + # 发送新评论到 PR + response=$(curl -s -w "\n%{http_code}" \ + -X POST \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ + -d "$json_payload") + fi # 提取 HTTP 状态码和响应体 http_code=$(echo "$response" | tail -n1) response_body=$(echo "$response" | sed '$d') - if [ "$http_code" -eq 201 ]; then - echo "Format notification comment added successfully" + if [ "$http_code" -eq 200 ] || [ "$http_code" -eq 201 ]; then + echo "Format notification comment processed successfully" echo "Comment URL: $(echo "$response_body" | jq -r '.html_url')" else - echo "Failed to add comment. HTTP status: $http_code" + echo "Failed to process comment. HTTP status: $http_code" echo "Response: $response_body" exit 1 fi From 81bafcd4436cb8032913fa306204e72004c4c2e7 Mon Sep 17 00:00:00 2001 From: Yuqiang Wang Date: Tue, 23 Sep 2025 18:02:20 +0800 Subject: [PATCH 2/8] Update pr_format_bot.yml --- .github/workflows/pr_format_bot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr_format_bot.yml b/.github/workflows/pr_format_bot.yml index 777c8483ce3..fbffc13d325 100644 --- a/.github/workflows/pr_format_bot.yml +++ b/.github/workflows/pr_format_bot.yml @@ -9,7 +9,7 @@ permissions: jobs: notify-format: - if: github.repository_owner == 'RT-Thread' + # if: github.repository_owner == 'RT-Thread' runs-on: ubuntu-latest steps: - name: Check if first commit and add comment From 6746ce69d2ee95b6fd6fb956fb6bd9d1d824eed5 Mon Sep 17 00:00:00 2001 From: Yuqiang Wang Date: Tue, 23 Sep 2025 18:06:26 +0800 Subject: [PATCH 3/8] Update auto-assign-reviewers.yml --- .github/workflows/auto-assign-reviewers.yml | 112 +++++++++++++++----- 1 file changed, 86 insertions(+), 26 deletions(-) diff --git a/.github/workflows/auto-assign-reviewers.yml b/.github/workflows/auto-assign-reviewers.yml index 8fc10453cca..00a7ec0e9e7 100644 --- a/.github/workflows/auto-assign-reviewers.yml +++ b/.github/workflows/auto-assign-reviewers.yml @@ -10,6 +10,7 @@ # 2025-05-10 kurisaW Fixed file existence, cache, and comment time issues # 2025-05-11 kurisaW Fixed missing unique files creation and cache logic # 2025-07-14 kurisaW Merge same tag with different paths, remove Path display from CI comment +# 2025-01-23 Assistant Added unique identifier for comment isolation # Script Function Description: Assign PR reviews based on the MAINTAINERS list. @@ -23,7 +24,7 @@ on: jobs: assign-reviewers: runs-on: ubuntu-22.04 - if: github.repository_owner == 'RT-Thread' + # if: github.repository_owner == 'RT-Thread' permissions: issues: read pull-requests: write @@ -80,14 +81,22 @@ jobs: echo "$changed_files" > changed_files.txt echo "Successfully fetched $(wc -l < changed_files.txt) changed files" - # 以下是原有的评论处理逻辑(保持不变) + # 唯一标识符 - 用于识别此工作流的评论 + COMMENT_IDENTIFIER="" + + # 获取现有评论,只查找包含特定标识符的评论 existing_comment=$(curl -s \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.extract-pr.outputs.PR_NUMBER }}/comments") # Check if response is valid JSON if jq -e . >/dev/null 2>&1 <<<"$existing_comment"; then - existing_comment=$(jq -r '.[] | select(.user.login == "github-actions[bot]") | {body: .body} | @base64' <<< "$existing_comment") + # 只查找包含特定标识符的评论 + existing_comment=$(jq -r --arg identifier "$COMMENT_IDENTIFIER" ' + .[] | + select(.user.login == "github-actions[bot]") | + select(.body | contains($identifier)) | + {body: .body} | @base64' <<< "$existing_comment") else existing_comment="" echo "Warning: Invalid JSON response from GitHub API for comments" @@ -98,7 +107,7 @@ jobs: if [[ ! -z "$existing_comment" ]]; then comment_body=$(echo "$existing_comment" | head -1 | base64 -d | jq -r .body | sed -nE 's/.*Last Updated: ([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2} CST).*/\1/p') comment_time=$(TZ='Asia/Shanghai' date -d "$comment_body" +%s) - echo "CACHE_TIMESTAMP=${comment_time}" >> $GITHUB_OUTPUT # 统一使用这个变量名 + echo "CACHE_TIMESTAMP=${comment_time}" >> $GITHUB_OUTPUT echo "COMMENT_TIME=${comment_time}" >> $GITHUB_OUTPUT else comment_time="" @@ -340,6 +349,10 @@ jobs: notified_users=$(cat unique_reviewers_bak.txt | xargs) fi current_time=$(TZ='Asia/Shanghai' date +"%Y-%m-%d %H:%M CST") + + # 唯一标识符 + COMMENT_IDENTIFIER="" + { echo "## 📌 Code Review Assignment" echo "" @@ -395,49 +408,96 @@ jobs: id: post_comment if: steps.generate_reviewers.outputs.HAS_REVIEWERS == 'true' run: | - # 查找现有的 bot 评论 - existing_comment=$(curl -s \ + # 唯一标识符 + COMMENT_IDENTIFIER="" + + # 查找现有的 bot 评论(只查找包含特定标识符的评论) + existing_comments=$(curl -s \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.extract-pr.outputs.PR_NUMBER }}/comments" | \ - jq -r '.[] | select(.user.login == "github-actions[bot]") | {id: .id, body: .body} | @base64') + "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.extract-pr.outputs.PR_NUMBER }}/comments") - if [[ -n "$existing_comment" ]]; then + # 查找包含标识符的评论ID + existing_comment_id=$(echo "$existing_comments" | jq -r --arg identifier "$COMMENT_IDENTIFIER" ' + .[] | + select(.user.login == "github-actions[bot]") | + select(.body | contains($identifier)) | + .id' | head -1) + + # 读取评论内容 + comment_content=$(cat review_data.md) + + if [[ -n "$existing_comment_id" ]] && [[ "$existing_comment_id" != "null" ]]; then # 更新现有评论 - comment_id=$(echo "$existing_comment" | head -1 | base64 -d | jq -r .id) - echo "Updating existing comment $comment_id" - response=$(curl -s -X PATCH \ + echo "Updating existing comment $existing_comment_id" + response=$(curl -s -w "\n%{http_code}" -X PATCH \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -d "$(jq -n --arg body "$(cat review_data.md)" '{body: $body}')" \ - "https://api.github.com/repos/${{ github.repository }}/issues/comments/$comment_id") + -H "Accept: application/vnd.github.v3+json" \ + -d "$(jq -n --arg body "$comment_content" '{body: $body}')" \ + "https://api.github.com/repos/${{ github.repository }}/issues/comments/$existing_comment_id") else # 创建新评论 echo "Creating new comment" - response=$(curl -s -X POST \ + response=$(curl -s -w "\n%{http_code}" -X POST \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -d "$(jq -n --arg body "$(cat review_data.md)" '{body: $body}')" \ + -H "Accept: application/vnd.github.v3+json" \ + -d "$(jq -n --arg body "$comment_content" '{body: $body}')" \ "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.extract-pr.outputs.PR_NUMBER }}/comments") fi + + # 检查响应 + http_code=$(echo "$response" | tail -n1) + response_body=$(echo "$response" | sed '$d') + + if [ "$http_code" -eq 200 ] || [ "$http_code" -eq 201 ]; then + echo "Comment processed successfully (HTTP $http_code)" + else + echo "Failed to process comment. HTTP status: $http_code" + echo "Response: $response_body" + exit 1 + fi - name: Get Comment Time id: get_comment_time if: steps.generate_reviewers.outputs.HAS_REVIEWERS == 'true' run: | - existing_comment=$(curl -s \ + # 唯一标识符 + COMMENT_IDENTIFIER="" + + existing_comments=$(curl -s \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.extract-pr.outputs.PR_NUMBER }}/comments") # Check if response is valid JSON - if jq -e . >/dev/null 2>&1 <<<"$existing_comment"; then - existing_comment=$(jq -r '.[] | select(.user.login == "github-actions[bot]") | {body: .body} | @base64' <<< "$existing_comment") + if jq -e . >/dev/null 2>&1 <<<"$existing_comments"; then + # 只查找包含特定标识符的评论 + existing_comment_body=$(echo "$existing_comments" | jq -r --arg identifier "$COMMENT_IDENTIFIER" ' + .[] | + select(.user.login == "github-actions[bot]") | + select(.body | contains($identifier)) | + .body' | head -1) else - existing_comment="" + existing_comment_body="" echo "Warning: Invalid JSON response from GitHub API" - echo "Response: $existing_comment" fi - comment_body="${{ steps.get_approval.outputs.CURRENT_TIME }}" - comment_time=$(TZ='Asia/Shanghai' date -d "$comment_body" +%s) - echo "CACHE_TIMESTAMP=${comment_time}" >> $GITHUB_OUTPUT # 统一使用这个变量名 - echo "Debug - Saving cache with timestamp: $comment_time" + + if [[ -n "$existing_comment_body" ]]; then + comment_time=$(echo "$existing_comment_body" | sed -nE 's/.*Last Updated: ([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2} CST).*/\1/p') + if [[ -n "$comment_time" ]]; then + timestamp=$(TZ='Asia/Shanghai' date -d "$comment_time" +%s) + echo "CACHE_TIMESTAMP=${timestamp}" >> $GITHUB_OUTPUT + echo "Debug - Found existing comment with timestamp: $comment_time -> $timestamp" + else + current_time=$(TZ='Asia/Shanghai' date +"%Y-%m-%d %H:%M CST") + timestamp=$(TZ='Asia/Shanghai' date -d "$current_time" +%s) + echo "CACHE_TIMESTAMP=${timestamp}" >> $GITHUB_OUTPUT + echo "Debug - Using current time for cache: $current_time -> $timestamp" + fi + else + current_time=$(TZ='Asia/Shanghai' date +"%Y-%m-%d %H:%M CST") + timestamp=$(TZ='Asia/Shanghai' date -d "$current_time" +%s) + echo "CACHE_TIMESTAMP=${timestamp}" >> $GITHUB_OUTPUT + echo "Debug - No existing comment found, using current time: $current_time -> $timestamp" + fi mkdir -p $(dirname unique_reviewers_bak.txt) if [[ -s unique_reviewers.txt ]]; then @@ -461,4 +521,4 @@ jobs: path: | unique_tags_bak.txt unique_reviewers_bak.txt - key: ${{ runner.os }}-auto-assign-reviewers-${{ steps.extract-pr.outputs.PR_NUMBER }}-${{ steps.get_comment_time.outputs.CACHE_TIMESTAMP }}-${{ github.run_id }} \ No newline at end of file + key: ${{ runner.os }}-auto-assign-reviewers-${{ steps.extract-pr.outputs.PR_NUMBER }}-${{ steps.get_comment_time.outputs.CACHE_TIMESTAMP }}-${{ github.run_id }} From 012c85f50cf059e922372cb52eab35b287c540b8 Mon Sep 17 00:00:00 2001 From: Nedki-L <114712457+Nedki-L@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:06:53 +0800 Subject: [PATCH 4/8] Update auto-assign-reviewers.yml --- .github/workflows/auto-assign-reviewers.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto-assign-reviewers.yml b/.github/workflows/auto-assign-reviewers.yml index 00a7ec0e9e7..b3aab44087e 100644 --- a/.github/workflows/auto-assign-reviewers.yml +++ b/.github/workflows/auto-assign-reviewers.yml @@ -12,6 +12,7 @@ # 2025-07-14 kurisaW Merge same tag with different paths, remove Path display from CI comment # 2025-01-23 Assistant Added unique identifier for comment isolation + # Script Function Description: Assign PR reviews based on the MAINTAINERS list. name: Auto Review Assistant From 5f453ba0f0553b5705e182006d59053a30981c0b Mon Sep 17 00:00:00 2001 From: Nedki-L <114712457+Nedki-L@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:08:24 +0800 Subject: [PATCH 5/8] Update auto-assign-reviewers.yml --- .github/workflows/auto-assign-reviewers.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto-assign-reviewers.yml b/.github/workflows/auto-assign-reviewers.yml index b3aab44087e..30c8b1bc251 100644 --- a/.github/workflows/auto-assign-reviewers.yml +++ b/.github/workflows/auto-assign-reviewers.yml @@ -13,6 +13,7 @@ # 2025-01-23 Assistant Added unique identifier for comment isolation + # Script Function Description: Assign PR reviews based on the MAINTAINERS list. name: Auto Review Assistant From f919ac9f6630dfdeee49d5b726dbaac5926c7c40 Mon Sep 17 00:00:00 2001 From: Nedki-L <114712457+Nedki-L@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:28:09 +0800 Subject: [PATCH 6/8] Update pr_clang_format.yaml --- .github/workflows/pr_clang_format.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr_clang_format.yaml b/.github/workflows/pr_clang_format.yaml index 2e2dd16d4a7..8f277f8d8f4 100644 --- a/.github/workflows/pr_clang_format.yaml +++ b/.github/workflows/pr_clang_format.yaml @@ -263,3 +263,4 @@ jobs: echo "处理文件数: ${{ steps.find-files.outputs.files_count }}" echo "有更改: ${{ steps.check-changes.outputs.has_changes }}" echo "clang-format 版本: $(clang-format --version | head -1)" + From 0df2099e3266d47f85e595a04d4602fba7668cc6 Mon Sep 17 00:00:00 2001 From: Nedki-L <114712457+Nedki-L@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:28:49 +0800 Subject: [PATCH 7/8] Update pr_clang_format.yaml --- .github/workflows/pr_clang_format.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr_clang_format.yaml b/.github/workflows/pr_clang_format.yaml index 8f277f8d8f4..f89a207b48a 100644 --- a/.github/workflows/pr_clang_format.yaml +++ b/.github/workflows/pr_clang_format.yaml @@ -264,3 +264,4 @@ jobs: echo "有更改: ${{ steps.check-changes.outputs.has_changes }}" echo "clang-format 版本: $(clang-format --version | head -1)" + From b1232481f08d2384c1d26608b8beb4c1d4610b7d Mon Sep 17 00:00:00 2001 From: Nedki-L <114712457+Nedki-L@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:29:16 +0800 Subject: [PATCH 8/8] Update pr_clang_format.yaml