|
85 | 85 | ENABLE_LINTERS: "true" |
86 | 86 | ENABLE_AST: "true" |
87 | 87 | ENABLE_DEPENDENCY_ANALYSIS: "true" |
88 | | - |
89 | | - - name: Enforce strict review |
90 | | - if: always() |
91 | | - uses: actions/github-script@v7 |
92 | | - with: |
93 | | - github-token: ${{ secrets.PAT_TOKEN }} |
94 | | - script: | |
95 | | - const { owner, repo } = context.repo; |
96 | | - const pr_number = ${{ fromJSON(steps.pr.outputs.result).number }}; |
97 | | -
|
98 | | - const { data: comments } = await github.rest.issues.listComments({ |
99 | | - owner, repo, issue_number: pr_number, per_page: 100 |
100 | | - }); |
101 | | -
|
102 | | - const aiComments = comments |
103 | | - .filter(c => c.user.type === 'Bot' || c.user.login.includes('github-actions')) |
104 | | - .filter(c => c.body.includes('AI CODE REVIEW') || c.body.includes('AI Code Review')) |
105 | | - .sort((a, b) => new Date(b.created_at) - new Date(a.created_at)); |
106 | | -
|
107 | | - if (aiComments.length === 0) { |
108 | | - core.setFailed('❌ 找不到 AI Review 結果留言 —— AI 審查可能沒跑完或 vLLM 連線失敗'); |
109 | | - return; |
110 | | - } |
111 | | -
|
112 | | - const latest = aiComments[0].body; |
113 | | - core.info('=== 最新 AI Review 留言節錄 ==='); |
114 | | - core.info(latest.slice(0, 500)); |
115 | | -
|
116 | | - const blockers = []; |
117 | | -
|
118 | | - if (/❌\s*REJECTED|❌\s*BLOCKED|Verdict.*REJECTED|verdict.*reject/i.test(latest)) { |
119 | | - blockers.push('AI 給出 REJECTED 判定'); |
120 | | - } |
121 | | -
|
122 | | - const critMatch = latest.match(/Critical[^0-9]*?(\d+)/i); |
123 | | - if (critMatch && parseInt(critMatch[1]) > 0) { |
124 | | - blockers.push(`發現 ${critMatch[1]} 個 Critical 問題`); |
125 | | - } |
126 | | -
|
127 | | - const scoreMatch = latest.match(/Quality Score[^\d]*(\d+)\s*\/\s*100/i); |
128 | | - if (scoreMatch && parseInt(scoreMatch[1]) < 60) { |
129 | | - blockers.push(`Quality Score 過低: ${scoreMatch[1]}/100(門檻 60)`); |
130 | | - } |
131 | | -
|
132 | | - if (blockers.length > 0) { |
133 | | - const msg = '🚫 嚴格模式擋 PR:\n' + blockers.map(b => ` - ${b}`).join('\n'); |
134 | | - core.setFailed(msg); |
135 | | -
|
136 | | - await github.rest.issues.createComment({ |
137 | | - owner, repo, issue_number: pr_number, |
138 | | - body: `## 🚫 嚴格模式:此 PR 被擋下\n\n${blockers.map(b => `- ${b}`).join('\n')}\n\n請依照上方 AI Review 建議修正後重新 push。` |
139 | | - }); |
140 | | - } else { |
141 | | - core.info('✅ 嚴格模式通過,沒有發現 blocker'); |
142 | | - } |
0 commit comments