memoryleak
6/18/2019 - 4:46 PM

git-ticket-status.sh

#!/bin/bash
REGEXP=$1
LOOKUP_BRANCH=$2

if [[ -z "$REGEXP" ]]; then
	echo "Usage: `basename "$0"` <ticket-regexp> [<branch>]"
	echo ""
	echo "Omit [<branch>] if you want to see all branches this ticket is deployed to."
	exit 1
fi

TICKETS=$(git branch -a | grep remotes | grep -E -o "$REGEXP" | sort)

if [[ ! -z "$LOOKUP_BRANCH" ]]; then
	BRANCH=$(git branch -a | grep remotes | grep "$REGEXP")
	BRANCH_RECENT_COMMIT=$(git log -n1 --pretty=oneline $BRANCH | cut -d " " -f1)
	RESULT=$(git branch --contains $BRANCH_RECENT_COMMIT $LOOKUP_BRANCH)

	if [[ ! -z "$RESULT" ]]; then
		exit 0
	fi
	exit 1
fi

for TICKET in $TICKETS; do
	echo "Iteration"
	BRANCH=$(git branch -a | grep remotes | grep "$TICKET")
	BRANCH_RECENT_COMMIT=$(git log -n1 --pretty=oneline $BRANCH | cut -d " " -f1)

	if [[ $TICKET -ne "" ]]; then
		BRANCHES=$(git branch --contains $BRANCH_RECENT_COMMIT | sort | tr "\n" "\t")
		echo "$TICKET	$BRANCHES"
	fi
done