Last active
March 13, 2023 07:44
-
-
Save RomiC/03c3502189a6adf9d4f68755fc7ea2e8 to your computer and use it in GitHub Desktop.
An example of commit-hoot to check spell of the commit message via LanguageTool service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script check the spell of your commit message saving | |
# using LanguageTool service (https://languagetool.org/). | |
# | |
# To use it, you register an account in LanguageTool service, | |
# than go to "Settings -> Account -> Access Tokens" and click | |
# "Create Integration Key". Copy your email and key and paste | |
# them into this scrip into the corrsponsing variables (LT_EMAIL, | |
# LT_API_KEY). | |
# | |
# Copy this script into .git/hooks folder inside your repo. | |
# On the next commit, script will check the spell of its message | |
# and if it contains any errors will display them like this: | |
# | |
# SPELL CHECK FAILED: | |
# | |
# 1. A sample a good mesage | |
# > Missing comma: sample, | |
# 2. A sample a good mesage | |
# > Missing preposition: of a | |
# 3. A sample a good mesage | |
# > Spelling mistake: message, menage, me sage, mes age, ménage | |
# | |
# The message contains list of errors. Each error starts with | |
# a context (part of the string contains the error). The error message | |
# on the next line with a list of possible fixes after a colon. | |
LT_EMAIL='<your-email-goes-here>' | |
LT_API_KEY='<provide-your-api-key>' | |
SPELL_CHECK_RESULT=$(cat $1 | xargs -I {} curl -s -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'language=en-US&enabledOnly=false' --data-urlencode "username=$LT_EMAIL" --data-urlencode "apiKey=$LT_API_KEY" --data-urlencode text="{}" 'https://api.languagetoolplus.com/v2/check' | jq -r '.matches | keys[] as $k | "\($k + 1). \(.[$k] | .context.text)\n > \(.[$k] | .shortMessage): \(.[$k] | .replacements | map(.value) | join(", "))"') | |
if [[ -n $SPELL_CHECK_RESULT ]]; then | |
echo -e >&2 "SPELL CHECK FAILED:\n\n$SPELL_CHECK_RESULT" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment