mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Use new api format
This commit is contained in:
parent
c0ba7cdb6c
commit
60794cb3e1
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type OnCallResponse struct {
|
type OnCallResponse struct {
|
||||||
OnCallData []OnCallData `json:"data"`
|
OnCallData OnCallData `json:"data"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
RequestID string `json:"requestId"`
|
RequestID string `json:"requestId"`
|
||||||
Took float32 `json:"took"`
|
Took float32 `json:"took"`
|
||||||
@ -29,12 +29,17 @@ type Parent struct {
|
|||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func Fetch() (*OnCallResponse, error) {
|
func Fetch(scheduleIdentifierType string, schedules []string) ([]*OnCallResponse, error) {
|
||||||
scheduleUrl := "https://api.opsgenie.com/v2/schedules/on-calls?flat=true"
|
agregatedResponses := []*OnCallResponse{}
|
||||||
|
for _, sched := range schedules {
|
||||||
|
scheduleUrl := fmt.Sprintf("https://api.opsgenie.com/v2/schedules/%s/on-calls?scheduleIdentifierType=%s&flat=true", sched, scheduleIdentifierType)
|
||||||
response, err := opsGenieRequest(scheduleUrl, apiKey())
|
response, err := opsGenieRequest(scheduleUrl, apiKey())
|
||||||
|
agregatedResponses = append(agregatedResponses, response)
|
||||||
return response, err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return agregatedResponses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -23,8 +23,10 @@ func NewWidget(app *tview.Application) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
data, err := Fetch()
|
data, err := Fetch(
|
||||||
|
wtf.Config.UString("wtf.mods.opsgenie.scheduleIdentifierType"),
|
||||||
|
getSchedules(),
|
||||||
|
)
|
||||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
||||||
|
|
||||||
var content string
|
var content string
|
||||||
@ -41,24 +43,42 @@ func (widget *Widget) Refresh() {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(onCallResponse *OnCallResponse) string {
|
func getSchedules() []string {
|
||||||
|
// see if schedule is set to a single string
|
||||||
|
configPath := "wtf.mods.opsgenie.schedule"
|
||||||
|
singleSchedule, err := wtf.Config.String(configPath)
|
||||||
|
if err == nil {
|
||||||
|
return []string{singleSchedule}
|
||||||
|
}
|
||||||
|
// else, assume list
|
||||||
|
scheduleList := wtf.Config.UList(configPath)
|
||||||
|
var ret []string
|
||||||
|
for _, schedule := range scheduleList {
|
||||||
|
if str, ok := schedule.(string); ok {
|
||||||
|
ret = append(ret, str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) contentFrom(onCallResponses []*OnCallResponse) string {
|
||||||
str := ""
|
str := ""
|
||||||
|
|
||||||
displayEmpty := wtf.Config.UBool("wtf.mods.opsgenie.displayEmpty", true)
|
displayEmpty := wtf.Config.UBool("wtf.mods.opsgenie.displayEmpty", true)
|
||||||
|
|
||||||
for _, data := range onCallResponse.OnCallData {
|
for _, data := range onCallResponses {
|
||||||
if (len(data.Recipients) == 0) && (displayEmpty == false) {
|
if (len(data.OnCallData.Recipients) == 0) && (displayEmpty == false) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg string
|
var msg string
|
||||||
if len(data.Recipients) == 0 {
|
if len(data.OnCallData.Recipients) == 0 {
|
||||||
msg = " [gray]no one[white]\n\n"
|
msg = " [gray]no one[white]\n\n"
|
||||||
} else {
|
} else {
|
||||||
msg = fmt.Sprintf(" %s\n\n", strings.Join(wtf.NamesFromEmails(data.Recipients), ", "))
|
msg = fmt.Sprintf(" %s\n\n", strings.Join(wtf.NamesFromEmails(data.OnCallData.Recipients), ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
str = str + widget.cleanScheduleName(data.Parent.Name)
|
str = str + widget.cleanScheduleName(data.OnCallData.Parent.Name)
|
||||||
str = str + msg
|
str = str + msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user