<commit_before>package outputs

import (
	"fmt"
	"sort"

	"github.com/hexbotio/hex/models"
	"github.com/nlopes/slack"
)

// Slack struct
type Slack struct {
}

// Output function
func (x Slack) Write(message models.Message, config models.Config) {
	api := slack.New(config.SlackToken)
	msg := ""
	params := slack.NewPostMessageParameters()
	params.Username = config.BotName
	image := config.SlackIcon
	if image == "" {
		image = ":nut_and_bolt:"
	}
	params.IconEmoji = image
	for _, output := range message.Outputs {
		if message.Attributes["hex.rule.format"] == "true" {
			color := "grey"
			if output.Success {
				color = "good"
			} else {
				color = "danger"
			}
			attachment := slack.Attachment{
				Title:      "TBD", //message.Attributes["hex.pipeline.name"],
				Text:       "```" + output.Response + "```",
				Color:      color,
				MarkdownIn: []string{"text"},
			}
			params.Attachments = []slack.Attachment{attachment}
		} else {
			msg = msg + output.Response + "\n"
		}
	}
	if message.Debug {
		keys := make([]string, 0, len(message.Attributes))
		for key, _ := range message.Attributes {
			keys = append(keys, key)
		}
		sort.Strings(keys)
		msg = msg + fmt.Sprintf("\n```MESSAGE DEBUG (%d sec to complete)\n", message.EndTime-message.StartTime)
		for _, key := range keys {
			msg = msg + fmt.Sprintf("  %s: '%s'\n", key, message.Attributes[key])
		}
		msg = msg + "```"
	}<commit_msg>fixing slack formatted title<commit_after>package outputs

import (
	"fmt"
	"sort"

	"github.com/hexbotio/hex/models"
	"github.com/nlopes/slack"
)

// Slack struct
type Slack struct {
}

// Output function
func (x Slack) Write(message models.Message, config models.Config) {
	api := slack.New(config.SlackToken)
	msg := ""
	params := slack.NewPostMessageParameters()
	params.Username = config.BotName
	image := config.SlackIcon
	if image == "" {
		image = ":nut_and_bolt:"
	}
	params.IconEmoji = image
	for _, output := range message.Outputs {
		if message.Attributes["hex.rule.format"] == "true" {
			color := "grey"
			if output.Success {
				color = "good"
			} else {
				color = "danger"
			}
			attachment := slack.Attachment{
				Title:      message.Attributes["hex.rule.name"],
				Text:       "```" + output.Response + "```",
				Color:      color,
				MarkdownIn: []string{"text"},
			}
			params.Attachments = []slack.Attachment{attachment}
		} else {
			msg = msg + output.Response + "\n"
		}
	}
	if message.Debug {
		keys := make([]string, 0, len(message.Attributes))
		for key, _ := range message.Attributes {
			keys = append(keys, key)
		}
		sort.Strings(keys)
		msg = msg + fmt.Sprintf("\n```MESSAGE DEBUG (%d sec to complete)\n", message.EndTime-message.StartTime)
		for _, key := range keys {
			msg = msg + fmt.Sprintf("  %s: '%s'\n", key, message.Attributes[key])
		}
		msg = msg + "```"
	}
{'fraction_non_alphanumeric': 0.16702127659574467, 'fraction_numerical': 0.0007092198581560284, 'mean_word_length': 3.229385307346327, 'pattern_counts': {'":': 2, '<': 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': '3049556', 'n_tokens_mistral': 1092, 'n_tokens_neox': 969, 'n_words': 214}