Skip to content

Commit

Permalink
iox-#2 Port 'prepart-commit-msg' git-hook from iceoryx to iceory-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Aug 23, 2023
1 parent 680efa4 commit fba60c9
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tools/git-hooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#! /bin/bash

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: © 2021 - 2022 by Apex.AI Inc. All rights reserved.
# SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project
# SPDX-FileContributor: Mathias Kraus

# This script adds the issue number of the branch name to the commit message if it is available

set -eu

COLOR_RESET='\033[0m'
COLOR_RED='\033[1;31m'
COLOR_GREEN='\033[1;32m'
COLOR_YELLOW='\033[1;33m'

BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
BRANCH_ISSUE_NUMBER='0'

if [[ "${BRANCH_NAME}" =~ ^iox-[0-9]+ ]]; then
BRANCH_ISSUE_NUMBER="$(echo "${BRANCH_NAME}" | grep -Eo 'iox-[0-9]+' | grep -Eo '[0-9]+')"
else
echo -e "${COLOR_YELLOW}"
echo -e "Warning: The branch name doesn't follow the convention of 'iox-ISSUE_NUMBER'."
echo -e "Commit message won't be autoformatted."
echo -e "${COLOR_RESET}"
exit 0
fi

COMMIT_MSG=$(cat $1)
if [[ ${COMMIT_MSG} =~ ^iox-#[0-9]+ ]]; then
COMMIT_ISSUE_NUMBER="$(echo "${COMMIT_MSG}" | grep -Eo 'iox-#[0-9]+' | grep -Eo '[0-9]+')"
if [[ "${COMMIT_ISSUE_NUMBER}" != "${BRANCH_ISSUE_NUMBER}" ]]; then
echo -e "${COLOR_YELLOW}"
echo -e "Warning: Commit message issue number does not fit to branch issue number: '${BRANCH_ISSUE_NUMBER}'"
echo -e "Is this on purpose?"
echo -e "Commit message will not be autoformatted."
echo -e "${COLOR_RESET}"
exit 0
fi
else
echo -e "${COLOR_GREEN}"
echo -e "Info: Commit message does not start with issue number: '${COMMIT_MSG}'"
echo -e "Commit message will be autoformatted."
echo -e "${COLOR_RESET}"
echo -e "iox-#${BRANCH_ISSUE_NUMBER} ${COMMIT_MSG}" > $1
fi

0 comments on commit fba60c9

Please sign in to comment.