diff --git a/example/incident_list.json b/example/incident_list.json new file mode 100755 index 0000000..8a03255 --- /dev/null +++ b/example/incident_list.json @@ -0,0 +1 @@ +[{"id":"QINCIDENT00002","type":"incident","summary":"[#1234567] console-ErrorBudgetBurn CRITICAL (1)","self":"https://api.pagerduty.com/incidents/QINCIDENT00002","html_url":"https://subdomain.pagerduty.com/incidents/QINCIDENT00002","incident_number":1234567,"title":"console-ErrorBudgetBurn CRITICAL (1)","description":"console-ErrorBudgetBurn CRITICAL (1)","created_at":"2024-07-25T23:06:00Z","pending_actions":[{"type":"unacknowledge","at":"2024-07-26T05:06:41Z"}],"incident_key":"gwtiabpw2aznaopxyjgfuf6mibppmhmp8984iej759s9znu5mouk2b6qy7xpskou","service":{"id":"PSVC001","type":"service_reference","summary":"cluster.xy09.p1.example.org-hive-cluster","self":"https://api.pagerduty.com/services/PSVC001","html_url":"https://subdomain.pagerduty.com/service-directory/PSVC001"},"assignments":[{"at":"2024-07-25T23:06:00Z","assignee":{"id":"PUSER01","type":"user_reference","summary":"Jane SRE","self":"https://api.pagerduty.com/users/PUSER01","html_url":"https://subdomain.pagerduty.com/users/PUSER01"}}],"acknowledgements":[{"at":"2024-07-25T23:06:41Z","acknowledger":{"id":"PUSER01","type":"user_reference","summary":"Jane SRE","self":"https://api.pagerduty.com/users/PUSER01","html_url":"https://subdomain.pagerduty.com/users/PUSER01"}}],"last_status_change_at":"2024-07-25T23:06:41Z","last_status_change_by":{"id":"PUSER01","type":"user_reference","summary":"Jane SRE","self":"https://api.pagerduty.com/users/PUSER01","html_url":"https://subdomain.pagerduty.com/users/PUSER01"},"first_trigger_log_entry":{"id":"4PJTMFSWQQYTLJ25A26J4BMZLA","type":"trigger_log_entry_reference","summary":"Triggered through the API.","self":"https://api.pagerduty.com/log_entries/4PJTMFSWQQYTLJ25A26J4BMZLA","html_url":"https://subdomain.pagerduty.com/incidents/QINCIDENT00002/log_entries/4PJTMFSWQQYTLJ25A26J4BMZLA","agent":{},"channel":{},"acknowledgement_timeout":0,"incident":{}},"escalation_policy":{"id":"PESCPLC","type":"escalation_policy_reference","summary":"Escalation Policy","self":"https://api.pagerduty.com/escalation_policies/PESCPLC","html_url":"https://subdomain.pagerduty.com/escalation_policies/PESCPLC"},"teams":[{"id":"PTEAM01","type":"team_reference","summary":"Platform SRE","self":"https://api.pagerduty.com/teams/PTEAM01","html_url":"https://subdomain.pagerduty.com/teams/PTEAM01"}],"urgency":"high","status":"acknowledged","resolve_reason":{"incident":{}},"alert_counts":{"triggered":1,"resolved":5,"all":6},"body":{},"is_mergeable":true,"assigned_via":"escalation_policy","updated_at":"2024-07-25T23:06:41Z"},{"id":"QINCIDENT00001","type":"incident","summary":"[#9876543] cluster.ab12.p1.example.org has gone missing","self":"https://api.pagerduty.com/incidents/QINCIDENT00001","html_url":"https://subdomain.pagerduty.com/incidents/QINCIDENT00001","incident_number":9876543,"title":"cluster.ab12.p1.example.org has gone missing","description":"cluster.ab12.p1.example.org has gone missing","created_at":"2024-07-26T00:15:44Z","pending_actions":[{"type":"unacknowledge","at":"2024-07-26T06:16:29Z"}],"incident_key":"dms/1a32a5cd7c","service":{"id":"PSVC002","type":"service_reference","summary":"prod-deadmanssnitch","self":"https://api.pagerduty.com/services/PSVC002","html_url":"https://subdomain.pagerduty.com/service-directory/PSVC002"},"assignments":[{"at":"2024-07-26T00:15:50Z","assignee":{"id":"PUSER01","type":"user_reference","summary":"Jane SRE","self":"https://api.pagerduty.com/users/PUSER01","html_url":"https://subdomain.pagerduty.com/users/PUSER01"}}],"acknowledgements":[{"at":"2024-07-26T00:16:29Z","acknowledger":{"id":"PUSER01","type":"user_reference","summary":"Jane SRE","self":"https://api.pagerduty.com/users/PUSER01","html_url":"https://subdomain.pagerduty.com/users/PUSER01"}}],"last_status_change_at":"2024-07-26T00:16:29Z","last_status_change_by":{"id":"PUSER01","type":"user_reference","summary":"Jane SRE","self":"https://api.pagerduty.com/users/PUSER01","html_url":"https://subdomain.pagerduty.com/users/PUSER01"},"first_trigger_log_entry":{"id":"6AB6CD5VAHHFLLUK7Q98DYG2R5","type":"trigger_log_entry_reference","summary":"Triggered through the API.","self":"https://api.pagerduty.com/log_entries/6AB6CD5VAHHFLLUK7Q98DYG2R5","html_url":"https://subdomain.pagerduty.com/incidents/QINCIDENT00001/log_entries/6AB6CD5VAHHFLLUK7Q98DYG2R5","agent":{},"channel":{},"acknowledgement_timeout":0,"incident":{}},"escalation_policy":{"id":"PESCPLC","type":"escalation_policy_reference","summary":"Escalation Policy","self":"https://api.pagerduty.com/escalation_policies/PESCPLC","html_url":"https://subdomain.pagerduty.com/escalation_policies/PESCPLC"},"teams":[{"id":"PTEAM01","type":"team_reference","summary":"Platform SRE","self":"https://api.pagerduty.com/teams/PTEAM01","html_url":"https://subdomain.pagerduty.com/teams/PTEAM01"}],"urgency":"high","status":"acknowledged","resolve_reason":{"incident":{}},"alert_counts":{"triggered":1,"all":1},"body":{},"is_mergeable":true,"assigned_via":"escalation_policy","updated_at":"2024-07-26T00:16:29Z"}] diff --git a/pkg/tui/commands.go b/pkg/tui/commands.go index 09b2207..7f8b538 100644 --- a/pkg/tui/commands.go +++ b/pkg/tui/commands.go @@ -2,6 +2,7 @@ package tui import ( "context" + "encoding/json" "errors" "fmt" "io" @@ -528,3 +529,17 @@ func doIfIncidentSelected(m *model, cmd tea.Cmd) tea.Cmd { cmd, ) } + +// writeJSONDataToFile writes the given json data to the given file +// This is useful for debugging and generating test data +// IMPORTANT: sanitize/anonymize any sensitive data +// lint:ignore U1000 - future proofing +func writeJSONDataToFile(d any, f string) error { + jsonString, err := json.Marshal(d) + if err != nil { + return err + } + os.WriteFile(f, jsonString, os.ModePerm) + + return nil +}