From c83ba679655a84ab8b86389dcc1a620f2ae7b489 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 13 Jul 2025 01:00:11 +0300 Subject: [PATCH] feat: add imperative mood --- .github/workflows/commit-check.yml | 1 + README.md | 6 ++++++ action.yml | 5 +++++ main.py | 13 ++++++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml index dc398fd..f75de56 100644 --- a/.github/workflows/commit-check.yml +++ b/.github/workflows/commit-check.yml @@ -26,5 +26,6 @@ jobs: author-email: true commit-signoff: true merge-base: true + imperative: true job-summary: true pr-comments: ${{ github.event_name == 'pull_request' }} diff --git a/README.md b/README.md index 9e9df7b..c9dd2de 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ jobs: author-email: true commit-signoff: true merge-base: false + imperative: true job-summary: true pr-comments: ${{ github.event_name == 'pull_request' }} ``` @@ -114,6 +115,11 @@ jobs: > > To use this feature, you need fetch all history for all branches by setting `fetch-depth: 0` in `actions/checkout`. +### `imperative` + +- **Description**: check commit message is imperative mood. +- Default: `true` + ### `dry-run` - **Description**: run checks without failing. exit code is 0 otherwise is 1. diff --git a/action.yml b/action.yml index cdd75ea..5f164b1 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,10 @@ inputs: description: check current branch is rebased onto target branch required: false default: false + imperative: + description: check commit message is in imperative mood + required: false + default: true dry-run: description: run checks without failing required: false @@ -76,6 +80,7 @@ runs: AUTHOR_EMAIL: ${{ inputs.author-email }} COMMIT_SIGNOFF: ${{ inputs.commit-signoff }} MERGE_BASE: ${{ inputs.merge-base }} + IMPERATIVE: ${{ inputs.imperative }} DRY_RUN: ${{ inputs.dry-run }} JOB_SUMMARY: ${{ inputs.job-summary }} PR_COMMENTS: ${{ inputs.pr-comments }} diff --git a/main.py b/main.py index 87434ec..ef9c920 100755 --- a/main.py +++ b/main.py @@ -17,6 +17,7 @@ AUTHOR_EMAIL = os.getenv("AUTHOR_EMAIL", "false") COMMIT_SIGNOFF = os.getenv("COMMIT_SIGNOFF", "false") MERGE_BASE = os.getenv("MERGE_BASE", "false") +IMPERATIVE = os.getenv("IMPERATIVE", "true") DRY_RUN = os.getenv("DRY_RUN", "false") JOB_SUMMARY = os.getenv("JOB_SUMMARY", "false") PR_COMMENTS = os.getenv("PR_COMMENTS", "false") @@ -34,6 +35,7 @@ def log_env_vars(): print(f"AUTHOR_EMAIL = {AUTHOR_EMAIL}") print(f"COMMIT_SIGNOFF = {COMMIT_SIGNOFF}") print(f"MERGE_BASE = {MERGE_BASE}") + print(f"IMPERATIVE = {IMPERATIVE}") print(f"DRY_RUN = {DRY_RUN}") print(f"JOB_SUMMARY = {JOB_SUMMARY}") print(f"PR_COMMENTS = {PR_COMMENTS}\n") @@ -48,12 +50,21 @@ def run_commit_check() -> int: "--author-email", "--commit-signoff", "--merge-base", + "--imperative", ] args = [ arg for arg, value in zip( args, - [MESSAGE, BRANCH, AUTHOR_NAME, AUTHOR_EMAIL, COMMIT_SIGNOFF, MERGE_BASE], + [ + MESSAGE, + BRANCH, + AUTHOR_NAME, + AUTHOR_EMAIL, + COMMIT_SIGNOFF, + MERGE_BASE, + IMPERATIVE, + ], ) if value == "true" ]