PLT-7077: ignore null array items in slack attachments (#6904)

* ignore null array items in incoming webhooks / command responses

* consolidate code, process announcements in command response as well

* make a bit more idiomatic, add tests

* add missing file
Этот коммит содержится в:
Chris
2017-07-12 06:43:07 -07:00
коммит произвёл Harrison Healey
родитель 83d53ea98c
Коммит 9ee7f661c7
6 изменённых файлов: 135 добавлений и 58 удалений

Просмотреть файл

@@ -5,7 +5,6 @@ package model
import (
"encoding/json"
"fmt"
"io"
)
@@ -15,12 +14,12 @@ const (
)
type CommandResponse struct {
ResponseType string `json:"response_type"`
Text string `json:"text"`
Username string `json:"username"`
IconURL string `json:"icon_url"`
GotoLocation string `json:"goto_location"`
Attachments []*SlackAttachment `json:"attachments"`
ResponseType string `json:"response_type"`
Text string `json:"text"`
Username string `json:"username"`
IconURL string `json:"icon_url"`
GotoLocation string `json:"goto_location"`
Attachments SlackAttachments `json:"attachments"`
}
func (o *CommandResponse) ToJson() string {
@@ -40,14 +39,8 @@ func CommandResponseFromJson(data io.Reader) *CommandResponse {
return nil
}
// Ensure attachment fields are stored as strings
for _, attachment := range o.Attachments {
for _, field := range attachment.Fields {
if field.Value != nil {
field.Value = fmt.Sprintf("%v", field.Value)
}
}
}
o.Text = ExpandAnnouncement(o.Text)
o.Attachments.Process()
return &o
}