Skip to content

ci: Add pr.yml #1816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .commit-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
checks:

- check: message
regex: '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)|(Merge).*|(fixup!.*)'
error: "The commit message should be structured as follows:\n\n
<type>[optional scope]: <description>\n
[optional body]\n
[optional footer(s)]\n\n
More details please refer to https://www.conventionalcommits.org"
suggest: please check your commit message whether matches above regex

- check: branch
regex: ^(bugfix|feature|release|hotfix|task|chore)\/.+|(master)|(main)|(HEAD)|(PR-.+)
error: "Branches must begin with these types: bugfix/ feature/ release/ hotfix/ task/ chore/"
suggest: run command `git checkout -b type/branch_name`

Comment on lines +12 to +16
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

建议移除不必要的 PR- 分支命名支持

根据仓库历史记录分析,当前并未使用 PR- 前缀的分支命名模式。建议简化分支命名规则,移除 PR- 相关配置:

-    regex: ^(bugfix|feature|release|hotfix|task|chore)\/.+|(master)|(main)|(HEAD)|(PR-.+)
+    regex: ^(bugfix|feature|release|hotfix|task|chore)\/[\w\-\.]+|(master)|(main)|(HEAD)$

这样的修改可以:

  • 移除未使用的 PR- 前缀支持
  • 限制分支名称仅使用字母、数字、下划线、连字符和点号
  • 保持配置简洁明确
🔗 Analysis chain

验证分支命名规则的合理性

当前的分支命名规则需要进行以下验证:

  1. PR- 前缀是否确实需要支持?
  2. 分支名称中允许的字符没有限制,可能导致不规范的命名

建议修改正则表达式以限制分支名称中的字符:

-    regex: ^(bugfix|feature|release|hotfix|task|chore)\/.+|(master)|(main)|(HEAD)|(PR-.+)
+    regex: ^(bugfix|feature|release|hotfix|task|chore)\/[\w\-\.]+|(master)|(main)|(HEAD)|(PR-\d+)$

Let me gather more information about branch naming patterns in the repository.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查仓库中现有的分支命名模式
git branch -r | grep -E "PR-" || echo "No PR- prefixed branches found"

Length of output: 100


Script:

#!/bin/bash
# Check existing branch naming patterns
git branch -r | sort -u

# Check commit history for any PR related branch names
git log --all --format="%D" | grep -E "PR-|origin/" | sort -u

Length of output: 178

- check: author_name
regex: ^[A-Za-z ,.\'-]+$|.*(\[bot])
error: The committer name seems invalid
suggest: run command `git config user.name "Your Name"`

Comment on lines +17 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

改进作者姓名验证以支持国际化

当前的姓名验证规则过于严格,不支持国际化名称:

  1. 仅支持英文字母和有限的特殊字符
  2. 不支持中文、日文等非拉丁字符
  3. 不支持带音标的欧洲名称

建议修改为更包容的正则表达式:

-    regex: ^[A-Za-z ,.\'-]+$|.*(\[bot])
+    regex: ^[\p{L}\p{M}\p{N} ,.\'-]+$|.*(\[bot])

注意:此正则表达式使用了 Unicode 属性来匹配所有语言的字母和变音符号。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- check: author_name
regex: ^[A-Za-z ,.\'-]+$|.*(\[bot])
error: The committer name seems invalid
suggest: run command `git config user.name "Your Name"`
- check: author_name
regex: ^[\p{L}\p{M}\p{N} ,.\'-]+$|.*(\[bot])
error: The committer name seems invalid
suggest: run command `git config user.name "Your Name"`

- check: author_email
regex: ^.+@.+$
error: The committer email seems invalid
suggest: run command `git config user.email yourname@example.com`

Comment on lines +22 to +26
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

增强电子邮件地址验证

当前的电子邮件验证规则过于简单,可能允许无效的邮件地址。建议加强验证规则:

  1. 限制域名格式
  2. 验证用户名部分的有效字符
  3. 防止多个 @ 符号

建议使用更严格的正则表达式:

-    regex: ^.+@.+$
+    regex: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- check: author_email
regex: ^.+@.+$
error: The committer email seems invalid
suggest: run command `git config user.email yourname@example.com`
- check: author_email
regex: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
error: The committer email seems invalid
suggest: run command `git config user.email yourname@example.com`

- check: merge_base
regex: master # it can be master, develop, devel etc based on your project.
error: Current branch is not rebased onto target branch
suggest: please ensure your branch is rebased with the target branch
1 change: 1 addition & 0 deletions .github/workflows/artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
- 'qodana.yaml'
- 'SECURITY.md'
- '.imgbotconfig'
- '.commit-check.yml'
workflow_dispatch:
concurrency:
# On master/release, we don't want any jobs cancelled so the sha is used to name the group
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/commit-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Commit Check

on:
pull_request:
branches: 'master'

jobs:
commit-check:
runs-on: ubuntu-latest
permissions: # use permissions because of use pr-comments
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit
fetch-depth: 0 # required for merge-base check
- uses: commit-check/commit-check-action@v1
env:
GITHUB_TOKEN: ${{ secrets.CHANGELOG }} # use GITHUB_TOKEN because of use pr-comments
with:
message: false
branch: false
author-name: true
author-email: true
commit-signoff: true
merge-base: false
job-summary: true
pr-comments: true
Loading