Skip to content

Commit 0cffff7

Browse files
committed
fix
1 parent 056b332 commit 0cffff7

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

.github/workflows/auto-assign-reviewers.yml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,42 @@ jobs:
4545
- name: Get changed files
4646
id: changed_files
4747
run: |
48-
# 通过 GitHub API 获取 PR 的变更文件列表
49-
changed_files=$(curl -s \
50-
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.extract-pr.outputs.PR_NUMBER }}/files" | \
51-
jq -r '.[].filename') # 使用 jq 提取文件名
48+
# 通过 GitHub API 获取 PR 的变更文件列表(带重试机制和错误处理)
49+
max_retries=3
50+
retry_count=0
51+
changed_files=""
52+
api_response=""
53+
54+
echo "Fetching changed files for PR #${{ steps.extract-pr.outputs.PR_NUMBER }}..."
55+
56+
while [ $retry_count -lt $max_retries ]; do
57+
api_response=$(curl -s \
58+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
59+
-H "Accept: application/vnd.github.v3+json" \
60+
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.extract-pr.outputs.PR_NUMBER }}/files")
61+
62+
# 验证响应是否为有效JSON且包含文件数组
63+
if jq -e 'if type=="array" then .[0].filename else empty end' <<<"$api_response" >/dev/null 2>&1; then
64+
changed_files=$(jq -r '.[].filename' <<<"$api_response")
65+
break
66+
else
67+
echo "Retry $((retry_count+1)): API response not ready or invalid format"
68+
echo "API Response: $api_response"
69+
sleep 5
70+
((retry_count++))
71+
fi
72+
done
73+
74+
if [ -z "$changed_files" ]; then
75+
echo "Error: Failed to get changed files after $max_retries attempts"
76+
echo "Final API Response: $api_response"
77+
exit 1
78+
fi
79+
5280
echo "$changed_files" > changed_files.txt
81+
echo "Successfully fetched $(wc -l < changed_files.txt) changed files"
5382
83+
# 以下是原有的评论处理逻辑(保持不变)
5484
existing_comment=$(curl -s \
5585
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
5686
"https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.extract-pr.outputs.PR_NUMBER }}/comments")
@@ -60,7 +90,7 @@ jobs:
6090
existing_comment=$(jq -r '.[] | select(.user.login == "github-actions[bot]") | {body: .body} | @base64' <<< "$existing_comment")
6191
else
6292
existing_comment=""
63-
echo "Warning: Invalid JSON response from GitHub API"
93+
echo "Warning: Invalid JSON response from GitHub API for comments"
6494
echo "Response: $existing_comment"
6595
fi
6696

0 commit comments

Comments
 (0)