7
7
# Date Author Notes
8
8
# 2025-01-21 kurisaW Initial version
9
9
# 2025-03-14 hydevcode
10
+ # 2025-05-10 kurisaW Fixed file existence, cache, and comment time issues
10
11
11
12
# Script Function Description: Assign PR reviews based on the MAINTAINERS list.
12
13
50
51
"https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.extract-pr.outputs.PR_NUMBER }}/comments" | \
51
52
jq -r '.[] | select(.user.login == "github-actions[bot]") | {body: .body} | @base64')
52
53
54
+ echo "=== Changed Files ==="
55
+ cat changed_files.txt
56
+ echo "====================="
57
+
53
58
comment_body=""
54
59
if [[ ! -z "$existing_comment" ]]; then
55
60
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} UTC).*/\1/p')
63
68
echo "COMMENT_TIME=${comment_time}" >> $GITHUB_OUTPUT
64
69
fi
65
70
echo "COMMENT_TIME=${comment_time}"
71
+
72
+
66
73
- name : Parse MAINTAINERS file
67
74
id : parse_maintainer
68
75
run : |
72
79
/^tag:/ {
73
80
tag = substr($0, index($0, $2)) # 提取标签内容
74
81
}
75
- /^path:/ {
76
- path = substr($0, index($0, $2)) # 提取路径内容
82
+ /^path:/ {
83
+ # 提取 path 字段并去除前后空格
84
+ path = substr($0, index($0, $2))
85
+ gsub(/^[ \t]+|[ \t]+$/, "", path) # 清理前后空格和制表符
77
86
}
78
87
/^owners:/ {
79
88
owners = substr($0, index($0, $2)) # 提取维护者信息
@@ -85,21 +94,30 @@ jobs:
85
94
print tag "|" path "|" github_ids
86
95
}
87
96
' MAINTAINERS > tag_data.csv
97
+
88
98
- name : Generate reviewers list
89
99
id : generate_reviewers
90
100
run : |
91
- # 根据变更文件路径匹配维护者规则
92
- rm -f triggered_reviewers.txt
93
- rm -f triggered_tags.txt
101
+ rm -f triggered_reviewers.txt triggered_tags.txt
102
+ touch triggered_reviewers.txt triggered_tags .txt
103
+
94
104
while IFS='|' read -r tag path reviewers; do
95
- # 使用正则匹配路径(支持子目录)
96
- if grep -qE "^$path(/|$)" changed_files.txt; then
97
- echo "$reviewers" | tr ' ' '\n' >> triggered_reviewers.txt
98
- echo "$tag" | tr ' ' '\n' >> triggered_tags.txt
105
+ # 转义路径中的正则特殊字符
106
+ escaped_path=$(sed 's/[.[\*^$]/\\&/g' <<< "$path")
107
+
108
+ # 使用增强型正则匹配路径及其所有子目录
109
+ if grep -qE "^$escaped_path(/.*)*" changed_files.txt; then
110
+ echo "$reviewers" | tr -s ' ' '\n' | sed '/^$/d' >> triggered_reviewers.txt
111
+ echo "$tag" >> triggered_tags.txt
112
+ echo "Matched: $path → $tag"
99
113
fi
100
114
done < tag_data.csv
101
- awk 'NF && !seen[$0]++' triggered_reviewers.txt > unique_reviewers.txt
102
- awk 'NF && !seen[$0]++' triggered_tags.txt > unique_tags.txt
115
+
116
+ echo "=== Matched Paths ==="
117
+ cat triggered_tags.txt
118
+ echo "=== Matched Reviewers ==="
119
+ cat triggered_reviewers.txt
120
+
103
121
- name : Restore Reviewers Cache
104
122
id : reviewers-cache-restore
105
123
if : ${{ steps.changed_files.outputs.COMMENT_TIME != '' }}
@@ -289,4 +307,4 @@ jobs:
289
307
path : |
290
308
unique_tags_bak.txt
291
309
unique_reviewers_bak.txt
292
- key : ${{ runner.os }}-auto-assign-reviewers-${{ steps.extract-pr.outputs.PR_NUMBER }}-${{ steps.get_comment_time.outputs.CURRENT_TIME }}
310
+ key : ${{ runner.os }}-auto-assign-reviewers-${{ steps.extract-pr.outputs.PR_NUMBER }}-${{ steps.get_comment_time.outputs.CURRENT_TIME }}
0 commit comments