From 656ca71a8c7f0dd19e1305c85e1a345c8054c3c0 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 6 Apr 2025 20:47:24 +0300 Subject: [PATCH 01/12] docs: remove .readthedocs.yaml (#231) * docs: remove .readthedocs.yaml * chore: conf.py clean up --- .readthedocs.yaml | 17 ----------------- docs/conf.py | 5 ----- 2 files changed, 22 deletions(-) delete mode 100644 .readthedocs.yaml diff --git a/.readthedocs.yaml b/.readthedocs.yaml deleted file mode 100644 index 9bfb5c2..0000000 --- a/.readthedocs.yaml +++ /dev/null @@ -1,17 +0,0 @@ -# Read the Docs configuration file for Sphinx projects -# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details -version: 2 - -build: - os: ubuntu-22.04 - tools: - python: "3.12" - -sphinx: - builder: "dirhtml" - configuration: docs/conf.py - -# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html -python: - install: - - requirements: docs/requirements.txt diff --git a/docs/conf.py b/docs/conf.py index 53d5b56..2f3e1d9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,11 +25,6 @@ "sphinx.ext.viewcode", ] -intersphinx_mapping = { - "python": ("https://docs.python.org/3", None), - "requests": ("https://requests.readthedocs.io/en/latest/", None), -} - autodoc_member_order = "bysource" templates_path = ["_templates"] From 742fc42d011930827a7fc2b9129a7ef7dc15ba6d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 21:20:01 +0300 Subject: [PATCH 02/12] ci: pre-commit autoupdate (#232) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cc6ee16..cf938ad 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: - id: requirements-txt-fixer - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.11.2 + rev: v0.11.4 hooks: # Run the linter. - id: ruff @@ -35,7 +35,7 @@ repos: hooks: - id: codespell - repo: https://github.com/commit-check/commit-check - rev: v0.9.4 + rev: v0.9.5 hooks: - id: check-message # - id: check-branch # uncomment if you need. From 0219eb33ad5099ab9459c52c876d9c24dc8e1bc1 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 1 Jun 2025 19:30:04 +0300 Subject: [PATCH 03/12] chore: move deps from `requirements.txt` to `pyproject.toml` (#233) * chore: remove requirements.txt files * install nox * install nox * Apply suggestions from code review Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * update noxfile.py * update noxfile.py and pyproject.tom * fix pyproject.toml * move sphinx-autobuild into pyproject.toml --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .github/workflows/main.yml | 14 +++++++++++--- .gitpod.yml | 4 ++-- docs/requirements.txt | 3 --- noxfile.py | 14 +++----------- pyproject.toml | 5 +++++ requirements-dev.txt | 5 ----- 6 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 docs/requirements.txt delete mode 100644 requirements-dev.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6333198..e470c14 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,11 @@ jobs: - uses: actions/setup-python@v5 with: python-version: '3.x' - - run: pip install -r requirements-dev.txt + + - name: Install nox + run: | + python -m pip install --upgrade pip + python -m pip install nox - name: Run pre-commit run: | @@ -63,7 +67,7 @@ jobs: python-version: ${{ matrix.py }} - run: | pip install --upgrade pip - pip install -r requirements-dev.txt + pip install .[dev] - name: Download wheel artifact uses: actions/download-artifact@v4 @@ -85,7 +89,11 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.10" - - run: pip install -r requirements-dev.txt + + - name: Install nox + run: | + python -m pip install --upgrade pip + python -m pip install nox - name: Build docs run: nox -s docs diff --git a/.gitpod.yml b/.gitpod.yml index 8123636..4f2f475 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -3,6 +3,6 @@ # and commit this file to your remote git repository to share the goodness with others. tasks: - - before: pip install --upgrade pip && pip install -r requirements-dev.txt + - before: pip install --upgrade pip init: pre-commit install - command: pip install -e . + command: pip install -e .[dev] diff --git a/docs/requirements.txt b/docs/requirements.txt deleted file mode 100644 index af718d9..0000000 --- a/docs/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ - -. -sphinx-immaterial diff --git a/noxfile.py b/noxfile.py index 079df8a..50599af 100644 --- a/noxfile.py +++ b/noxfile.py @@ -4,11 +4,6 @@ nox.options.reuse_existing_virtualenvs = True nox.options.sessions = ["lint"] -REQUIREMENTS = { - "dev": "requirements-dev.txt", - "docs": "docs/requirements.txt", -} - # ----------------------------------------------------------------------------- # Development Commands # ----------------------------------------------------------------------------- @@ -54,8 +49,7 @@ def commit_check(session): @nox.session() def coverage(session): - session.install(".") - session.install("-r", REQUIREMENTS["dev"]) + session.install('.[test]') session.run("coverage", "run", "--source", "commit_check", "-m", "pytest") session.run("coverage", "report") session.run("coverage", "xml") @@ -63,13 +57,11 @@ def coverage(session): @nox.session() def docs(session): - session.install(".") - session.install("-r", REQUIREMENTS["docs"]) + session.install('.[docs]') session.run("sphinx-build", "-E", "-W", "-b", "html", "docs", "_build/html") @nox.session(name="docs-live") def docs_live(session): - session.install(".") - session.install("-r", REQUIREMENTS["docs"], "sphinx-autobuild") + session.install('.[docs]') session.run("sphinx-autobuild", "-b", "html", "docs", "_build/html") diff --git a/pyproject.toml b/pyproject.toml index c84d181..3f0759e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,11 @@ tracker = "https://github.com/commit-check/commit-check/issues" # ... other project metadata fields as specified in: # https://packaging.python.org/en/latest/specifications/declaring-project-metadata/ +[project.optional-dependencies] +dev = ['nox'] +test = ['coverage', 'pytest', 'pytest-mock'] +docs = ['sphinx-immaterial', 'sphinx-autobuild'] + [tool.setuptools] zip-safe = false packages = ["commit_check"] diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 120645f..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,5 +0,0 @@ -coverage -git+https://github.com/wntrblm/nox.git@main -pre-commit -pytest -pytest-mock From 309bc74baf7b3a0b38049d8af0ef601ad44cdad4 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 13 Jun 2025 11:02:48 +0300 Subject: [PATCH 04/12] Potential fix Workflow does not contain permissions (#234) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e470c14..3163c6c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,8 @@ name: main +permissions: + contents: write + on: push: branches: From 53ea82057400fea2b90b53b9614ef305cedead57 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 13 Jun 2025 11:05:37 +0300 Subject: [PATCH 05/12] fix: potential fix workflow does not contain permissions (#235) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- .github/workflows/release-drafter.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index d25c13e..0b36c74 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -6,6 +6,10 @@ on: - "main" workflow_dispatch: +permissions: + contents: read + pull-requests: write + jobs: draft-release: uses: commit-check/.github/.github/workflows/release-drafter.yml@main From 634075918a736be7440fa612d018ad5360283459 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 13 Jun 2025 11:21:17 +0300 Subject: [PATCH 06/12] fix: potential fix workflow does not contain permissions (#236) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- .github/workflows/publish-image.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml index 39dd16e..9c148f6 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yml @@ -1,5 +1,8 @@ name: publish image +permissions: + contents: read + on: push: paths: From 6cdeb1405270b21f3e7df33b730a5decf871bdbc Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 13 Jun 2025 11:31:31 +0300 Subject: [PATCH 07/12] fix: potential fix workflow does not contain permissions (#237) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- .github/workflows/labeler.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 52689d6..659f080 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -1,5 +1,9 @@ name: PR Autolabeler +permissions: + contents: read + pull-requests: write + on: # pull_request event is required for autolabeler pull_request: From 485e745ec7b7a675680b93cd62d2138d3f10e4f4 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 13 Jun 2025 11:33:54 +0300 Subject: [PATCH 08/12] fix: Potential fix Workflow does not contain permissions #235 --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 0b36c74..182ecec 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -7,7 +7,7 @@ on: workflow_dispatch: permissions: - contents: read + contents: write pull-requests: write jobs: From 031950fa5b33d7832a553c2cf9db23b365ba8617 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 22 Jun 2025 16:53:25 +0200 Subject: [PATCH 09/12] chore: update CODEOWNERS (#238) * chore: update CODEOWNERS * chore: update CODEOWNERS * fix: Update labeler.yml to fix permission issue * chore: Update CODEOWNERS --- .github/CODEOWNERS | 2 +- .github/workflows/labeler.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 4f08a45..9861b85 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @shenxianpeng +* @commit-check/commit-check-maintain diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 659f080..13e989a 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -1,7 +1,7 @@ name: PR Autolabeler permissions: - contents: read + contents: write pull-requests: write on: From 9f8b78e98c1b9a6448f0f41ac608c085d9698fad Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Wed, 25 Jun 2025 10:01:14 +0300 Subject: [PATCH 10/12] chore: Update CODEOWNERS --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9861b85..37cffb1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @commit-check/commit-check-maintain +* @commit-check/developers From d87094260d660c645b3f0ddd91f55baae7e136eb Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 4 Jul 2025 03:37:00 +0300 Subject: [PATCH 11/12] docs: update README.rst (#239) --- README.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 2f19257..b9ac03a 100644 --- a/README.rst +++ b/README.rst @@ -42,15 +42,14 @@ Configuration Use Default Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~ -- If you don't set ``.commit-check.yml``, Commit Check will use the `default configuration `_. +- **Commit Check** uses a `default configuration `_ if you do not provide a ``.commit-check.yml`` file. -- The commit message will follow the rules of `Conventional Commits `_, - branch naming follow the rules of `Conventional Branch `_. +- The default configuration enforces commit message rules based on the `Conventional Commits `_ specification and branch naming rules based on the `Conventional Branch `_ convention. Use Custom Configuration ~~~~~~~~~~~~~~~~~~~~~~~~ -Create a config file ``.commit-check.yml`` under your repository's root directory, e.g., `.commit-check.yml `_ +To customize the behavior, create a config file ``.commit-check.yml`` under your repository's root directory, e.g., `.commit-check.yml `_ Usage ----- From dac2281855bf9a39202e766b7caaf58fb3fbe8e2 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Mon, 7 Jul 2025 01:05:33 +0300 Subject: [PATCH 12/12] fix: display a clear message when there are no commits (#244) * fix: check if there are commit in the current branch * fix: check if there are commit in the current branch * add output when no commits found * docs: change output when no commits found * test: add more test for util --- .pre-commit-config.yaml | 4 +-- commit_check/util.py | 17 +++++++++++ tests/util_test.py | 66 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cf938ad..d289da2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,5 +41,5 @@ repos: # - id: check-branch # uncomment if you need. - id: check-author-name # uncomment if you need. - id: check-author-email # uncomment if you need. - # - id: commit-signoff # uncomment if you need. - # - id: check-merge-base # requires download all git history + # - id: check-commit-signoff # uncomment if you need. + # - id: check-merge-base # requires download all git history diff --git a/commit_check/util.py b/commit_check/util.py index a63d6c1..52b4eaa 100644 --- a/commit_check/util.py +++ b/commit_check/util.py @@ -29,6 +29,21 @@ def get_branch_name() -> str: return branch_name.strip() +def has_commits() -> bool: + """Check if there are any commits in the current branch. + :returns: `True` if there are commits, `False` otherwise. + """ + try: + subprocess.run( + ["git", "rev-parse", "--verify", "HEAD"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + check=True + ) + return True + except subprocess.CalledProcessError: + return False + def get_commit_info(format_string: str, sha: str = "HEAD") -> str: """Get latest commits information :param format_string: could be @@ -41,6 +56,8 @@ def get_commit_info(format_string: str, sha: str = "HEAD") -> str: :returns: A `str`. """ + if has_commits() is False: + return 'Repo has no commits yet.' try: commands = [ 'git', 'log', '-n', '1', f"--pretty=format:%{format_string}", f"{sha}", diff --git a/tests/util_test.py b/tests/util_test.py index 42870ea..e42ba24 100644 --- a/tests/util_test.py +++ b/tests/util_test.py @@ -1,6 +1,7 @@ import pytest import subprocess from commit_check.util import get_branch_name +from commit_check.util import has_commits from commit_check.util import git_merge_base from commit_check.util import get_commit_info from commit_check.util import cmd_output @@ -46,6 +47,43 @@ def test_get_branch_name_with_exception(self, mocker): ] assert retval == "" + class TestHasCommits: + def test_has_commits_true(self, mocker): + # Must return True when git rev-parse HEAD succeeds + m_subprocess_run = mocker.patch( + "subprocess.run", + return_value=None + ) + retval = has_commits() + assert m_subprocess_run.call_count == 1 + assert m_subprocess_run.call_args[0][0] == [ + "git", "rev-parse", "--verify", "HEAD" + ] + assert m_subprocess_run.call_args[1] == { + 'stdout': subprocess.DEVNULL, + 'stderr': subprocess.DEVNULL, + 'check': True + } + assert retval is True + + def test_has_commits_false(self, mocker): + # Must return False when git rev-parse HEAD fails + m_subprocess_run = mocker.patch( + "subprocess.run", + side_effect=subprocess.CalledProcessError(128, "git rev-parse") + ) + retval = has_commits() + assert m_subprocess_run.call_count == 1 + assert m_subprocess_run.call_args[0][0] == [ + "git", "rev-parse", "--verify", "HEAD" + ] + assert m_subprocess_run.call_args[1] == { + 'stdout': subprocess.DEVNULL, + 'stderr': subprocess.DEVNULL, + 'check': True + } + assert retval is False + class TestGitMergeBase: @pytest.mark.parametrize("returncode,expected", [ (0, 0), # ancestor exists @@ -78,20 +116,45 @@ class TestGetCommitInfo: ] ) def test_get_commit_info(self, mocker, format_string): - # Must call get_commit_info with given argument. + # Must call get_commit_info with given argument when there are commits. + m_has_commits = mocker.patch( + "commit_check.util.has_commits", + return_value=True + ) m_cmd_output = mocker.patch( "commit_check.util.cmd_output", return_value=" fake commit message " ) retval = get_commit_info(format_string) + assert m_has_commits.call_count == 1 assert m_cmd_output.call_count == 1 assert m_cmd_output.call_args[0][0] == [ "git", "log", "-n", "1", f"--pretty=format:%{format_string}", "HEAD" ] assert retval == " fake commit message " + def test_get_commit_info_no_commits(self, mocker): + # Must return 'Repo has no commits yet.' when there are no commits. + m_has_commits = mocker.patch( + "commit_check.util.has_commits", + return_value=False + ) + m_cmd_output = mocker.patch( + "commit_check.util.cmd_output", + return_value=" fake commit message " + ) + format_string = "s" + retval = get_commit_info(format_string) + assert m_has_commits.call_count == 1 + assert m_cmd_output.call_count == 0 # Should not call cmd_output + assert retval == "Repo has no commits yet." + def test_get_commit_info_with_exception(self, mocker): # Must return empty string when exception raises in cmd_output. + m_has_commits = mocker.patch( + "commit_check.util.has_commits", + return_value=True + ) m_cmd_output = mocker.patch( "commit_check.util.cmd_output", return_value=" fake commit message " @@ -104,6 +167,7 @@ def test_get_commit_info_with_exception(self, mocker): ) format_string = "s" retval = get_commit_info(format_string) + assert m_has_commits.call_count == 1 assert m_cmd_output.call_count == 1 assert m_cmd_output.call_args[0][0] == [ "git", "log", "-n", "1", f"--pretty=format:%{format_string}", "HEAD" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy