Last active
July 3, 2023 16:33
-
-
Save zph/790e9259a9afa4ab7741a493994d8fa8 to your computer and use it in GitHub Desktop.
Deno wrapper for pagerduty-cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S deno run --allow-all | |
// Relies on pd binary which is auto installed with npx https://github.com/martindstone/pagerduty-cli/blob/master/docs/incident.md#pd-incident-create | |
// for globals and happy editor | |
import "https://deno.land/x/[email protected]/globals.d.ts"; | |
// For shell like syntax without needing vl shebang | |
import "https://deno.land/x/[email protected]/globals.ts"; | |
import "https://deno.land/std/log/mod.ts" | |
import * as log from "https://deno.land/std/log/mod.ts"; | |
import { Checkbox } from "https://deno.land/x/[email protected]/prompt/checkbox.ts"; | |
import { Input } from "https://deno.land/x/[email protected]/prompt/input.ts"; | |
// Ensure dependencies | |
const PD = ["echo", "npx", "pagerduty-cli"] | |
await $`${PD} version` | |
// TODO: authenticate selectively if auth isn't setup | |
await $`${PD} auth web --default` | |
interface Teammate { | |
name: string; | |
value: string; | |
} | |
const teammates: Teammate[] = [ | |
{ name: "Jay", value: "[email protected]" }, | |
{ name: "Jane", value: "[email protected]" }, | |
{ name: "Joe", value: "[email protected]" }, | |
{ name: "Jolene", value: "[email protected]" }, | |
{ name: "Jana", value: "[email protected]" }, | |
] | |
const people: string[] = await Checkbox.prompt({ | |
message: "Pick teammate(s) to page for help", | |
info: true, | |
options: teammates, | |
}); | |
const title: string = await Input.prompt({ | |
message: "What's the incident title? (choose one or type custom)", | |
list: true, | |
info: true, | |
suggestions: [ | |
"URGENT: Help resolve SEV0", | |
"URGENT: Help resolve SEV1", | |
"URGENT: Companywide outage", | |
"Join to stop SEV2 from escalating", | |
] | |
, | |
}); | |
const details: string = await Input.prompt({ | |
message: "What's the incident details? (choose one or type custom and include google meet link or Slack channel)", | |
list: true, | |
info: true, | |
suggestions: [ | |
"Join me in #storage-operations", | |
"Ping me on Slack", | |
] | |
, | |
}); | |
log.info(`Creating incident and paging first person ${people[0]}`) | |
// TODO: remove echos used for testing | |
const response = await $`echo ${PD} incident create --user=${people[0]} --priority=high --title=${title} --details=${details}` | |
// TODO: enable once out of testing mode | |
//const r = JSON.parse(response.stdout) | |
//const { incident_id } = r; | |
const incident_id = 1 | |
if(people.length > 1) { | |
const restOfPeople = people.slice(1).map(p => `--user_emails=${p}`).join(" ") | |
await $`echo ${PD} incident responder add --ids ${incident_id} ${restOfPeople}` | |
} | |
log.info(`Help is on the way from ${people}. Try to mitigate or rally others to help in meantime!`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment