#!/bin/sh

REPOS="$1"
REV="$2"

LOGFILE=/tmp/post-commit-${REV}.log
CHANGED=$(svnlook changed -r $REV $REPOS)
echo "${CHANGED}" > ${LOGFILE}

declare -A FE_MAP BE_MAP
FE_MAP=([20200205/IQuizoo_FrontEnd]="dnkt-mgr" [trunk/ant-design-pro]="jigou-mgr" [trunk/IQuizoo_Teaching_FE_New]="dnkt" [trunk/IQuizoo_Teaching_FE_Institution]="dnkt-jigou")
BE_MAP=([20200203/IdentityService]="identity" [20200203/APIGateway]="gateway" [20200203/UserService]="user" [20200203/ContentService]="content" [20200203/ExternalServices]="content-external" [20200203/FileService]="file" [20200203/TimingTasks]="timing-tasks" [20200203/DataCenter]="data-center" [20200203/SystemConfigService]="systemconfig")

for KEY in $(echo ${!FE_MAP[*]})
do
	grep ${KEY} ${LOGFILE} > /dev/null
	if [ `echo $?` -eq 0 ]; then
	  echo ${FE_MAP[${KEY}]} >> ${LOGFILE}
		#curl -X POST http://192.168.0.50:4000/api/bd/build/${FE_MAP[${KEY}]} &
	fi
done

for KEY in $(echo ${!BE_MAP[*]})
do
	grep ${KEY} ${LOGFILE} > /dev/null
	if [ `echo $?` -eq 0 ]; then
	  echo ${BE_MAP[${KEY}]} >> ${LOGFILE}
		#curl -X POST http://192.168.0.50:4000/api/bd/build/${BE_MAP[${KEY}]} &
	fi
done
