feat: add AI co-author pattern check for PR and commits#783
Open
hudeng-go wants to merge 1 commit intolinuxdeepin:masterfrom
Open
feat: add AI co-author pattern check for PR and commits#783hudeng-go wants to merge 1 commit intolinuxdeepin:masterfrom
hudeng-go wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
Contributor
hudeng-go
commented
Apr 29, 2026
- Check PR description for blocked AI co-author patterns (ai, agent, copilot, llm, gpt)
- Check commit messages for the same patterns
- Avoid AI-generated content copyright risks
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
Contributor
deepin pr auto review这段代码是一个 GitHub Actions 工作流配置文件的差异,目的是在 Pull Request (PR) 流程中增加对 "AI 共同作者"(AI Co-author)的检查。它试图阻止在 PR 描述或提交信息中包含由 AI 工具(如 Copilot, GPT 等)生成的 以下是对该代码的详细审查,包括语法逻辑、代码质量、代码性能和代码安全方面的改进意见: 1. 语法逻辑审查
2. 代码质量审查
3. 代码性能审查
4. 代码安全审查
5. 改进建议以下是改进后的代码,整合了上述建议: name: Commitlint
on: pull_request
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: check PR description and commits for AI co-author pattern
id: check_ai_coauthor
shell: bash
env:
BLOCKED_PATTERN: 'Co-authored-by:.*ai|Co-authored-by:.*agent|Co-authored-by:.*copilot|Co-authored-by:.*llm|合并自.*AI|合并自.*ai'
run: |
# Function to check for blocked patterns
check_text() {
local text="$1"
local source_name="$2"
if printf '%s' "${text}" | grep -qiE "${BLOCKED_PATTERN}"; then
echo "FAIL: ${source_name} contains blocked co-author AI pattern." >&2
echo "Blocked pattern: ${BLOCKED_PATTERN}" >&2
echo "Please remove AI-generated co-author lines." >&2
exit 1
fi
}
# Check PR Body
# 使用 printf 代替 echo 以增强安全性
printf '%s' "${{ github.event.pull_request.body }}" | check_text "PR description"
# Check Commit Messages
# 获取提交信息,如果失败则忽略(例如在空 PR 时)
COMMIT_MSGS=$(git log --format=%B ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} 2>/dev/null || true)
if [[ -n "${COMMIT_MSGS}" ]]; then
printf '%s' "${COMMIT_MSGS}" | check_text "Commit messages"
fi
echo "PASS: No blocked AI co-author patterns found."改进点总结:
这段改进后的代码在保持原有功能的同时,提高了安全性、可维护性和可读性。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.