Last active
September 6, 2022 22:24
-
-
Save donpdonp/091fa5b48fbc664c9f5f to your computer and use it in GitHub Desktop.
gluon github status watch
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
(function() { | |
// setup | |
setup() | |
// descriptor | |
return {name: "github"} | |
}) | |
// global state | |
var report_channel = '#' //disable | |
var major_report_channel = '#pdxtech' | |
var old_status_json | |
var dbKey = 'github-status' | |
function setup() { | |
db.get(dbKey, function(status_json){ | |
if(status_json) { | |
var github = JSON.parse(status_json) | |
bot.say('#zrobo', 'github status loaded '+github.status.indicator) | |
old_status_json = status_json | |
} else { | |
bot.say('#zrobo', 'github status uninitialized') | |
} | |
}) | |
} | |
function go(msg) { | |
var override = false; | |
var clock = false | |
if (msg.method == "clocktower") { | |
var time = new Date(Date.parse(msg.params.time)) | |
if(time.getMinutes() % 5 == 0) { | |
clock = true | |
} | |
} | |
if (msg.method == "irc.privmsg") { | |
var temp_match = /^!?github/.exec(msg.params.message) | |
if(temp_match) { | |
override = true; | |
} | |
} | |
if(override || clock) { | |
// was https://status.github.com/api/last-message.json | |
var url = "https://kctbh9vrtdwd.statuspage.io/api/v2/summary.json" | |
var github_json = http.get(url) | |
try { | |
var github = JSON.parse(github_json) | |
if(old_status_json != github_json) { | |
db.set(dbKey, github_json) | |
if (clock) { | |
var old_status = JSON.parse(old_status_json) | |
var report | |
if(old_status.status.indicator == github.status.indicator) { | |
// no change | |
} else { | |
var nonops = nonoperational(github.components) | |
var opstat = nonops.map(function(o){return o.name+" "+o.status}) | |
report = "github status changed from "+old_status.status.indicator + | |
" -> "+github.status.indicator+": "+github.status.description + | |
" "+opstat.join(' ') | |
var channel = github.status.indicator == "major" ? major_report_channel : report_channel; | |
bot.say(channel, report) | |
} | |
} | |
old_status_json = github_json | |
} | |
} catch(e) { | |
bot.say(bot.admin_channel, "github json len "+github_json.length+" tail "+github_json.substr(github_json.length-20,20)+" "+e+" "+url) | |
} | |
if(override){ | |
var incidents = github.incidents.map(function(i){ | |
var update = '' | |
if (i.incident_updates.length > 0) { | |
update = i.incident_updates[0].body | |
} | |
return i.impact+"/"+i.name+' last update:'+update | |
}) | |
bot.say(msg.params.channel, 'github reports '+github.status.description+' ' | |
+github.incidents.length+' incidents: '+incidents.join(', ')) | |
} | |
} | |
} | |
function nonoperational(components) { | |
return components.filter(function(c){return c.status != "operational"}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment