From 2eba9cf352099a0cefa930d59ff995e8dca06d56 Mon Sep 17 00:00:00 2001
From: Pierre Smeyers <pierre.smeyers@gmail.com>
Date: Thu, 18 May 2023 15:53:29 +0200
Subject: [PATCH] feat(release): make release commit message configurable

---
 README.md                      |  1 +
 kicker.json                    |  6 ++++++
 templates/gitlab-ci-python.yml | 12 +++++++-----
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index c63f09d..c03c394 100644
--- a/README.md
+++ b/README.md
@@ -306,6 +306,7 @@ The release job is bound to the `publish` stage, appears only on production and
 | `GIT_USERNAME`          | Git username for Git push operations (see below)                        | _none_            |
 | :lock: `GIT_PASSWORD`   | Git password for Git push operations (see below)                        | _none_            |
 | :lock: `GIT_PRIVATE_KEY`| SSH key for Git push operations (see below)                             | _none_            |
+| `PYTHON_RELEASE_COMMIT_MESSAGE`| The Git commit message to use on the release commit. This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax). Available in the template context are current_version and new_version. | `chore(python-release): {current_version} → {new_version}` |
 | `PYTHON_REPOSITORY_URL`| Target PyPI repository to publish packages                              | _[GitLab project's PyPI packages repository](https://docs.gitlab.com/ee/user/packages/pypi_repository/)_ |
 | `PYTHON_REPOSITORY_USERNAME`| Target PyPI repository username credential                              | `gitlab-ci-token` |
 | :lock: `PYTHON_REPOSITORY_PASSWORD`| Target PyPI repository password credential                              | `$CI_JOB_TOKEN` |
diff --git a/kicker.json b/kicker.json
index 60821c8..65ac497 100644
--- a/kicker.json
+++ b/kicker.json
@@ -194,6 +194,12 @@
           "type": "boolean",
           "advanced": true
         },
+        {
+          "name": "PYTHON_RELEASE_COMMIT_MESSAGE",
+          "description": "The Git commit message to use on the release commit. This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax). Available in the template context are current_version and new_version.",
+          "default": "chore(python-release): {current_version} → {new_version}",
+          "advanced": true
+        },
         {
           "name": "GIT_USERNAME",
           "description": "Git username for Git push operations",
diff --git a/templates/gitlab-ci-python.yml b/templates/gitlab-ci-python.yml
index 12acc84..8427b0f 100644
--- a/templates/gitlab-ci-python.yml
+++ b/templates/gitlab-ci-python.yml
@@ -81,6 +81,7 @@ variables:
   PYTHON_SBOM_OPTS: "--catalogers python-index-cataloger"
 
   PYTHON_RELEASE_NEXT: "minor"
+  PYTHON_RELEASE_COMMIT_MESSAGE: "chore(python-release): {current_version} → {new_version}"
 
   # By default, publish on the Packages registry of the project
   # https://docs.gitlab.com/ee/user/packages/pypi_repository/#authenticate-with-a-ci-job-token
@@ -451,33 +452,34 @@ variables:
       py_next_version=$(poetry version --short)
       # Git commit and tag
       git add pyproject.toml
-      git commit -m "chore(python-release): $py_cur_version → $py_next_version"
+      # emulate Bumpversion to generate commit message
+      py_commit_message=$(python -c "print('$PYTHON_RELEASE_COMMIT_MESSAGE'.format(current_version='$py_cur_version', new_version='$py_next_version'))")
+      git commit -m "$py_commit_message"
       git tag "$py_next_version"
     else
       # Setuptools / bumpversion
       # shellcheck disable=SC2086
       pip install ${PIP_OPTS} bumpversion
-      py_commit_message="chore(python-release): {current_version} → {new_version}"
       if [[ "$py_next_version" ]]
       then
         # explicit release version (semantic-release)
         log_info "[bumpversion] change version \\e[1;94m${py_cur_version}\\e[0m → \\e[1;94m${py_next_version}\\e[0m"
         # create cfg in case it doesn't exist - will be updated by bumpversion
         touch .bumpversion.cfg
-        bumpversion ${TRACE+--verbose} --current-version "$py_cur_version" --commit --message "$py_commit_message" --tag --tag-name "{new_version}" "$py_release_part"
+        bumpversion ${TRACE+--verbose} --current-version "$py_cur_version" --commit ${PYTHON_RELEASE_COMMIT_MESSAGE+--message "$PYTHON_RELEASE_COMMIT_MESSAGE"} --tag --tag-name "{new_version}" "$py_release_part"
       elif [[ -f ".bumpversion.cfg" ]]
       then
         # current version shall be set in .bumpversion.cfg
         py_release_part="$PYTHON_RELEASE_NEXT"
         log_info "[bumpversion] increase \\e[1;94m${py_release_part}\\e[0m"
-        bumpversion ${TRACE+--verbose} --commit --message "$py_commit_message" --tag --tag-name "{new_version}" "$py_release_part"
+        bumpversion ${TRACE+--verbose} --commit ${PYTHON_RELEASE_COMMIT_MESSAGE+--message "$PYTHON_RELEASE_COMMIT_MESSAGE"} "$PYTHON_RELEASE_COMMIT_MESSAGE" --tag --tag-name "{new_version}" "$py_release_part"
       elif [[ -f "setup.py" ]]
       then
         # retrieve current version from setup.py
         py_cur_version=$(python setup.py --version)
         py_release_part="$PYTHON_RELEASE_NEXT"
         log_info "[bumpversion] increase \\e[1;94m${py_release_part}\\e[0m (from current \\e[1;94m${py_cur_version}\\e[0m)"
-        bumpversion ${TRACE+--verbose} --current-version "$py_cur_version" --commit --message "$py_commit_message" --tag --tag-name "{new_version}" "$py_release_part" setup.py
+        bumpversion ${TRACE+--verbose} --current-version "$py_cur_version" --commit ${PYTHON_RELEASE_COMMIT_MESSAGE+--message "$PYTHON_RELEASE_COMMIT_MESSAGE"} --tag --tag-name "{new_version}" "$py_release_part" setup.py
       else
         log_error "--- setup.py or .bumpversion.cfg file required to retrieve current version: cannot perform release"
         exit 1
-- 
GitLab