From 0f4759f02e303a4a0618b34782eaed6d6d9069c1 Mon Sep 17 00:00:00 2001 From: Yuqiang Wang Date: Tue, 23 Sep 2025 18:02:06 +0800 Subject: [PATCH 1/9] 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/9] 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/9] 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 46443202b9d3f06346552a7230e3da72ed3b8215 Mon Sep 17 00:00:00 2001 From: Yuqiang Wang Date: Tue, 23 Sep 2025 18:20:20 +0800 Subject: [PATCH 4/9] Update auto-assign-reviewers.yml --- .github/workflows/auto-assign-reviewers.yml | 109 +++++--------------- 1 file changed, 25 insertions(+), 84 deletions(-) diff --git a/.github/workflows/auto-assign-reviewers.yml b/.github/workflows/auto-assign-reviewers.yml index 00a7ec0e9e7..2b06227fb99 100644 --- a/.github/workflows/auto-assign-reviewers.yml +++ b/.github/workflows/auto-assign-reviewers.yml @@ -10,7 +10,6 @@ # 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. @@ -81,22 +80,14 @@ 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 --arg identifier "$COMMENT_IDENTIFIER" ' - .[] | - select(.user.login == "github-actions[bot]") | - select(.body | contains($identifier)) | - {body: .body} | @base64' <<< "$existing_comment") + existing_comment=$(jq -r '.[] | select(.user.login == "github-actions[bot]" and (.body | contains(""))) | {body: .body} | @base64' <<< "$existing_comment") else existing_comment="" echo "Warning: Invalid JSON response from GitHub API for comments" @@ -107,7 +98,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="" @@ -349,11 +340,8 @@ 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 "" echo "## 📌 Code Review Assignment" echo "" for tag in $unique_tags; do @@ -408,96 +396,49 @@ jobs: id: post_comment if: steps.generate_reviewers.outputs.HAS_REVIEWERS == 'true' run: | - # 唯一标识符 - COMMENT_IDENTIFIER="" - - # 查找现有的 bot 评论(只查找包含特定标识符的评论) - existing_comments=$(curl -s \ + # 查找现有的 bot 评论 + 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") + "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.extract-pr.outputs.PR_NUMBER }}/comments" | \ + jq -r '.[] | select(.user.login == "github-actions[bot]" and (.body | contains(""))) | {id: .id, body: .body} | @base64') - # 查找包含标识符的评论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 + if [[ -n "$existing_comment" ]]; then # 更新现有评论 - echo "Updating existing comment $existing_comment_id" - response=$(curl -s -w "\n%{http_code}" -X PATCH \ + comment_id=$(echo "$existing_comment" | head -1 | base64 -d | jq -r .id) + echo "Updating existing comment $comment_id" + response=$(curl -s -X PATCH \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -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") + -d "$(jq -n --arg body "$(cat review_data.md)" '{body: $body}')" \ + "https://api.github.com/repos/${{ github.repository }}/issues/comments/$comment_id") else # 创建新评论 echo "Creating new comment" - response=$(curl -s -w "\n%{http_code}" -X POST \ + response=$(curl -s -X POST \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - -d "$(jq -n --arg body "$comment_content" '{body: $body}')" \ + -d "$(jq -n --arg body "$(cat review_data.md)" '{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: | - # 唯一标识符 - COMMENT_IDENTIFIER="" - - existing_comments=$(curl -s \ + 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_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) + if jq -e . >/dev/null 2>&1 <<<"$existing_comment"; then + existing_comment=$(jq -r '.[] | select(.user.login == "github-actions[bot]" and (.body | contains(""))) | {body: .body} | @base64' <<< "$existing_comment") else - existing_comment_body="" + existing_comment="" echo "Warning: Invalid JSON response from GitHub API" + echo "Response: $existing_comment" fi - - 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 + 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" mkdir -p $(dirname unique_reviewers_bak.txt) if [[ -s unique_reviewers.txt ]]; then From a94648974c92e66272810d7ef615b03144a661df Mon Sep 17 00:00:00 2001 From: Yuqiang Wang Date: Tue, 23 Sep 2025 18:25:55 +0800 Subject: [PATCH 5/9] Update pr_format_bot.yml --- .github/workflows/pr_format_bot.yml | 44 +++++++++++++---------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/.github/workflows/pr_format_bot.yml b/.github/workflows/pr_format_bot.yml index fbffc13d325..891b61b2812 100644 --- a/.github/workflows/pr_format_bot.yml +++ b/.github/workflows/pr_format_bot.yml @@ -45,12 +45,9 @@ 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 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流。" @@ -86,49 +83,46 @@ jobs: echo "Message content:" echo "$message" - # 使用 jq 安全地构建 JSON 负载 - json_payload=$(jq -n --arg body "$message" '{"body": $body}') - - # 首先检查是否已存在此工作流的评论 - existing_comments=$(curl -s \ + # 查找现有的 bot 评论 + existing_comment=$(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") + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" | \ + jq -r '.[] | select(.user.login == "github-actions[bot]" and (.body | contains(""))) | {id: .id, body: .body} | @base64') - # 查找是否已存在带有标识符的评论 - existing_comment_id=$(echo "$existing_comments" | jq -r --arg identifier "$COMMENT_IDENTIFIER" '.[] | select(.body | contains($identifier)) | .id' | head -1) + # 使用 jq 安全地构建 JSON 负载 + json_payload=$(jq -n --arg body "$message" '{"body": $body}') - if [ -n "$existing_comment_id" ] && [ "$existing_comment_id" != "null" ]; then - echo "Updating existing format notification comment (ID: $existing_comment_id)" - + if [[ -n "$existing_comment" ]]; then # 更新现有评论 + comment_id=$(echo "$existing_comment" | head -1 | base64 -d | jq -r .id) + echo "Updating existing comment $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") + -d "$json_payload" \ + "https://api.github.com/repos/${{ github.repository }}/issues/comments/$comment_id") else - echo "Adding new format notification comment" - - # 发送新评论到 PR + # 创建新评论 + echo "Creating new comment" 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") + -d "$json_payload" \ + "https://api.github.com/repos/${{ github.event.pull_request.number }}/comments") fi # 提取 HTTP 状态码和响应体 http_code=$(echo "$response" | tail -n1) response_body=$(echo "$response" | sed '$d') - if [ "$http_code" -eq 200 ] || [ "$http_code" -eq 201 ]; then - echo "Format notification comment processed successfully" + if [ "$http_code" -eq 201 ] || [ "$http_code" -eq 200 ]; then + echo "Format notification comment added/updated successfully" echo "Comment URL: $(echo "$response_body" | jq -r '.html_url')" else - echo "Failed to process comment. HTTP status: $http_code" + echo "Failed to add/update comment. HTTP status: $http_code" echo "Response: $response_body" exit 1 fi From 3a814aada90266c4c9cd96551855d9f93524882b Mon Sep 17 00:00:00 2001 From: Yuqiang Wang Date: Tue, 23 Sep 2025 18:32:47 +0800 Subject: [PATCH 6/9] Update pr_format_bot.yml --- .github/workflows/pr_format_bot.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr_format_bot.yml b/.github/workflows/pr_format_bot.yml index 891b61b2812..11f5763e776 100644 --- a/.github/workflows/pr_format_bot.yml +++ b/.github/workflows/pr_format_bot.yml @@ -64,7 +64,7 @@ jobs: "- 设置需排除的文件/目录(目录请以\"/\"结尾)" "Set files/directories to exclude (directories should end with \"/\")" "- 将目标分支设置为 \ Set the target branch to:**\`${branch}\`**" - "- 设置PR number为 \ Set the PR number to:**\`${{ github.event.number }}\`**" + "- 设置PR number为 \ Set the PR number to:**\`${{ github.event.pull_request.number }}\`**" "" "3. **等待工作流完成 | Wait for the workflow to complete**" "格式化后的代码将自动推送至你的分支。" @@ -111,7 +111,7 @@ jobs: -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -d "$json_payload" \ - "https://api.github.com/repos/${{ github.event.pull_request.number }}/comments") + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments") fi # 提取 HTTP 状态码和响应体 From 9e0b362a7f7153af6445f4b1f52b2aa286c3e2b2 Mon Sep 17 00:00:00 2001 From: Yuqiang Wang Date: Tue, 23 Sep 2025 18:33:11 +0800 Subject: [PATCH 7/9] 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 11f5763e776..7dcf981e90a 100644 --- a/.github/workflows/pr_format_bot.yml +++ b/.github/workflows/pr_format_bot.yml @@ -1,7 +1,7 @@ name: PR Format Notification on: pull_request_target: - types: [opened, synchronize] + types: [opened, synchronize, reopened] permissions: pull-requests: write From eba77e8c84e4249c1255a51c33cca54f08d80825 Mon Sep 17 00:00:00 2001 From: Nedki-L <114712457+Nedki-L@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:35:12 +0800 Subject: [PATCH 8/9] Update .cproject --- bsp/renesas/ra6m3-hmi-board/.cproject | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp/renesas/ra6m3-hmi-board/.cproject b/bsp/renesas/ra6m3-hmi-board/.cproject index 7fddc369ed6..7af59087d2b 100644 --- a/bsp/renesas/ra6m3-hmi-board/.cproject +++ b/bsp/renesas/ra6m3-hmi-board/.cproject @@ -1,4 +1,4 @@ - + From 8204775eb8ab205b0978cf8b343eaeaddfb29e20 Mon Sep 17 00:00:00 2001 From: Nedki-L <114712457+Nedki-L@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:36:17 +0800 Subject: [PATCH 9/9] Update .config --- bsp/renesas/ra2a1-ek/.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp/renesas/ra2a1-ek/.config b/bsp/renesas/ra2a1-ek/.config index 2f4cb605c5e..c3eb28d061f 100644 --- a/bsp/renesas/ra2a1-ek/.config +++ b/bsp/renesas/ra2a1-ek/.config @@ -7,7 +7,7 @@ CONFIG_SOC_R7FA2A1AB=y # # klibc options # - + # # rt_vsnprintf options #