12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/bin/bash
- # --[ function
- function get_sed () {
- OS=$(uname -s)
- if [ "${OS}" == "Linux" ]; then
- SED=$(command -v sed)
- else
- SED=$(command -v gsed)
- fi
- if [ -z "${SED}" ]; then
- echo ">> GNU 'sed' was not found on the system."
- echo ">> Please install it"
- exit 1
- fi
- echo "${SED}"
- }
- function rebasing-branch() {
- for location in rebase-merge rebase-apply; do
- path=$(git rev-parse --git-path ${location})
- if test -d ${path}; then
- revision=$(<${path}/head-name)
- echo ${revision##refs/heads/}
- return 0
- fi
- done
- }
- function get_branch_name () {
- BRANCH_NAME="$(git branch --show-current)"
- if [ -z "${BRANCH_NAME}" ]; then
- BRANCH_NAME="$(rebasing-branch)"
- fi
- echo "${BRANCH_NAME}"
- }
- # Function to extract the ticket number:
- # Ex: 12324-toto -> AVXSRE-1234
- # 12134/titi -> AVXSRE-1234
- function clean_branch_name () {
- echo "$1" | grep -E -o '[0-9][0-9]+'
- }
- # --[ Env
- TRAILER=$1
- SED="$(get_sed)"
- BRANCH="$(get_branch_name)"
- CLEAN_BRANCH="$(clean_branch_name $BRANCH)"
- # --[ Main function
- echo "${1}-${CLEAN_BRANCH}"
|