#!/usr/bin/env bash

# Copyright Elasticsearch B.V. and contributors
# SPDX-License-Identifier: Apache-2.0

the_exit=0

check_file() {
  if grep -q "Copyright Elasticsearch B.V. and contributors" "$1" && \
     grep -q "SPDX-License-Identifier: Apache-2.0" "$1"; then
    echo "Correct: $1"
  else
    echo "Incorrect: $1"
    the_exit=1
  fi
}

echo "SPDX license header check"
for file in $(git ls-files | grep -E '\.(ts|js|mjs)$'); do
  check_file "$file"
done

exit "$the_exit"
