From b5fe641d4c0c0228275d547e37838cf321f0f725 Mon Sep 17 00:00:00 2001 From: Michael de Villiers Date: Thu, 20 Apr 2023 14:00:09 +0200 Subject: [PATCH] Added pre-commit hooks for checking and updating news in projects using pre-commit (#498) * added ``towncrier-check`` to just check newly commited news fragments * added ``towncrier-update`` to actually update the news * added documentation section for ``pre-commit`` --- .pre-commit-hooks.yaml | 16 ++++++++++ docs/index.rst | 1 + docs/pre-commit.rst | 41 +++++++++++++++++++++++++ src/towncrier/newsfragments/498.feature | 1 + 4 files changed, 59 insertions(+) create mode 100644 .pre-commit-hooks.yaml create mode 100644 docs/pre-commit.rst create mode 100644 src/towncrier/newsfragments/498.feature diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 00000000..6c101c36 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,16 @@ +- id: towncrier-check + name: towncrier-check + description: Check towncrier changelog updates + entry: towncrier --draft + pass_filenames: false + types: [text] + files: newsfragments/ + language: python +- id: towncrier-update + name: towncrier-update + description: Update changelog with towncrier + entry: towncrier + pass_filenames: false + args: ["--yes"] + files: newsfragments/ + language: python diff --git a/docs/index.rst b/docs/index.rst index a0349e67..4bb31802 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,6 +23,7 @@ Reference cli configuration + pre-commit customization/index diff --git a/docs/pre-commit.rst b/docs/pre-commit.rst new file mode 100644 index 00000000..036c6e27 --- /dev/null +++ b/docs/pre-commit.rst @@ -0,0 +1,41 @@ +pre-commit +========== + +``towncrier`` can also be used in your `pre-commit `_ configuration (``.pre-commit-config.yaml``) +to check and/or update your news fragments on commit or during CI processes. + +No additional configuration is needed in your ``towncrier`` configuration, the hook will read from the appropriate configuration +files in your project. + + +Examples +-------- + +Usage with the default configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: yaml + + repos: + - repo: https://github.com/twisted/towncrier + - rev: 22.13.0 # run 'pre-commit autoupdate' to update + - hooks: + - id: towncrier-check + + +Usage with custom configuration and directories +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +News fragments are stored in ``changelog.d/`` in the root of the repository and we want to keep the news fragments when +running ``update``: + +.. code-block:: yaml + + repos: + - repo: https://github.com/twisted/towncrier + - rev: 22.13.0 # run 'pre-commit autoupdate' to update + - hooks: + - id: towncrier-update + files: $changelog\.d/ + args: ['--keep'] + diff --git a/src/towncrier/newsfragments/498.feature b/src/towncrier/newsfragments/498.feature new file mode 100644 index 00000000..364eda0d --- /dev/null +++ b/src/towncrier/newsfragments/498.feature @@ -0,0 +1 @@ +Added pre-commit hooks for checking and updating news in projects using pre-commit.