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