<commit_before>package phases

import (
	"github.com/Everlane/evan/common"
	"github.com/Everlane/evan/slack"
)

type SlackNotifierPhase struct {
	// URL for the Slack Incoming Webhook
	Webhook string
	Channel string
	Format  func(common.Deployment) (*slack.Payload, error)
}

func (snp *SlackNotifierPhase) CanPreload() bool {
	return false
}

func (snp *SlackNotifierPhase) Execute(deployment common.Deployment, _ interface{}) error {
	payload, err := snp.Format(deployment)
	if err != nil {
		return err
	}

	// Don't send a message to Slack if the format function didn't return
	// a message to send
	if payload == nil {
		return nil
	}

	err = slack.Send(snp.Webhook, "", *payload)
	if err != nil {
		return err
	}

	return nil
}<commit_msg>Correcly default channel in Slack webhooks<commit_after>package phases

import (
	"github.com/Everlane/evan/common"
	"github.com/Everlane/evan/slack"
)

type SlackNotifierPhase struct {
	// URL for the Slack Incoming Webhook
	Webhook string
	Channel string
	Format  func(common.Deployment) (*slack.Payload, error)
}

func (snp *SlackNotifierPhase) CanPreload() bool {
	return false
}

func (snp *SlackNotifierPhase) Execute(deployment common.Deployment, _ interface{}) error {
	payload, err := snp.Format(deployment)
	if err != nil {
		return err
	}

	// Don't send a message to Slack if the format function didn't return
	// a message to send
	if payload == nil {
		return nil
	}

	if payload.Channel == "" {
		payload.Channel = snp.Channel
	}

	err = slack.Send(snp.Webhook, "", *payload)
	if err != nil {
		return err
	}

	return nil
}
{'fraction_non_alphanumeric': 0.10865445356917246, 'fraction_numerical': 0.0, 'mean_word_length': 3.9040247678018574, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7357538', 'n_tokens_mistral': 570, 'n_tokens_neox': 545, 'n_words': 159}