ifeq ($(PIPELINE_ACTION),destroy)
	export CODEFRESH_SLACK_WEBAPP_TEXT_ICON ?= :boom:
else
	export CODEFRESH_SLACK_WEBAPP_TEXT_ICON ?= :point_right:
endif

ifeq ($(PIPELINE_ACTION),destroy)
	export CODEFRESH_SLACK_TEXT_ICON ?= :boom:
else
	export CODEFRESH_SLACK_TEXT_ICON ?= :heavy_check_mark:
endif



## Send notification from codefresh to slack using "build" template
codefresh/notify/slack/build:
	$(call assert-set,PIPELINE_ACTION)
	$(call assert-set,CHART_NAME)
	$(call assert-set,CF_BUILD_URL)
	$(call assert-set,CF_REPO_OWNER)
	$(call assert-set,CF_REPO_NAME)
	$(call assert-set,CF_BUILD_TIMESTAMP)
	$(call assert-set,CF_BUILD_TRIGGER)
	@$(MAKE) slack/notify/build \
		ACTION=$(PIPELINE_ACTION) \
		NAME=$(CHART_NAME) \
		BUILD_URL=$(CF_BUILD_URL) \
		REPO_OWNER=$(CF_REPO_OWNER) \
		REPO_NAME=$(CF_REPO_NAME) \
		BUILD_TIMESTAMP=$(shell expr $(CF_BUILD_TIMESTAMP) / 1000) \
		BUILD_TRIGGER=$(CF_BUILD_TRIGGER)

## Send notification from codefresh to slack using "deploy" template
codefresh/notify/slack/deploy:
	$(call assert-set,PIPELINE_ENV)
	$(call assert-set,PIPELINE_ACTION)
	$(call assert-set,CHART_NAME)
	$(call assert-set,CF_BUILD_URL)
	$(call assert-set,CF_REPO_OWNER)
	$(call assert-set,CF_REPO_NAME)
	$(call assert-set,CF_BUILD_TIMESTAMP)
	$(call assert-set,CF_BUILD_TRIGGER)
	@$(MAKE) slack/notify/deploy \
		ACTION=$(PIPELINE_ACTION) \
		NAME=$(CHART_NAME) \
		ENVIRONMENT=$(PIPELINE_ENV) \
		BUILD_URL=$(CF_BUILD_URL) \
		REPO_OWNER=$(CF_REPO_OWNER) \
		REPO_NAME=$(CF_REPO_NAME) \
		BUILD_TIMESTAMP=$(shell expr $(CF_BUILD_TIMESTAMP) / 1000) \
		BUILD_TRIGGER=$(CF_BUILD_TRIGGER) \
		SLACK_TEXT="$(CODEFRESH_SLACK_TEXT_ICON) Done"

## Send notification from codefresh to slack using "deploy" template with exposed endpoint
codefresh/notify/slack/deploy/webapp:
	$(call assert-set,APP_HOST)
	$(call assert-set,PIPELINE_ENV)
	$(call assert-set,PIPELINE_ACTION)
	$(call assert-set,CHART_NAME)
	$(call assert-set,CF_BUILD_URL)
	$(call assert-set,CF_REPO_OWNER)
	$(call assert-set,CF_REPO_NAME)
	$(call assert-set,CF_BUILD_TIMESTAMP)
	$(call assert-set,CF_BUILD_TRIGGER)
	@$(MAKE) slack/notify/deploy \
		ACTION=$(PIPELINE_ACTION) \
		NAME=$(CHART_NAME) \
		ENVIRONMENT=$(PIPELINE_ENV) \
		BUILD_URL=$(CF_BUILD_URL) \
		REPO_OWNER=$(CF_REPO_OWNER) \
		REPO_NAME=$(CF_REPO_NAME) \
		BUILD_TIMESTAMP=$(shell expr $(CF_BUILD_TIMESTAMP) / 1000) \
		BUILD_TRIGGER=$(CF_BUILD_TRIGGER) \
		SLACK_TEXT="$(CODEFRESH_SLACK_WEBAPP_TEXT_ICON) $(APP_HOST)"

## Send notification from codefresh to slack using "codefresh-sync" template
codefresh/notify/slack/sync:
	$(call assert-set,PIPELINE_ACTION)
	$(call assert-set,CF_BUILD_URL)
	$(call assert-set,CF_REPO_OWNER)
	$(call assert-set,CF_REPO_NAME)
	$(call assert-set,CF_BUILD_TIMESTAMP)
	$(call assert-set,CF_BUILD_TRIGGER)
	$(call assert-set,ACCOUNTS)
	$(call assert-set,REPOSITORIES)
	$(call assert-set,PIPELINES)
	@$(MAKE) slack/notify \
		SLACK_NOTIFIER_TEMPLATE=$(BUILD_HARNESS_PATH)/templates/slack-notifier/sync.env \
		ACTION=$(PIPELINE_ACTION) \
		ACCOUNTS="$(ACCOUNTS)" \
		REPOSITORIES="$(REPOSITORIES)" \
		BUILD_URL=$(CF_BUILD_URL) \
		REPO_OWNER=$(CF_REPO_OWNER) \
		REPO_NAME=$(CF_REPO_NAME) \
		BUILD_TIMESTAMP=$(shell expr $(CF_BUILD_TIMESTAMP) / 1000) \
		BUILD_TRIGGER=$(CF_BUILD_TRIGGER)