From 947b3f33abadfd3171ec42252ff018c2ebd69e22 Mon Sep 17 00:00:00 2001 From: Anton Agestam Date: Wed, 22 Mar 2023 10:17:28 +0100 Subject: [PATCH] fix: Use regular grep for copyright check --- .pre-commit-config.yaml | 6 ++---- copyright.sh | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100755 copyright.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c7c9ee9a..8894178d1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,10 +17,8 @@ repos: name: copyright language: system types: [ python ] - pass_filenames: false - # Lists the Python files that do not have an Aiven copyright. Exits with a - # non-zero exit code if any are found. - entry: bash -c "! git grep -ELm1 'Copyright \(c\) 20[0-9]{2} Aiven' -- '*.py' ':!*__init__.py'" + exclude: __init__\.py + entry: ./copyright.sh - repo: https://github.com/shellcheck-py/shellcheck-py rev: v0.9.0.2 diff --git a/copyright.sh b/copyright.sh new file mode 100755 index 000000000..fee10b22d --- /dev/null +++ b/copyright.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +missing_copyright=$( + grep \ + --extended-regexp \ + --files-without-match \ + --max-count=1 \ + 'Copyright \(c\) 20[0-9]{2} Aiven' \ + -- "$@" +) + +if [[ -n $missing_copyright ]]; then + echo "💥 There are files missing required copyright statement." + echo "$missing_copyright" + exit 1 +else + echo "✅ All files have required copyright statement." +fi