github.com/greenboxal/deis@v1.12.1/contrib/util/commit-msg (about)

     1  #!/usr/bin/env bash
     2  #
     3  # This hook verifies that the commit message follows deis commit style
     4  # To install this hook run the following command from the deis git root
     5  # cp contrib/util/commit-msg .git/hooks/commit-msg
     6  set -eo pipefail
     7  
     8  RED=$(tput setaf 1)
     9  YELLOW=$(tput setaf 3)
    10  NORMAL=$(tput sgr0)
    11  subject_regex="^(feat|fix|docs|style|ref|test|chore)\(.+\): [\w\s\d]*"
    12  capital_regex="^.+\): [a-z][\w\s\d]*"
    13  
    14  MESSAGE[1]="file"
    15  
    16  i=1 # the first array variable is at index 1
    17  while read line
    18  do
    19  	MESSAGE[$i]=$line
    20  	let i++
    21  done < "$1"
    22  
    23  SUBJECT=${MESSAGE[1]}
    24  
    25  if ! [[ $SUBJECT =~ $subject_regex ]]; then
    26  	echo "${RED}ERROR - Invalid subject line."
    27  	echo ""
    28  	echo "$SUBJECT"
    29  	echo ""
    30  	echo "It must be in the format: {type}({scope}): {subject}"
    31  	echo ""
    32  	echo "The following {type}s are allowed:"
    33  	echo "feat"
    34  	echo "fix"
    35  	echo "docs"
    36  	echo "style"
    37  	echo "ref"
    38  	echo "test"
    39  	echo "chore"
    40  	echo ""
    41  	echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
    42  	exit 0
    43  fi
    44  
    45  if ! [[ $SUBJECT =~ $capital_regex ]]; then
    46  	echo "${RED}ERROR - Don't the capitalize commit message."
    47  	echo ""
    48  	echo "$SUBJECT"
    49  	echo ""
    50  	echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
    51  	exit 0
    52  fi
    53  
    54  if [[ ${#SUBJECT} -gt 50 ]]; then
    55  	echo "${YELLOW}WARNING - Subject shouldn't be longer than 50 characters."
    56  	echo ""
    57  	echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
    58  	exit 0
    59  fi
    60  
    61  if [[ ${#MESSAGE[2]} -gt 0 ]]; then
    62  	echo "${RED}ERROR - Second line must be blank"
    63  	echo ""
    64  	echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
    65  	exit 0
    66  fi
    67  
    68  cnt=${#MESSAGE[@]}
    69  for (( i = 3 ; i <= cnt ; i++ ))
    70  do
    71  		if [[ ${#MESSAGE[$i]} -gt 72 ]] && [[ ${MESSAGE[$i]:0:1} != '#' ]]; then
    72  			echo "${RED}ERROR on line $i -  can't be longer than 72 characters."
    73  			echo ""
    74  			echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
    75  			exit 0
    76  		fi
    77  done
    78  
    79  echo "Your commit message follows the deis commit style."
    80  
    81  exit 0