-
Notifications
You must be signed in to change notification settings - Fork 1
/
clearIssue.go
60 lines (51 loc) · 1.3 KB
/
clearIssue.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
package smee
import (
"context"
"fmt"
"os"
"time"
avcli "github.com/byuoitav/av-cli"
"github.com/byuoitav/av-cli/cli/cmd/args"
"github.com/byuoitav/av-cli/cli/cmd/wso2"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var closeIssueCmd = &cobra.Command{
Use: "closeIssue [room ID]",
Short: "Close a room issue in smee",
Args: args.ValidRoomID,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Closing issue for %s\n", args[0])
fail := func(format string, a ...interface{}) {
fmt.Printf(format, a...)
os.Exit(1)
}
idToken := wso2.GetIDToken()
auth := avcli.Auth{
Token: idToken,
User: "",
}
client, err := avcli.NewClient(viper.GetString("api"), auth)
if err != nil {
fail("unable to create client: %v\n", err)
}
ctx, cancel := context.WithTimeout(cmd.Context(), 30*time.Second)
defer cancel()
_, err = client.CloseMonitoringIssue(ctx, &avcli.ID{Id: args[0]})
switch {
case err != nil:
if s, ok := status.FromError(err); ok {
switch s.Code() {
case codes.Unavailable:
fail("api is unavailable: %s\n", s.Err())
default:
fail("%s\n", s.Err())
}
}
fail("unable to close issue: %s\n", err)
}
fmt.Printf("Room issue closed for %s.\n", args[0])
},
}