From bf26acb831e4dcb2363a826e4a7e34f47809bf84 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 15 Mar 2024 09:27:39 +0100 Subject: [PATCH] Introduce some new pre-commit hooks --- .pre-commit-config.yaml | 93 ++++++++++++++++++++++++++--------------- .woodpecker.yml | 3 +- .yamllint.yml | 7 ++++ README.md | 11 ++--- build.sh | 2 +- check_syncthing | 2 +- 6 files changed, 77 insertions(+), 41 deletions(-) create mode 100644 .yamllint.yml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 01fc28a..9bab40d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,37 +1,64 @@ # Pre-commit hooks to run tests and ensure code is cleaned. # See https://pre-commit.com for more information +--- repos: -- repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 - hooks: - - id: pyupgrade - args: ['--keep-percent-format', '--py37-plus'] -- repo: https://github.com/psf/black - rev: 23.11.0 - hooks: - - id: black - args: ['--target-version', 'py37', '--line-length', '100'] -- repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - args: ['--profile', 'black', '--line-length', '100'] -- repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 - hooks: - - id: flake8 - args: ['--max-line-length=100'] -- repo: local - hooks: - - id: pylint - name: pylint - entry: pylint - language: system - types: [python] - require_serial: true -- repo: https://github.com/PyCQA/bandit - rev: 1.7.5 - hooks: - - id: bandit - args: [--skip, "B101", --recursive, "mylib"] + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.6 + hooks: + - id: ruff + args: ["--fix"] + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: ["--keep-percent-format", "--py37-plus"] + - repo: https://github.com/psf/black + rev: 23.11.0 + hooks: + - id: black + args: ["--target-version", "py37", "--line-length", "100"] + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + args: ["--profile", "black", "--line-length", "100"] + - repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + args: ["--max-line-length=100"] + - repo: https://github.com/codespell-project/codespell + rev: v2.2.2 + hooks: + - id: codespell + args: + - --ignore-words-list=exten + - --skip="./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf" + - --quiet-level=2 + - --ignore-regex=.*codespell-ignore$ + # - --write-changes # Uncomment to write changes + exclude_types: [csv, json] + - repo: https://github.com/adrienverge/yamllint + rev: v1.32.0 + hooks: + - id: yamllint + ignore: .github/ + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.7.1 + hooks: + - id: prettier + args: ["--print-width", "100"] + - repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + require_serial: true + - repo: https://github.com/PyCQA/bandit + rev: 1.7.5 + hooks: + - id: bandit + args: [--skip, "B101", --recursive] minimum_pre_commit_version: 3.2.0 diff --git a/.woodpecker.yml b/.woodpecker.yml index 49b1fc9..d796650 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,3 +1,4 @@ +--- clone: git: image: woodpeckerci/plugin-git @@ -18,7 +19,7 @@ pipeline: commands: - echo "$GPG_KEY"|base64 -d|gpg --import - ./build.sh --quiet - secrets: [ maintainer_name, maintainer_email, gpg_key, debian_codename ] + secrets: [maintainer_name, maintainer_email, gpg_key, debian_codename] publish-dryrun: group: publish diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..937d3d5 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,7 @@ +--- +extends: default + +rules: + line-length: + max: 100 + level: warning diff --git a/README.md b/README.md index 894e154..4c70110 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,10 @@ This Icinga/Nagios check plugin permit to check Syncthing status : ## Installation -First, generate and retreive the REST API key from Syncthing web interface: - - in Actions menu, click on Configuration - - in General tab, under API key, click on Generate button and copy the key +First, generate and retrieve the REST API key from Syncthing web interface: + +- in Actions menu, click on Configuration +- in General tab, under API key, click on Generate button and copy the key ``` API_KEY=n6RseK3HWY5LJ29PzNSUJbmK4XKHa5uV @@ -67,6 +68,6 @@ Copyright (c) 2023 Benjamin Renard This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. -This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. diff --git a/build.sh b/build.sh index 1e8befa..6cef148 100755 --- a/build.sh +++ b/build.sh @@ -24,7 +24,7 @@ sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" $BDIR/check_syncthing if [ -z "$DEBIAN_CODENAME" ] then - echo "Retreive debian codename using lsb_release..." + echo "Retrieve debian codename using lsb_release..." DEBIAN_CODENAME=$( lsb_release -c -s ) else echo "Use debian codename from environment ($DEBIAN_CODENAME)" diff --git a/check_syncthing b/check_syncthing index 68ca0d9..e840a12 100755 --- a/check_syncthing +++ b/check_syncthing @@ -78,7 +78,7 @@ def call_api(uri, method=None, data=None, headers=None, what=None): ) r.raise_for_status() except Exception: # pylint: disable=broad-exception-caught - print(f"UNKNOWN - Fail to retreive {what if what else 'data'} from Syncthing REST API") + print(f"UNKNOWN - Fail to retrieve {what if what else 'data'} from Syncthing REST API") if data: print(f"Request data: {json.dumps(data, indent=2)}") logging.exception("Error on requesting %s %s", method, uri)