From 0603a3ba3a1d78758152e64de474a0f94642c192 Mon Sep 17 00:00:00 2001 From: Rangarajan Radhakrishnan Date: Fri, 10 Jan 2014 18:19:22 -0500 Subject: [PATCH] use newer shell features (suitable for bash / Korn / Posix) changes: (1) backticks replaced by $(....) (2) sed delimiters changed to pipe, eliminating the need to escape backslashes (3) replace escaped double quoutes (inside double quotes), replaced them with single quotes without impacting variable interpolation (4) use of "==" for coparison instead of "=" --- hipchat-post-receive | 63 +++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/hipchat-post-receive b/hipchat-post-receive index 209f2e6..bf9f52e 100755 --- a/hipchat-post-receive +++ b/hipchat-post-receive @@ -1,30 +1,30 @@ -#!/bin/sh +#!/bin/bash # Read variables passed on by GIT read OLDREV NEWREV REFNAME # Find out basic variables -GIT_EXEC=${GIT_EXEC:-`which git`} -REPO=${REPO:-`basename $PWD`} -HIPCHAT_COLOR=${HIPCHAT_COLOR:-"yellow"} +GIT_EXEC="${GIT_EXEC:-$(which git)}" +REPO="${REPO:-$(basename $PWD)}" +HIPCHAT_COLOR="${HIPCHAT_COLOR:-'yellow'}" # User is commiter of either last or first commit NULLREV="0000000000000000000000000000000000000000" -[ "$NEWREV" = "$NULLREV" ] && USER_REV="$OLDREV" || USER_REV="$NEWREV" -USER=`$GIT_EXEC log -1 $USER_REV --format="%aN"` -BRANCH=${REFNAME#refs/heads/} +[[ "$NEWREV" == "$NULLREV" ]] && USER_REV="$OLDREV" || USER_REV="$NEWREV" +USER=$($GIT_EXEC log -1 $USER_REV --format="%aN") +BRANCH="${REFNAME#refs/heads/}" # Setup gitweb links -if [ -n "$GITWEB" ] +if [[ -n "$GITWEB" ]] then - USER_LINK="$USER" - BRANCH_LINK="$BRANCH" - REPO_LINK="$REPO" -elif [ -n "$CGIT" ] + USER_LINK="$USER" + BRANCH_LINK="$BRANCH" + REPO_LINK="$REPO" +elif [[ -n "$CGIT" ]] then USER_LINK=$USER - BRANCH_LINK="$BRANCH" - REPO_LINK="$REPO" + BRANCH_LINK="$BRANCH" + REPO_LINK="$REPO" else USER_LINK=$USER BRANCH_LINK=$BRANCH @@ -32,43 +32,46 @@ else fi # Construct gitorious links -if [ -n "$GITORIOUS" ] +if [[ -n "$GITORIOUS" ]] then - REPO_NO_GIT=`echo -e $REPO|sed "s/.git//g"` - USER_LINK="$USER" - REPO_LINK="$REPO" - BRANCH_LINK="$BRANCH" + REPO_NO_GIT=$(echo -e $REPO|sed "s/.git//g") + USER_LINK="$USER" + REPO_LINK="$REPO" + BRANCH_LINK="$BRANCH" fi # Construct message -if [ "$OLDREV" = "$NULLREV" ] +if [[ "$OLDREV" == "$NULLREV" ]] then MSG="$USER_LINK created branch $BRANCH_LINK of $REPO_LINK" HIPCHAT_COLOR="green" -elif [ "$NEWREV" = "$NULLREV" ] +elif [[ "$NEWREV" == "$NULLREV" ]] then MSG="$USER_LINK deleted branch $BRANCH of $REPO_LINK" HIPCHAT_COLOR="red" else TITLE="$USER_LINK pushed to branch $BRANCH_LINK of $REPO_LINK" - if [ -n "$GITWEB" ] + if [[ -n "$GITWEB" ]] then - LOG=`$GIT_EXEC log $OLDREV..$NEWREV --format="- %s (%h)"` - elif [ -n "$CGIT" ] + FMT_STR="- %s (%h)" + elif [[ -n "$CGIT" ]] then - LOG=`$GIT_EXEC log $OLDREV..$NEWREV --format="- %s (%h)"` + FMT_STR="- %s (%h)" elif [ -n "$GITORIOUS" ] then - LOG=`$GIT_EXEC log $OLDREV..$NEWREV --format="- %s (%h)"` + FMT_STR="- %s (%h)" else - LOG=`$GIT_EXEC log $OLDREV..$NEWREV --format="- %s (%h)"` + FMT_STR="- %s (%h)" fi - if [ -n "$REDMINE" ] + + LOG=$($GIT_EXEC log $OLDREV..$NEWREV --format="$FMT_STR") + + if [[ -n "$REDMINE" ]] then - LOG=`echo -e "$LOG" | sed "s/#\([0-9]*\)/#\1<\/a>/g"` + LOG=$(echo -e "$LOG" | sed "s|#\([0-9]*\)|#\1|g") elif [ -n "$JIRA" ] then - LOG=`echo -e "$LOG" | sed "s/\([A-Z]\{2,\}\-[0-9]\{1,\}\)/\1<\/a>/g"` + LOG=$(echo -e "$LOG" | sed "s|\([A-Z]\{2,\}\-[0-9]\{1,\}\)|\1|g") fi MSG="$TITLE\n$LOG" fi