Repository: Lazarus-org/dj-announcement-api (language: python)

Issue:
🔧 Missing `.pre-commit-config` for Local and CI Integration
### **Description:**

The package is missing a `.pre-commit-config.yaml` file to enforce consistent code formatting, linting, and other quality checks across both local development and CI environments. Without this configuration, developers may introduce style inconsistencies or code that doesn’t pass basic quality checks, leading to issues during CI pipelines or code reviews.

**Problems Identified:**

1. **Inconsistent Code Style**:
   - Without a pre-commit configuration, there is no automatic enforcement of code styles (e.g., using `black`, `isort`, etc.).
   - This leads to style inconsistencies across the codebase, increasing the difficulty of code reviews and collaboration.

2. **Lack of Pre-commit Hooks**:
   - Important checks such as linting (via `flake8`), security scanning, and fixing common issues (via `prettier`, etc.) are not enforced before each commit, allowing errors and potential vulnerabilities to slip through.
   
3. **No Integration with CI**:
   - The absence of pre-commit hooks in the CI pipeline allows non-compliant code to be merged, leading to build failures or technical debt over time.
   
4. **Manual Process**:
   - Developers have to manually run linters and formatters, which can lead to human errors or oversight.



Discussion / hints:

Fix patch:
diff --git a/.pre-commit-config-ci.yaml b/.pre-commit-config-ci.yaml
new file mode 100644
index 0000000..569f230
--- /dev/null
+++ b/.pre-commit-config-ci.yaml
@@ -0,0 +1,84 @@
+repos:
+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v5.0.0
+    hooks:
+      - id: check-toml
+      - id: check-yaml
+        files: \.yaml$
+      - id: trailing-whitespace
+        exclude: (migrations/|tests/|docs/).*
+      - id: end-of-file-fixer
+        exclude: (migrations/|tests/|docs/).*
+      - id: check-added-large-files
+        exclude: (migrations/|tests/|docs/).*
+      - id: check-case-conflict
+        exclude: (migrations/|tests/|docs/).*
+      - id: check-merge-conflict
+        exclude: (migrations/|tests/|docs/).*
+      - id: check-docstring-first
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/tox-dev/pyproject-fmt
+    rev: 2.4.3
+    hooks:
+      - id: pyproject-fmt
+
+  - repo: https://github.com/tox-dev/tox-ini-fmt
+    rev: 1.4.1
+    hooks:
+      - id: tox-ini-fmt
+
+  - repo: https://github.com/asottile/pyupgrade
+    rev: v3.19.0
+    hooks:
+      - id: pyupgrade
+
+  - repo: https://github.com/pre-commit/mirrors-isort
+    rev: v5.10.1
+    hooks:
+      - id: isort
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/psf/black
+    rev: 24.10.0
+    hooks:
+      - id: black
+        args: [ "--config=pyproject.toml" ]
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/commitizen-tools/commitizen
+    rev: v3.30.0
+    hooks:
+      - id: commitizen
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/PyCQA/bandit
+    rev: 1.7.10
+    hooks:
+      - id: bandit
+        args: [ "-c", "pyproject.toml", "-r", "." ]
+        additional_dependencies: [ "bandit[toml]" ]
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/PyCQA/docformatter
+    rev: v1.7.5
+    hooks:
+      - id: docformatter
+        args: [ "--in-place", "--recursive", "--blank" ]
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/adamchainz/blacken-docs
+    rev: 1.19.1
+    hooks:
+      - id: blacken-docs
+        additional_dependencies:
+          - black==24.4.2
+        files: '\.rst$'
+
+  - repo: https://github.com/rstcheck/rstcheck
+    rev: "v6.2.4"
+    hooks:
+      - id: rstcheck
+        args: [ "--report-level=warning" ]
+        files: ^(docs/(.*/)*.*\.rst)
+        additional_dependencies: [ Sphinx==6.2.1 ]
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..58fe318
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,115 @@
+repos:
+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v5.0.0
+    hooks:
+      - id: check-toml
+      - id: check-yaml
+        files: \.yaml$
+      - id: trailing-whitespace
+        exclude: (migrations/|tests/|docs/).*
+      - id: end-of-file-fixer
+        exclude: (migrations/|tests/|docs/).*
+      - id: check-added-large-files
+        exclude: (migrations/|tests/|docs/).*
+      - id: check-case-conflict
+        exclude: (migrations/|tests/|docs/).*
+      - id: check-merge-conflict
+        exclude: (migrations/|tests/|docs/).*
+      - id: check-docstring-first
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/tox-dev/pyproject-fmt
+    rev: 2.4.3
+    hooks:
+      - id: pyproject-fmt
+
+  - repo: https://github.com/tox-dev/tox-ini-fmt
+    rev: 1.4.1
+    hooks:
+      - id: tox-ini-fmt
+
+  - repo: https://github.com/asottile/pyupgrade
+    rev: v3.19.0
+    hooks:
+      - id: pyupgrade
+
+  - repo: https://github.com/pre-commit/mirrors-isort
+    rev: v5.10.1
+    hooks:
+      - id: isort
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/psf/black
+    rev: 24.10.0
+    hooks:
+      - id: black
+        args: [ "--config=pyproject.toml" ]
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/commitizen-tools/commitizen
+    rev: v3.30.0
+    hooks:
+      - id: commitizen
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/PyCQA/bandit
+    rev: 1.7.10
+    hooks:
+      - id: bandit
+        args: [ "-c", "pyproject.toml", "-r", "." ]
+        additional_dependencies: [ "bandit[toml]" ]
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/PyCQA/docformatter
+    rev: v1.7.5
+    hooks:
+      - id: docformatter
+        args: [ "--in-place", "--recursive", "--blank" ]
+        exclude: (migrations/|tests/|docs/).*
+
+  - repo: https://github.com/adamchainz/blacken-docs
+    rev: 1.19.1
+    hooks:
+      - id: blacken-docs
+        additional_dependencies:
+          - black==24.4.2
+        files: '\.rst$'
+
+  - repo: https://github.com/rstcheck/rstcheck
+    rev: "v6.2.4"
+    hooks:
+      - id: rstcheck
+        args: [ "--report-level=warning" ]
+        files: ^(docs/(.*/)*.*\.rst)
+        additional_dependencies: [ Sphinx==6.2.1 ]
+
+  - repo: local
+    hooks:
+      - id: pytest
+        name: Pytest
+        entry: poetry run pytest -v
+        language: system
+        types: [ python ]
+        stages: [ pre-commit ]
+        pass_filenames: false
+        always_run: true
+
+      - id: pylint
+        name: pylint
+        entry: pylint
+        language: system
+        types: [ python ]
+        require_serial: true
+        args:
+          - "-rn"
+          - "-sn"
+          - "--rcfile=pyproject.toml"
+        files: ^django_notification/
+        exclude: (migrations/|tests/|docs/).*
+
+      - id: pre-commit-django-migration-lint
+        name: Lint Django migrations
+        entry: ./manage.py lintmigrations
+        language: system
+        types: [python]
+        pass_filenames: false


Test patch:
diff --git a/django_announcement/tests/conftest.py b/django_announcement/tests/conftest.py
index 1d24d24..f2c2908 100644
--- a/django_announcement/tests/conftest.py
+++ b/django_announcement/tests/conftest.py
@@ -1,3 +1,4 @@
+from django_announcement.tests import setup
 from django_announcement.tests.fixtures import (
     admin_user,
     announce_profile_admin,
@@ -11,4 +12,3 @@
     user,
     user_announcement_profile,
 )
-from django_announcement.tests.setup import configure_django_settings
diff --git a/django_announcement/tests/setup.py b/django_announcement/tests/setup.py
index 3f415c3..4323f01 100644
--- a/django_announcement/tests/setup.py
+++ b/django_announcement/tests/setup.py
@@ -68,6 +68,7 @@ def configure_django_settings() -> None:
                 "django.contrib.staticfiles",
                 "rest_framework",
                 "django_filters",
+                "django_migration_linter",
                 "django_announcement",
             ],
             MIDDLEWARE=[