/
microsoft_teams.go
63 lines (52 loc) · 1.47 KB
/
microsoft_teams.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
// Copyright (c) 2019, NewReleases CLI AUTHORS.
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cmd
import (
"context"
"github.com/spf13/cobra"
"newreleases.io/newreleases"
)
func (c *command) initMicrosoftTeamsCmd() (err error) {
cmd := &cobra.Command{
Use: "microsoft-teams",
Short: "List Microsoft Teams integrations",
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx, cancel := newClientContext(c.config)
defer cancel()
webhooks, err := c.microsoftTeamsWebhooksService.List(ctx)
if err != nil {
return err
}
if len(webhooks) == 0 {
cmd.Println("No Microsoft Teams Webhooks found.")
return nil
}
printWebhooksTable(cmd, webhooks)
return nil
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if err := addClientConfigOptions(cmd, c.config); err != nil {
return err
}
return c.setMicrosoftTeamsWebhooksService(cmd, args)
},
}
c.root.AddCommand(cmd)
return addClientFlags(cmd)
}
func (c *command) setMicrosoftTeamsWebhooksService(cmd *cobra.Command, args []string) (err error) {
if c.microsoftTeamsWebhooksService != nil {
return nil
}
client, err := c.getClient(cmd)
if err != nil {
return err
}
c.microsoftTeamsWebhooksService = client.MicrosoftTeamsWebhooks
return nil
}
type microsoftTeamsWebhooksService interface {
List(ctx context.Context) (webhooks []newreleases.Webhook, err error)
}