fix: extend AI co-author pattern check with more model names#788
Conversation
Add claude, anthropic, openai, chatgpt, gemini, deepseek, mistral, llama, codestral to the blocked co-author pattern list to catch more AI-generated co-author lines.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideExtends the existing GitHub Actions commitlint workflow’s AI co-author detection by expanding the blocked regex pattern with additional popular AI/model vendor names for both PR body and commit message checks. Sequence diagram for updated AI co-author pattern check in commitlint workflowsequenceDiagram
actor Developer
participant GitHub
participant commitlint_workflow
participant pr_body_check_step
participant commit_msg_check_step
participant grep
Developer->>GitHub: open pull_request
GitHub->>commitlint_workflow: trigger workflow
commitlint_workflow->>pr_body_check_step: set BLOCKED_PATTERN
pr_body_check_step->>grep: grep -Eiq BLOCKED_PATTERN on PR_BODY
alt [PR body matches extended AI co-author pattern]
pr_body_check_step-->>commitlint_workflow: nonzero exit (fail job)
else [no match]
pr_body_check_step-->>commitlint_workflow: success
end
commitlint_workflow->>commit_msg_check_step: set BLOCKED_PATTERN
commit_msg_check_step->>commit_msg_check_step: git log commit messages
commit_msg_check_step->>grep: grep -Eiq BLOCKED_PATTERN on COMMIT_MSGS
alt [commit messages match extended AI co-author pattern]
commit_msg_check_step-->>commitlint_workflow: nonzero exit (fail job)
else [no match]
commit_msg_check_step-->>commitlint_workflow: success
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review你好!我是CodeGeeX。我已经仔细审查了你提供的 Git Diff 内容。 这次修改的主要目的是在 GitHub Actions 的 CI 流程中,扩展对 AI 生成代码的 以下是详细的审查意见和改进建议: 1. 语法与逻辑问题
2. 代码质量
3. 代码性能
4. 代码安全
改进建议与重构代码为了解决上述问题,建议进行以下重构:
重构后的代码: - name: check PR description for AI co-author pattern
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
# 优化正则:使用分组,避免重复 Co-authored-by:
# 使用 \b 词边界替代 .* 防止误匹配(如 Dave, email)
BLOCKED_PATTERN='Co-authored-by:.*\b(ai|agent|copilot|llm|gpt|claude|anthropic|openai|chatgpt|gemini|deepseek|mistral|llama|codestral)\b'
# 安全修复:将 PR Body 写入文件再 grep,避免 Shell 元字符导致的命令注入
echo "${PR_BODY}" > pr_body.txt
if grep -Eiq "${BLOCKED_PATTERN}" pr_body.txt; then
echo "FAIL: PR description contains blocked co-author AI pattern." >&2
echo "Blocked pattern: ${BLOCKED_PATTERN}" >&2
exit 1
fi
echo "PASS: No blocked AI co-author patterns found in PR description."
rm -f pr_body.txt
- name: check commit messages for AI co-author pattern
env:
# 质量优化:将公共正则提取到顶层 env(或使用 GITHUB_ENV 跨步骤共享)
BLOCKED_PATTERN: 'Co-authored-by:.*\b(ai|agent|copilot|llm|gpt|claude|anthropic|openai|chatgpt|gemini|deepseek|mistral|llama|codestral)\b'
shell: bash
run: |
# 性能优化:直接将 git log 输出重定向到文件,避免变量赋值和 echo 时的解析风险
git log --format=%B ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} > commit_msgs.txt 2>/dev/null || true
if [[ -s commit_msgs.txt ]] && grep -Eiq "${BLOCKED_PATTERN}" commit_msgs.txt; then
echo "FAIL: Commit messages contain blocked co-author AI pattern." >&2
echo "Blocked pattern: ${BLOCKED_PATTERN}" >&2
exit 1
fi
echo "PASS: No blocked AI co-author patterns found in commit messages."
rm -f commit_msgs.txt改进点详细说明:
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
BLOCKED_PATTERNregex is duplicated in two steps; consider factoring it into a single definition (e.g., an env var at the job level or a YAML anchor) to avoid divergence when updating the list in future. - The regex has become quite long and hard to read; consider breaking the alternatives onto multiple lines with a here-doc or using grouping (e.g.,
Co-authored-by:.*(ai|agent|copilot|...)) to make future edits less error-prone.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `BLOCKED_PATTERN` regex is duplicated in two steps; consider factoring it into a single definition (e.g., an env var at the job level or a YAML anchor) to avoid divergence when updating the list in future.
- The regex has become quite long and hard to read; consider breaking the alternatives onto multiple lines with a here-doc or using grouping (e.g., `Co-authored-by:.*(ai|agent|copilot|...)`) to make future edits less error-prone.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia, hudeng-go The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Add claude, anthropic, openai, chatgpt, gemini, deepseek, mistral, llama, codestral to the blocked co-author pattern list to catch more AI-generated co-author lines.
Summary by Sourcery
Build: