From 920aea69dc5a289f5d6d11dd4525bf5e90aec6e2 Mon Sep 17 00:00:00 2001 From: linhemin Date: Mon, 10 Feb 2025 19:05:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?ci(=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=A3=80=E6=9F=A5):=20=E6=B7=BB=E5=8A=A0=20Git=20Commit=20Angu?= =?UTF-8?q?lar=20=E9=A3=8E=E6=A0=BC=E6=A3=80=E6=9F=A5=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 GitHub Actions 工作流,检查 PR 中的提交信息是否符合 Angular 规范 - 在 PR 创建、更新或重新打开时,以及推送至 main 分支时触发检查 - 使用正则表达式验证提交信息的格式 - 如果提交信息不符合规范,自动关闭 PR --- .github/workflows/commit-check.yml | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/commit-check.yml diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml new file mode 100644 index 0000000..46de0b0 --- /dev/null +++ b/.github/workflows/commit-check.yml @@ -0,0 +1,55 @@ +name: Git Commit Angular Style Check + +on: + pull_request: + types: [ opened, synchronize, reopened ] + +jobs: + commit-check: + runs-on: ubuntu-latest + steps: + - name: Checkout 喵喵代码 + uses: actions/checkout@v2 + + - name: 获取提交信息 + id: get_commits + run: | + echo "喵~ 正在获取提交信息呢~" + git fetch --no-tags origin ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} + COMMITS=$(git log --pretty=format:"%s" ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}) + echo "找到以下提交:" + echo "$COMMITS" + echo "::set-output name=messages::$COMMITS" + + - name: 检查提交信息是否符合 Angular 规范 + id: check_commits + continue-on-error: true + run: | + echo "喵~ 开始检查提交信息啦~" + PATTERN='^(feat|fix|docs|style|refactor|perf|test|chore|ci)(\([a-zA-Z0-9\-]+\))?: .+' + FAIL=0 + while IFS= read -r line; do + if [[ ! $line =~ $PATTERN ]]; then + echo "❌ 无效的提交信息: $line" + FAIL=1 + fi + done <<< "${{ steps.get_commits.outputs.messages }}" + if [ $FAIL -eq 1 ]; then + echo "::set-output name=result::fail" + exit 1 + else + echo "::set-output name=result::pass" + fi + + - name: 如果提交不符合规范,则自动关闭 PR + if: steps.check_commits.outputs.result == 'fail' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + echo "喵~ 检测到有无效的提交信息,正在关闭该 PR 呀~" + PR_NUMBER=${{ github.event.pull_request.number }} + curl -X PATCH \ + -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER \ + -d '{"state": "closed"}' From bfc4499ea22f45ddeeff9c7b2f7e9316f8edaa00 Mon Sep 17 00:00:00 2001 From: linhemin Date: Mon, 10 Feb 2025 19:27:06 +0800 Subject: [PATCH 2/4] fix(ci): update set-output syntax to use $GITHUB_OUTPUT Replace deprecated echo "::set-output name=messages::$COMMITS" with echo "messages=$COMMITS" >> $GITHUB_OUTPUT in the GitHub Actions workflow. --- .github/workflows/commit-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml index 46de0b0..1c0b473 100644 --- a/.github/workflows/commit-check.yml +++ b/.github/workflows/commit-check.yml @@ -19,7 +19,7 @@ jobs: COMMITS=$(git log --pretty=format:"%s" ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}) echo "找到以下提交:" echo "$COMMITS" - echo "::set-output name=messages::$COMMITS" + echo "messages=$COMMITS" >> $GITHUB_OUTPUT - name: 检查提交信息是否符合 Angular 规范 id: check_commits From f0c94039012161985a840d1d2637142a12219dd7 Mon Sep 17 00:00:00 2001 From: linhemin Date: Mon, 10 Feb 2025 19:38:43 +0800 Subject: [PATCH 3/4] =?UTF-8?q?docs(readme):=20=E6=B7=BB=E5=8A=A0=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E6=8C=87=E5=8D=97=E4=B8=AD=E6=94=AF=E6=8C=81=E7=9A=84?= =?UTF-8?q?=20type=20=E8=A1=A8=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/readme.md b/readme.md index ed312e5..382e4d0 100644 --- a/readme.md +++ b/readme.md @@ -46,6 +46,34 @@ python3 app.py | DB_NAME | 数据库名 | emby_bot_db | | ADMIN_LIST | Bot 管理员的 Telegram ID 列表(用逗号分隔) | 123456789,987654321 | +## 贡献指南 +欢迎贡献代码!为了确保项目的高质量和一致性,请遵循以下贡献规程: +### 提交规范 +- 提交信息必须符合 Angular 提交信息规范,格式如下: + - `type(scope): description` + - 例如:`feat(user): 添加用户注册功能` +### 与数据库、API 代码相关的更改 +- 请确保所有更改都经过严格的测试,并且不会引入新的错误。 +### 创建 Pull Request +- 请确保创建 Pull Request 前进行本地测试,确保通过所有 CI/CD 测试。 +### 支持的 Type 列表 + +| Type | 描述 | +|----------|-------------------------------------------------------------| +| feat | 添加新功能,比如新增用户注册、功能扩展等 | +| fix | 修复 bug 或错误,解决问题的修改 | +| docs | 文档相关修改,如更新说明文档、README、注释等 | +| style | 代码格式、标点、空格等修改,不影响代码逻辑运行 | +| refactor | 代码重构,调整代码结构而不改变功能 | +| perf | 性能优化修改,提升效率或降低资源消耗 | +| test | 添加或更新测试代码,保证项目稳定性 | +| chore | 杂项维护,如依赖更新、构建脚本修改,不涉及代码逻辑 | +| ci | 持续集成相关修改,如 GitHub Actions 工作流程优化 | + +--- +感谢您的贡献! + + ### Thanks - [Pyrogram](https://docs.pyrogram.org/) - Telegram API for Python - [SQLAlchemy](https://www.sqlalchemy.org/) - Python SQL Toolkit and Object-Relational Mapping From e262826053c0e4e94553d4f52d78f262b2e07005 Mon Sep 17 00:00:00 2001 From: linhemin Date: Mon, 10 Feb 2025 21:05:25 +0800 Subject: [PATCH 4/4] =?UTF-8?q?ci(commit-check):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=A1=E6=81=AF=E6=A3=80=E6=9F=A5=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81=E4=B8=AD=E7=9A=84=E5=A4=9A=E8=A1=8C=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 EOF 标记替代单行输出,以正确处理多行提交信息 - 优化了 GitHub Actions 工作流中的变量输出方式 --- .github/workflows/commit-check.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml index 1c0b473..d734678 100644 --- a/.github/workflows/commit-check.yml +++ b/.github/workflows/commit-check.yml @@ -19,7 +19,9 @@ jobs: COMMITS=$(git log --pretty=format:"%s" ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}) echo "找到以下提交:" echo "$COMMITS" - echo "messages=$COMMITS" >> $GITHUB_OUTPUT + echo "messages<> $GITHUB_OUTPUT + echo "$COMMITS" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT - name: 检查提交信息是否符合 Angular 规范 id: check_commits