Skip to content

Commit

Permalink
Create prepare-commit-msg
Browse files Browse the repository at this point in the history
It is allowing you to put work items in `.related_work_items` file, line by line and it will add them to the commit message
  • Loading branch information
piotrgredowski authored Dec 1, 2023
1 parent ce22c40 commit c983969
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions git_hooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3

file=".related_work_items"

work_items_prefix="#"

# If the file exists, read it line by line and store it in an array
# if not - exit without modifying the commit message
if [ -f "$file" ]
then
related_work_items=()
while IFS= read -r line
do
related_work_items+=("$line")
done < "$file"
else
exit 0
fi

# Build the suffix string

suffix_template="
Related work items: "

work_items_suffix=$suffix_template

separator=", "

for i in "${related_work_items[@]}"
do
work_items_suffix+="$work_items_prefix$i"
if [[ $i != "${related_work_items[-1]}" ]]
then
work_items_suffix+="$separator"
fi
done

# Add the suffix to the beginning of the commit message

commit_message=$(cat $COMMIT_MSG_FILE)

echo "$work_items_suffix$commit_message" > $COMMIT_MSG_FILE

0 comments on commit c983969

Please sign in to comment.