#!/bin/bash set -x if [ -z $GIT_COMMIT ]; then echo "Expected env var 'GIT_COMMIT' to be set. Exiting..." exit 1 fi echo "Check that only alert confings are being pushed" echo "$PWD" for file in $(git diff-tree -r --name-only ${GIT_COMMIT}^1 ${GIT_COMMIT}); do new_id=$(grep ^id\: $file) if [ ! -z "$new_id" ]; then total_id=$(grep "$new_id" alert_configs/*.yaml | wc -l) if [ $total_id -gt 1 ] ; then echo "Duplicated id found! Please update the id of the alert configuration" exit 1 fi fi dir=$(dirname ${file}) # alert_configs/ change triggers a test of the new or changed aler configs if [ "$dir" == "alert_configs" ] || [ "$dir" == "alert_routing_lookup" ] ; then echo "Good to merge" exit 0 else echo "Only automatic merges allowed for alert config files" exit 1 fi done