Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pre-commit hooks (#498) #499

Merged
merged 6 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Reference

cli
configuration
pre-commit
customization/index


Expand Down
37 changes: 37 additions & 0 deletions docs/pre-commit.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pre-commit
==========

``towncrier`` can also be used in your `pre-commit <https://pre-commit.com/>`_ 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']
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/498.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added pre-commit hooks for checking and updating news in projects using pre-commit.