diff --git a/bamboohr/widget.go b/bamboohr/widget.go index 13b5d124..04759454 100644 --- a/bamboohr/widget.go +++ b/bamboohr/widget.go @@ -58,7 +58,7 @@ func (widget *Widget) contentFrom(items []Item) string { return fmt.Sprintf("\n\n\n\n\n\n\n%s", wtf.CenterText("[grey]no one[white]", 52)) } - str := "" + str := "\n" for _, item := range items { str = str + widget.format(item) } diff --git a/git/client.go b/git/client.go index 7f678639..249f7907 100644 --- a/git/client.go +++ b/git/client.go @@ -9,13 +9,11 @@ import ( type Client struct { CommitCount int - Repository string } func NewClient() *Client { client := Client{ CommitCount: 10, - Repository: "/Users/Chris/Documents/Lendesk/core-api", } return &client @@ -23,7 +21,7 @@ func NewClient() *Client { /* -------------------- Unexported Functions -------------------- */ -func (client *Client) CurrentBranch() string { +func (client *Client) Branch() string { arg := []string{"rev-parse", "--abbrev-ref", "HEAD"} cmd := exec.Command("git", arg...) str := wtf.ExecuteCommand(cmd) @@ -50,3 +48,11 @@ func (client *Client) Commits() []string { return data } + +func (client *Client) Repository() string { + arg := []string{"rev-parse", "--show-toplevel"} + cmd := exec.Command("git", arg...) + str := wtf.ExecuteCommand(cmd) + + return str +} diff --git a/git/git.go b/git/git.go index dfc61c9c..78162541 100644 --- a/git/git.go +++ b/git/git.go @@ -7,8 +7,8 @@ func Fetch() map[string][]string { result := make(map[string][]string) - result["repo"] = []string{client.Repository} - result["branch"] = []string{client.CurrentBranch()} + result["repo"] = []string{client.Repository()} + result["branch"] = []string{client.Branch()} result["changes"] = client.ChangedFiles() result["commits"] = client.Commits() diff --git a/opsgenie/client.go b/opsgenie/client.go index 3ebf5335..97c7c300 100644 --- a/opsgenie/client.go +++ b/opsgenie/client.go @@ -1,33 +1,55 @@ package opsgenie import ( + "encoding/json" + "fmt" + "net/http" "os" - - ogcli "github.com/opsgenie/opsgenie-go-sdk/client" - sch "github.com/opsgenie/opsgenie-go-sdk/schedule" ) -func Fetch() string { - apiKey := os.Getenv("WTF_OPS_GENIE_API_KEY") - - cli := new(ogcli.OpsGenieClient) - cli.SetAPIKey(apiKey) - - scheduler, err := cli.Schedule() - if err != nil { - panic(err) - } - - request := sch.ListSchedulesRequest{} - response, err := scheduler.List(request) - if err != nil { - panic(err) - } - - var str string - for _, schedule := range response.Schedules { - str = str + schedule.Name + "\n" - } - - return "" +type Data struct { + OnCallRecipients []string `json:"onCallRecipients"` + Parent Parent `json:"_parent"` +} +type OnCallData struct { + Data Data `json:"data"` + Message string `json:"message"` + RequestID string `json:"requestId"` + Took float32 `json:"took"` +} + +type Parent struct { + ID string `json:"id"` + Name string `json:"name"` + Enabled bool `json:"enabled"` +} + +func Fetch() *OnCallData { + apiKey := os.Getenv("WTF_OPS_GENIE_API_KEY") + scheduleName := "Oversight" + + url := fmt.Sprintf("https://api.opsgenie.com/v2/schedules/%s/on-calls?scheduleIdentifierType=name&flat=true", scheduleName) + + req, err := http.NewRequest("GET", url, nil) + if err != nil { + panic(err) + } + + req.Header.Set("Authorization", fmt.Sprintf("GenieKey %s", apiKey)) + + client := &http.Client{} + + resp, err := client.Do(req) + if err != nil { + panic(err) + } + defer resp.Body.Close() + + var onCallData OnCallData + + if err := json.NewDecoder(resp.Body).Decode(&onCallData); err != nil { + panic(err) + } + + return &onCallData } diff --git a/opsgenie/widget.go b/opsgenie/widget.go index b1b77313..fd0712bf 100644 --- a/opsgenie/widget.go +++ b/opsgenie/widget.go @@ -1,7 +1,8 @@ package opsgenie import ( - //"fmt" + "fmt" + "strings" "time" "github.com/rivo/tview" @@ -31,13 +32,13 @@ func NewWidget() *Widget { /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - //data := Fetch() + data := Fetch() widget.View.SetTitle(" OpsGenie ") widget.RefreshedAt = time.Now() widget.View.Clear() - //fmt.Fprintf(widget.View, "%s", widget.contentFrom(data)) + fmt.Fprintf(widget.View, "%s", widget.contentFrom(data)) } /* -------------------- Unexported Functions -------------------- */ @@ -52,6 +53,10 @@ func (widget *Widget) addView() { widget.View = view } -func (widget *Widget) contentFrom(data string) string { - return data +func (widget *Widget) contentFrom(onCallData *OnCallData) string { + str := "\n" + str = str + fmt.Sprintf(" [red]%s[white]\n", onCallData.Data.Parent.Name) + str = str + fmt.Sprintf(" %s\n", strings.Join(onCallData.Data.OnCallRecipients, ", ")) + + return str } diff --git a/status/widget.go b/status/widget.go index 9fe9697e..ac638198 100644 --- a/status/widget.go +++ b/status/widget.go @@ -32,7 +32,7 @@ func NewWidget() *Widget { /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - widget.View.SetTitle(" 🎁 Status ") + widget.View.SetTitle(" 🎉 Status ") widget.RefreshedAt = time.Now() widget.View.Clear()