-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cb 6263 lefthook #3291
base: devel
Are you sure you want to change the base?
Cb 6263 lefthook #3291
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Script is a pre-commit hook to check if the staged files | ||
# has the license header from the file license-header.txt | ||
|
||
set -eo pipefail | ||
|
||
LICENSE_HEADER=${LICENSE_HEADER:-""} | ||
INCLUDE_FILES_EXT="\.(ts|tsx)$" | ||
STAGED_FILES=$(git diff --name-only --diff-filter=d --staged) | ||
|
||
# read .license-checker.txt file if exists in the root directory | ||
if [[ -f .license-checker.txt && -z "$LICENSE_HEADER" ]]; then | ||
# read the file and set the LICENSE_HEADER variable | ||
LICENSE_HEADER=$(cat .license-checker.txt) | ||
fi | ||
|
||
|
||
# error message function printing in red color | ||
# usage: error "message" | ||
error() { | ||
local message=${1:-""} | ||
echo -e "\033[0;31m${message}\033[0m" | ||
} | ||
|
||
# if the LICENSE_HEADER is empty, then exit | ||
if [ -z "$LICENSE_HEADER" ]; then | ||
error "The LICENSE_HEADER environment variable is empty." | ||
error "Either create .license-checker.txt file in the root directory or set the LICENSE_HEADER environment variable." | ||
exit 1 | ||
fi | ||
|
||
LICENSE_HEADER=$(echo "$LICENSE_HEADER" | tr -d '\r' | sed 's/[[:space:]]*$//') | ||
LICENSE_LINES=$(echo "$LICENSE_HEADER" | wc -l) | ||
|
||
errorCount=0 | ||
# Check if the staged files contains the license header. | ||
for file in $STAGED_FILES; do | ||
# filter out files that ends with the included file extensions | ||
# which described in the INCLUDE_FILES_EXT | ||
if [[ ! $file =~ $INCLUDE_FILES_EXT ]] || [[ $file == *locales/* ]]; then | ||
continue | ||
fi | ||
|
||
# check if the file contains the license header at the top of the file | ||
# from the variable of LICENSE_HEADER | ||
|
||
FILE_HEADER=$(head -n "$LICENSE_LINES" "$file" | tr -d '\r' | sed 's/[[:space:]]*$//') | ||
|
||
if [[ "$FILE_HEADER" != "$LICENSE_HEADER" ]]; then | ||
error "The file $file does not contain the license header or the license header is not correct." | ||
errorCount=$((errorCount + 1)) | ||
fi | ||
done | ||
|
||
if [ $errorCount -gt 0 ]; then | ||
error "\nPlease add the license header to the file(s) above" | ||
exit 1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2025 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pre-commit: | ||
parallel: true | ||
scripts: | ||
"license-checker.sh": | ||
runner: bash |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/sh | ||
|
||
if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we still have the |
||
set -x | ||
fi | ||
|
||
if [ "$LEFTHOOK" = "0" ]; then | ||
exit 0 | ||
fi | ||
|
||
call_lefthook() | ||
{ | ||
if test -n "$LEFTHOOK_BIN" | ||
then | ||
"$LEFTHOOK_BIN" "$@" | ||
elif lefthook -h >/dev/null 2>&1 | ||
then | ||
lefthook "$@" | ||
else | ||
dir="$(git rev-parse --show-toplevel)" | ||
osArch=$(uname | tr '[:upper:]' '[:lower:]') | ||
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/') | ||
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" | ||
then | ||
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@" | ||
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook" | ||
then | ||
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook" "$@" | ||
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" | ||
then | ||
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@" | ||
elif test -f "$dir/node_modules/lefthook/bin/index.js" | ||
then | ||
"$dir/node_modules/lefthook/bin/index.js" "$@" | ||
|
||
elif bundle exec lefthook -h >/dev/null 2>&1 | ||
then | ||
bundle exec lefthook "$@" | ||
elif yarn lefthook -h >/dev/null 2>&1 | ||
then | ||
yarn lefthook "$@" | ||
elif pnpm lefthook -h >/dev/null 2>&1 | ||
then | ||
pnpm lefthook "$@" | ||
elif swift package plugin lefthook >/dev/null 2>&1 | ||
then | ||
swift package --disable-sandbox plugin lefthook "$@" | ||
elif command -v mint >/dev/null 2>&1 | ||
then | ||
mint run csjones/lefthook-plugin "$@" | ||
else | ||
echo "Can't find lefthook in PATH" | ||
fi | ||
fi | ||
} | ||
|
||
call_lefthook run "pre-commit" "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/sh | ||
|
||
if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then | ||
set -x | ||
fi | ||
|
||
if [ "$LEFTHOOK" = "0" ]; then | ||
exit 0 | ||
fi | ||
|
||
call_lefthook() | ||
{ | ||
if test -n "$LEFTHOOK_BIN" | ||
then | ||
"$LEFTHOOK_BIN" "$@" | ||
elif lefthook -h >/dev/null 2>&1 | ||
then | ||
lefthook "$@" | ||
else | ||
dir="$(git rev-parse --show-toplevel)" | ||
osArch=$(uname | tr '[:upper:]' '[:lower:]') | ||
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/') | ||
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" | ||
then | ||
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@" | ||
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook" | ||
then | ||
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook" "$@" | ||
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" | ||
then | ||
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@" | ||
elif test -f "$dir/node_modules/lefthook/bin/index.js" | ||
then | ||
"$dir/node_modules/lefthook/bin/index.js" "$@" | ||
|
||
elif bundle exec lefthook -h >/dev/null 2>&1 | ||
then | ||
bundle exec lefthook "$@" | ||
elif yarn lefthook -h >/dev/null 2>&1 | ||
then | ||
yarn lefthook "$@" | ||
elif pnpm lefthook -h >/dev/null 2>&1 | ||
then | ||
pnpm lefthook "$@" | ||
elif swift package plugin lefthook >/dev/null 2>&1 | ||
then | ||
swift package --disable-sandbox plugin lefthook "$@" | ||
elif command -v mint >/dev/null 2>&1 | ||
then | ||
mint run csjones/lefthook-plugin "$@" | ||
else | ||
echo "Can't find lefthook in PATH" | ||
fi | ||
fi | ||
} | ||
|
||
call_lefthook run "prepare-commit-msg" "$@" |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,7 @@ | |
"lint": "eslint", | ||
"validate-dependencies": "core-cli-validate-dependencies './packages/*/'", | ||
"add-plugin": "core-cli-add-plugin", | ||
"prepare": "cd .. && husky ./webapp/.husky", | ||
"version:set": "yarn workspaces foreach -Ap --include '@cloudbeaver/product-*' run version:set", | ||
"postinstall": "husky" | ||
"version:set": "yarn workspaces foreach -Ap --include '@cloudbeaver/product-*' run version:set" | ||
}, | ||
"devDependencies": { | ||
"@cloudbeaver/core-cli": "workspace:*", | ||
|
@@ -37,7 +35,7 @@ | |
"@types/react-dom": "^19", | ||
"concurrently": "^9", | ||
"eslint": "^9.20.1", | ||
"husky": "^9", | ||
"lefthook": "^1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it didnt workout for me to have githooks after all |
||
"mobx": "^6", | ||
"mobx-react-lite": "^4", | ||
"msw": "^2", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets have license 1 entry point for vscode snippet and license checking via git hooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, it will be strange to support both of them