Skip to content

Commit d22e85b

Browse files
authored
Add commit message checker on PSV (#721)
Add script to separate Azure job which verify correctness of agreed commit message. Title is less than 50 chars. Next to title must be clear line. After that all lines length is less than 72 chars. At the end should be Jira reference. Resolves: OLPEDGE-1573 Signed-off-by: Yaroslav Stefinko <[email protected]>
1 parent cee5476 commit d22e85b

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

azure-pipelines.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ variables:
1313
BUILD_TYPE: "RelWithDebInfo"
1414

1515
jobs:
16+
- job: Commit_checker
17+
pool:
18+
vmImage: 'ubuntu-18.04'
19+
steps:
20+
- bash: scripts/misc/commit_checker.sh
21+
displayName: 'Commit checker script'
1622
- job: Windows_build
1723
pool:
1824
vmImage: 'vs2017-win2016'

scripts/misc/commit_checker.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#################################################
2+
#################################################
3+
Summarize changes in around 50 characters or less.
4+
5+
More detailed explanatory text. Wrap it to about 72
6+
characters or so. In some contexts, the first line is treated as the
7+
subject of the commit and the rest of the text as the body. The
8+
blank line separating the summary from the body is critical (unless
9+
you omit the body entirely); various tools like `log`, `shortlog`
10+
and `rebase` can get confused if you run the two together.
11+
12+
Explain the problem that this commit is solving. Focus on why you
13+
are making this change as opposed to how (the code explains that).
14+
Are there side effects or other unintuitive consequences of this
15+
change? Here's the place to explain them.
16+
17+
Further paragraphs come after blank lines.
18+
19+
- Bullet points are okay, too.
20+
21+
- Typically a hyphen or asterisk is used for the bullet, preceded
22+
by a single space, with blank lines in between, but conventions
23+
vary here.
24+
25+
All commits need to reference a ticket, again separated by a blank
26+
line from the commit message summary above:
27+
28+
Resolves: ABC-111, #123
29+
Relates-To: ABC-333, #321
30+
See also: ABC-432, #456, #789
31+
32+
Signed-off-by: FirstName LastName <[email protected]>
33+
#################################################
34+
#################################################

0 commit comments

Comments
 (0)