set -e
add_jira_issue_id_prefix() {
jira_issue_id=$(git branch --show-current | grep -o -E "^[a-zA-Z]+-[0-9]+" | tr '[:lower:]' '[:upper:]');
commit_msg_file_text=$(cat "$1");
commit_msg=$(echo "$commit_msg_file_text" | grep -v "^\s*#" || "true");
if [ -n "$jira_issue_id" ] && echo "$commit_msg" | grep -q -i -v "^\[\?$jira_issue_id\]\?"; then
printf "[%s] %s" "$jira_issue_id" "$commit_msg_file_text" > "$1"
fi
}
add_co_authored_by_trailers() {
co_authored_by_trailers=$(git mob --list | sed "s/^/Co-authored-by: /");
trailer_args=""
OLDIFS="$IFS"
IFS='
'
for line in $co_authored_by_trailers; do
trailer_args="${trailer_args} --trailer \"$line\""
done
IFS="$OLDIFS"
if [ -n "$trailer_args" ]; then
eval "git interpret-trailers --if-exists addIfDifferent ${trailer_args} --in-place $1"
printf "\n%s\n\n" "$co_authored_by_trailers"
fi
}
main() {
if [ "$(git branch --show-current)" = "" ]; then
exit 0
fi
if [ "$2" = 'commit' ]; then
exit 0
fi
add_jira_issue_id_prefix "$@"
add_co_authored_by_trailers "$@"
}
main "$@"