Skip to content

Commit

Permalink
feat: initial version of the pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Sep 23, 2019
1 parent e6ac308 commit 7d328c0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Empty file removed githooks/.gitkeep
Empty file.
48 changes: 48 additions & 0 deletions githooks/pre-commit
@@ -0,0 +1,48 @@
#!/bin/bash

STAGED_GO_FILES=$(git diff --cached --name-only | grep "\.go$")

if [[ "$STAGED_GO_FILES" = "" ]]; then
exit 0
fi

GOLINT=$GOPATH/bin/golint
GOIMPORTS=$GOPATH/bin/goimports

# Check for golint
if [[ ! -x "$GOLINT" ]]; then
printf "\t\033[41mPlease install golint\033[0m (go get -u golang.org/x/lint/golint)"
exit 1
fi

# Check for goimports
if [[ ! -x "$GOIMPORTS" ]]; then
printf "\t\033[41mPlease install goimports\033[0m (go get golang.org/x/tools/cmd/goimports)"
exit 1
fi

PASS=true

for FILE in $STAGED_GO_FILES
do
# Run goimports on the staged file
$GOIMPORTS -w $FILE

# Run golint on the staged file and check the exit status
$GOLINT "-set_exit_status" $FILE
if [[ $? == 1 ]]; then
printf "\t\033[31mgolint $FILE\033[0m \033[0;30m\033[41mFAILURE!\033[0m\n"
PASS=false
else
printf "\t\033[32mgolint $FILE\033[0m \033[0;30m\033[42mpass\033[0m\n"
fi
done

if ! $PASS; then
printf "\033[0;30m\033[41mCOMMIT FAILED\033[0m\n"
exit 1
else
printf "\033[0;30m\033[42mCOMMIT SUCCEEDED\033[0m\n"
fi

exit 0
3 changes: 3 additions & 0 deletions go/internal/banner/banner.go
Expand Up @@ -27,10 +27,12 @@ const banner = `
/__/ /___/
`

// Banner returns the ascii-art representation of the Berty bird
func Banner() string {
return banner
}

// Say returns an ascii-art representation of the Berty bird saying something
func Say(message string) string {
ml := strings.Split(wordwrap(message, stopColumn-startColumn), "\n")
// append empty line at the top for short quotes
Expand Down Expand Up @@ -71,6 +73,7 @@ func Say(message string) string {
return strings.Join(output, "\n") + "\n"
}

// OfTheDay returns the ascii-art representation of the Berty bird saying the quote of the day
func OfTheDay() string {
q := QOTD()
return Say(q.String())
Expand Down

0 comments on commit 7d328c0

Please sign in to comment.