Merge pull request #719 from MikeWallaceDev/feat_replace_commit_lint_with_gitlint

Feat replace commit lint with gitlint
This commit is contained in:
Nathan.fooo 2022-07-26 11:00:16 +08:00 committed by GitHub
commit 6b363fab52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 88 additions and 64 deletions

View File

@ -6,7 +6,24 @@
# status after issuing an appropriate message if it wants to stop the
# commit. The hook is allowed to edit the commit message file.
echo "Running the AppFlowy commit-msg hook."
YELLOW="\e[93m"
GREEN="\e[32m"
RED="\e[31m"
ENDCOLOR="\e[0m"
printMessage() {
printf "${YELLOW}AppFlowy : $1${ENDCOLOR}\n"
}
printSuccess() {
printf "${GREEN}AppFlowy : $1${ENDCOLOR}\n"
}
printError() {
printf "${RED}AppFlowy : $1${ENDCOLOR}\n"
}
printMessage "Running the AppFlowy commit-msg hook."
# This example catches duplicate Signed-off-by lines.
@ -16,11 +33,19 @@ test "" = "$(grep '^Signed-off-by: ' "$1" |
exit 1
}
npx --no -- commitlint --edit $1
.githooks/gitlint \
--msg-file=$1 \
--subject-regex="^(build|chore|ci|docs|feat|feature|fix|perf|refactor|revert|style|test)(.*)?:\s?.*" \
--subject-maxlen=100 \
--subject-minlen=10 \
--body-regex=".*" \
--body-maxlen=200 \
--max-parents=1
if [ $? -ne 0 ]
then
echo "Please fix your commit message to match AppFlowy coding standards"
printError "Please fix your commit message to match AppFlowy coding standards"
printError "https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/software-contributions/submitting-code/style-guides"
exit 1
fi

View File

@ -1,6 +1,23 @@
#!/usr/bin/env bash
echo "Running local AppFlowy pre-commit hook."
YELLOW="\e[93m"
GREEN="\e[32m"
RED="\e[31m"
ENDCOLOR="\e[0m"
printMessage() {
printf "${YELLOW}AppFlowy : $1${ENDCOLOR}\n"
}
printSuccess() {
printf "${GREEN}AppFlowy : $1${ENDCOLOR}\n"
}
printError() {
printf "${RED}AppFlowy : $1${ENDCOLOR}\n"
}
printMessage "Running local AppFlowy pre-commit hook."
#flutter format .
##https://gist.github.com/benmccallum/28e4f216d9d72f5965133e6c43aaff6e

View File

@ -1,23 +1,41 @@
#!/usr/bin/env bash
echo "Running local AppFlowy pre-push hook."
YELLOW="\e[93m"
GREEN="\e[32m"
RED="\e[31m"
ENDCOLOR="\e[0m"
printMessage() {
printf "${YELLOW}AppFlowy : $1${ENDCOLOR}\n"
}
printSuccess() {
printf "${GREEN}AppFlowy : $1${ENDCOLOR}\n"
}
printError() {
printf "${RED}AppFlowy : $1${ENDCOLOR}\n"
}
printMessage "Running local AppFlowy pre-push hook."
if [[ `git status --porcelain` ]]; then
printf "\e[31;1m%s\e[0m\n" 'This script needs to run against committed code only. Please commit or stash you changes.'
printError "This script needs to run against committed code only. Please commit or stash you changes."
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Running the Flutter analyzer'
printMessage "Running the Flutter analyzer"
flutter analyze
if [ $? -ne 0 ]; then
printf "\e[31;1m%s\e[0m\n" 'Flutter analyzer error'
printError "Flutter analyzer error"
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running the Flutter analyzer'
printf "\e[33;1m%s\e[0m\n" 'Running unit tests'
printMessage "Finished running the Flutter analyzer"
#printMessage "Running unit tests"
#flutter test
#if [ $? -ne 0 ]; then
# printf "\e[31;1m%s\e[0m\n" 'Unit tests error'

3
.gitignore vendored
View File

@ -32,3 +32,6 @@ frontend/.vscode/*
# Commit the highest level pubspec.lock, but ignore the others
pubspec.lock
!frontend/app_flowy/pubspec.lock
# ignore tool used for commit linting
.githooks/gitlint

View File

@ -22,3 +22,4 @@ module.exports = {
'footer-max-line-length': [2, 'always', 100]
},
};

View File

@ -8,7 +8,6 @@ extend = [
{ path = "scripts/makefile/env.toml" },
{ path = "scripts/makefile/flutter.toml" },
{ path = "scripts/makefile/tool.toml" },
{ path = "scripts/makefile/githooks.toml" },
]
[config]

View File

@ -50,6 +50,13 @@ flutter doctor
printMessage "Setting up githooks."
git config core.hooksPath .githooks
# Install go-gitlint
printMessage "Installing go-gitlint."
GOLINT_FILENAME="go-gitlint_1.1.0_linux_x86_64.tar.gz"
wget https://github.com/llorllale/go-gitlint/releases/download/1.1.0/${GOLINT_FILENAME}
tar -zxv --directory .githooks/. -f ${GOLINT_FILENAME} gitlint
rm ${GOLINT_FILENAME}
# Change to the frontend directory
cd frontend
@ -61,10 +68,6 @@ cargo install --force cargo-make
printMessage "Installing duckscript."
cargo install --force duckscript_cli
# Install CommitLint
printMessage "Installing CommitLint."
npm install @commitlint/cli @commitlint/config-conventional --save-dev
# Check prerequisites
printMessage "Checking prerequisites."
cargo make flowy_dev

View File

@ -50,6 +50,13 @@ flutter doctor
printMessage "Setting up githooks."
git config core.hooksPath .githooks
# Install go-gitlint
printMessage "Installing go-gitlint."
GOLINT_FILENAME="go-gitlint_1.1.0_osx_x86_64.tar.gz"
wget https://github.com/llorllale/go-gitlint/releases/download/1.1.0/${GOLINT_FILENAME}
tar -zxv --directory .githooks/. -f ${GOLINT_FILENAME} gitlint
rm ${GOLINT_FILENAME}
# Change to the frontend directory
cd frontend
@ -61,10 +68,6 @@ cargo install --force cargo-make
printMessage "Installing duckscript."
cargo install --force duckscript_cli
# Install CommitLint
printMessagae "Installing CommitLint."
npm install @commitlint/cli @commitlint/config-conventional --save-dev
# Check prerequisites
printMessage "Checking prerequisites."
cargo make flowy_dev

View File

@ -1,39 +0,0 @@
[tasks.install-commitlint.mac]
script = [
"""
brew install npm
npm install @commitlint/cli @commitlint/config-conventional --save-dev
git config core.hooksPath .githooks
""",
]
script_runner = "@shell"
[tasks.install-commitlint.windows]
script = [
"""
echo "WIP"
git config core.hooksPath .githooks
""",
]
script_runner = "@duckscript"
[tasks.install-commitlint.linux]
script = [
"""
if command -v apt &> /dev/null
then
echo "Installing node.js (sudo apt install nodejs)"
sudo apt install nodejs
else
echo "Installing node.js (sudo pacman -S nodejs)"
sudo pacman -S nodejs
fi
npm install @commitlint/cli @commitlint/config-conventional --save-dev
git config core.hooksPath .githooks
""",
]
script_runner = "@shell"

View File

@ -1,6 +0,0 @@
{
"devDependencies": {
"@commitlint/cli": "^16.1.0",
"@commitlint/config-conventional": "^16.0.0"
}
}