generated from cybozu-go/neco-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
message.go
69 lines (61 loc) · 2.1 KB
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package agent
import (
"fmt"
"time"
"github.com/slack-go/slack"
)
const (
extendBlockID = "slack-agent-extend"
pickerActionID = "slack-agent-extend-timepicker"
buttonActionID = "slack-agent-extend-button"
)
func messageCIResult(color, text, job, pod string, extend bool) slack.MsgOption {
blockSet := []slack.Block{
slack.NewSectionBlock(
slack.NewTextBlockObject(slack.MarkdownType, text, false, false),
[]*slack.TextBlockObject{
// These test blocks are rendered as 2 columns of side-by-side text.
// So list field names and values two each.
slack.NewTextBlockObject(slack.MarkdownType, "Job", false, false),
slack.NewTextBlockObject(slack.MarkdownType, "Pod", false, false),
slack.NewTextBlockObject(slack.MarkdownType, job, false, false),
slack.NewTextBlockObject(slack.MarkdownType, pod, false, false),
},
nil,
),
}
if extend {
extendBlock := slack.NewActionBlock(
extendBlockID,
&slack.TimePickerBlockElement{
Type: slack.METTimepicker,
ActionID: pickerActionID,
InitialTime: time.Now().Add(30 * time.Minute).UTC().Format("03:04"),
},
slack.NewButtonBlockElement(
buttonActionID,
pod,
slack.NewTextBlockObject(slack.PlainTextType, "Extend", false, false),
),
)
blockSet = append(blockSet, extendBlock)
}
// We want to use the color bar. So use the attachment.
// ref: https://api.slack.com/messaging/attachments-to-blocks#switching_to_blocks
// > There is one exception, and that's the color parameter, which currently does not have a block alternative.
// > If you are strongly attached to the color bar, use the blocks parameter within an attachment.
return slack.MsgOptionAttachments(
slack.Attachment{
Color: color,
Blocks: slack.Blocks{
BlockSet: blockSet,
},
},
)
}
func messagePodExtendSuccess(pod string, extendedTime time.Time) slack.MsgOption {
return slack.MsgOptionText(fmt.Sprintf("%s is extended successfully.\n- %s", pod, extendedTime), false)
}
func messagePodExtendFailure(pod string) slack.MsgOption {
return slack.MsgOptionText(fmt.Sprintf("Failed to extend pod.\n- %s", pod), false)
}