|
| 1 | +#!/bin/bash -e |
| 2 | +# |
| 3 | +# Copyright (C) 2020 HERE Europe B.V. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +# SPDX-License-Identifier: Apache-2.0 |
| 18 | +# License-Filename: LICENSE |
| 19 | +# |
| 20 | + |
| 21 | +# This is script for verifying commit message by SDK requirements. |
| 22 | +# Best git and linux practices are included. |
| 23 | +# Requirements can be find in scripts/misc/commit_message_recom.txt |
| 24 | + |
| 25 | +# Saving whole commit message into file for reading below |
| 26 | +echo "`git log --pretty=format:'%B' -2 | sed '1d' | sed '1d' `" >> commit.log |
| 27 | + |
| 28 | +# Counting number of lines in file |
| 29 | +num_lines=`wc -l commit.log| cut -d'c' -f1` |
| 30 | + |
| 31 | +# Loop for every line in file |
| 32 | +for (( line=1; line<=${num_lines}; line++ )) |
| 33 | +do |
| 34 | + current_line_len=`cat commit.log| sed -n ${line}p |wc -m | sed 's/\ \ \ \ \ \ /''/g' ` |
| 35 | + if [ $line -eq 1 ] && [ ${current_line_len} -gt 50 ] ; then |
| 36 | + echo "ERROR: Title is ${current_line_len} length, so it's too long for title. It must be less than 50 chars " |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + if [ $line -eq 2 ] && [ ${current_line_len} -ne 1 ] ; then |
| 40 | + echo "ERROR: Second line in Commit Message is not zero length" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + if [ $line -eq 3 ] && [ ${current_line_len} -lt 1 ] && [ -n $(cat commit.log| sed -n ${line}p | grep 'See also: ') ] && [ -n $(cat commit.log| sed -n ${line}p | grep 'Relates-To: ') ] && [ -n $(echo ${current_line_len}| grep 'Resolves: ') ] ; then |
| 44 | + echo "ERROR: No details added to commit message besides title starting from 3rd line." |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + if [ ${current_line_len} -gt 72 ] ; then |
| 48 | + echo "ERROR: ${current_line_len} chars in ${line}-th line is too long. This line must be less than 80 chars" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + echo " ${line}-th line is ${current_line_len} chars length" |
| 52 | +done |
| 53 | + |
| 54 | +relates_to=$(cat commit.log | grep 'Relates-To: ') || true |
| 55 | +resolves=$(cat commit.log | grep 'Resolves: ') || true |
| 56 | +see=$(cat commit.log | grep 'See also: ') || true |
| 57 | + |
| 58 | +echo "Reference like: ${relates_to} ${resolves} ${see} was found in commit message." |
| 59 | + |
| 60 | +if [[ -n ${relates_to} || -n ${resolves} || -n ${see} ]] ; then |
| 61 | + echo "Commit message contains Jira link." |
| 62 | +else |
| 63 | + echo "ERROR: Commit message does not contain ticket reference like Relates-To: or Resolves: or See also: " |
| 64 | + echo "Please read following rules:" |
| 65 | + cat scripts/misc/commit_message_recom.txt |
| 66 | + exit 1 |
| 67 | +fi |
0 commit comments