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,10 +10,10 @@ import (
|
||||
)
|
||||
|
||||
type OnCallResponse struct {
|
||||
OnCallData []OnCallData `json:"data"`
|
||||
Message string `json:"message"`
|
||||
RequestID string `json:"requestId"`
|
||||
Took float32 `json:"took"`
|
||||
OnCallData OnCallData `json:"data"`
|
||||
Message string `json:"message"`
|
||||
RequestID string `json:"requestId"`
|
||||
Took float32 `json:"took"`
|
||||
}
|
||||
|
||||
type OnCallData struct {
|
||||
@ -29,12 +29,17 @@ type Parent struct {
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func Fetch() (*OnCallResponse, error) {
|
||||
scheduleUrl := "https://api.opsgenie.com/v2/schedules/on-calls?flat=true"
|
||||
|
||||
response, err := opsGenieRequest(scheduleUrl, apiKey())
|
||||
|
||||
return response, err
|
||||
func Fetch(scheduleIdentifierType string, schedules []string) ([]*OnCallResponse, error) {
|
||||
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())
|
||||
agregatedResponses = append(agregatedResponses, response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return agregatedResponses, nil
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
@ -23,8 +23,10 @@ func NewWidget(app *tview.Application) *Widget {
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
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))
|
||||
|
||||
var content string
|
||||
@ -41,24 +43,42 @@ func (widget *Widget) Refresh() {
|
||||
|
||||
/* -------------------- 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 := ""
|
||||
|
||||
displayEmpty := wtf.Config.UBool("wtf.mods.opsgenie.displayEmpty", true)
|
||||
|
||||
for _, data := range onCallResponse.OnCallData {
|
||||
if (len(data.Recipients) == 0) && (displayEmpty == false) {
|
||||
for _, data := range onCallResponses {
|
||||
if (len(data.OnCallData.Recipients) == 0) && (displayEmpty == false) {
|
||||
continue
|
||||
}
|
||||
|
||||
var msg string
|
||||
if len(data.Recipients) == 0 {
|
||||
if len(data.OnCallData.Recipients) == 0 {
|
||||
msg = " [gray]no one[white]\n\n"
|
||||
} 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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user