Skip to content

Commit 6ed664b

Browse files
committed
move slack attachment createor interface
1 parent 4a6019f commit 6ed664b

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pkg/notifier/slacknotifier/slack.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ var emailRegExp = regexp.MustCompile("`^(?P<name>[a-zA-Z0-9.!#$%&'*+/=?^_ \\x60{
3131

3232
var typeNamePrefixRE = regexp.MustCompile(`^\*?([a-zA-Z0-9_]+\.)?`)
3333

34+
type SlackAttachmentCreator interface {
35+
SlackAttachment() slack.Attachment
36+
}
37+
38+
type SlackBlocksCreator interface {
39+
SlackBlocks() slack.Blocks
40+
}
41+
3442
type notifyTask struct {
3543
channel string
3644

@@ -297,7 +305,7 @@ func (n *Notifier) PostLiveNote(obj livenote.Object, opts ...livenote.Option) er
297305
}
298306

299307
var attachment slack.Attachment
300-
if creator, ok := note.Object.(types.SlackAttachmentCreator); ok {
308+
if creator, ok := note.Object.(SlackAttachmentCreator); ok {
301309
attachment = creator.SlackAttachment()
302310
} else {
303311
return fmt.Errorf("livenote object does not support types.SlackAttachmentCreator interface")
@@ -422,7 +430,7 @@ func filterSlackAttachments(args []interface{}) (slackAttachments []slack.Attach
422430

423431
slackAttachments = append(slackAttachments, *a)
424432

425-
case types.SlackAttachmentCreator:
433+
case SlackAttachmentCreator:
426434
if firstAttachmentOffset == -1 {
427435
firstAttachmentOffset = idx
428436
}
@@ -471,7 +479,7 @@ func (n *Notifier) NotifyTo(channel string, obj interface{}, args ...interface{}
471479
case *slack.Attachment:
472480
opts = append(opts, slack.MsgOptionAttachments(append([]slack.Attachment{*a}, slackAttachments...)...))
473481

474-
case types.SlackAttachmentCreator:
482+
case SlackAttachmentCreator:
475483
// convert object to slack attachment (if supported)
476484
opts = append(opts, slack.MsgOptionAttachments(append([]slack.Attachment{a.SlackAttachment()}, slackAttachments...)...))
477485

pkg/types/slack.go

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
11
package types
2-
3-
import "github.com/slack-go/slack"
4-
5-
type SlackAttachmentCreator interface {
6-
SlackAttachment() slack.Attachment
7-
}

0 commit comments

Comments
 (0)