Skip to content

Instantly share code, notes, and snippets.

@kitop kitop/netlify.js
Created Oct 12, 2019

Embed
What would you like to do?
#!/usr/bin/env /usr/local/bin/node
const https = require("https");
const url = require("url");
const querystring = require('querystring')
// All my images as base64 strings
const imgLogo =
"iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJQAAFiUBSVIk8AAABBdpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iCiAgICAgICAgICAgIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIgogICAgICAgICAgICB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iCiAgICAgICAgICAgIHhtbG5zOnRpZmY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vdGlmZi8xLjAvIj4KICAgICAgICAgPHhtcE1NOkRlcml2ZWRGcm9tIHJkZjpwYXJzZVR5cGU9IlJlc291cmNlIj4KICAgICAgICAgICAgPHN0UmVmOmluc3RhbmNlSUQ+eG1wLmlpZDpFQzNGNDNDODdCMkIxMUU5QkNENURBRDc2M0QxRTREQjwvc3RSZWY6aW5zdGFuY2VJRD4KICAgICAgICAgICAgPHN0UmVmOmRvY3VtZW50SUQ+eG1wLmRpZDpFQzNGNDNDOTdCMkIxMUU5QkNENURBRDc2M0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DcyMDY4MTE5MTA5RjVGN0Q0RUY3RTBGIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjAxODAxMTc0MDcyMDY4MTE5MTA5RTk1MkM3Q0UzQ0M2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+7SjG7QAAAgpJREFUeNokkU1oE0EYht+Zne0mm3SzJtmQphJiC6Vp1RaF+lNB/AcPnqSleuxRPIiU0pvXHtSD1FtPiiJ48uBJC2JF8CD1UFoEE9KsIbFJ2jTs5m9/nN0MDHy83/vM984McV0X3nqx+kje2nz/IEDNeVHojHtaz5Z22478bvrS3bWHy89NTyMcII8Xr56wDn59GE0Yk+mYBVV2/EMOTYq9GsOff6FtdmzqztP1jbxw9mRK0bfefp7JNCevzJ7H6VtPkLm4hPSZRWSylzEcqEBo5RKVauNmoyO9FtLBwtK0Vpk/l+4hcWoBtGfAOcr5m3QOEFLTUBtfYDuO9nO7YLCYWJ+b0GxEJAJ7Zx2OPAwiyn4kt2fCNUt+Lxu3UWzW51g8YGSTig2RMhC7Axg6QEUfIE4P4BrlvaRigXvHWZjTQZGBiSFgQAEZUAHWnwDLgNttAN0jBBwTssRsBlnLdYXKmBSKgIRSIMEhDqpeIG489CO5pvfENogc3WOITW3UrE9jkQgHBodAwqOAFOtPaO/DlTgqmqjVD0G4l167/+xV3tSK1bYJqqgcioGGExzU+rUSwX7bQN7Qip6XRrXjhZHrayu7ZaqX9K/odvNwaYtfvO3XJX0Tv8uCPnLj5Yrn9X46wIenzGZ94sfH5Xus9X1WotWkl6jjxMtW8MK3mdurb+TB6A6X/v4XYABO7c//Tbpc4wAAAABJRU5ErkJggg==";
// First fetch all my sites
fetchNetlify("sites")
// Then fetch the build info for each of my sites and append the latest build
// info into what netlify returns
.then(sites => {
return Promise.all(
sites.map(site =>
fetchNetlify(`sites/${site.site_id}/builds`, { per_page: 1 }).then(builds => ({
...site,
...(builds && builds[0] && builds[0].id
? { __latestBuild__: builds[0] }
: {})
}))
)
);
})
/*
[
{
// `/sites` endpoint data from netlify
id: String,
site_id: String,
admin_url: <String> links to netlify admin page
url: <String> ,
updated_at: <String> ISO8601 format
// `/sites/:id/builds` data from netlify (the latest object)
__latestBuild__: {
"id": "5ceff7f99c0ff20174f10387",
"deploy_id": "5ceff7f99c0ff20174f10386",
"sha": null,
"done": false,
"error": null,
"created_at": "2019-05-30T15:34:17.629Z"
}
}
]
*/
.then(sites => {
// Ok now we have the data how we want, let's loop over it and concatenate
// a big string for bitbar
let log = "";
const addToLog = str => (log = log + str + "\n");
let notifications = 0;
sites.forEach(site => {
const hostname = new URL(site.url).hostname;
let img = imgClear;
if (site.__latestBuild__) {
const { done, error } = site.__latestBuild__;
if (error) {
notifications += 1;
img = imgRed;
} else if (done) {
img = imgGreen;
} else {
notifications += 1;
img = imgYellow;
}
}
addToLog(`${hostname} | href=${site.admin_url} image=${img}`);
});
// Log it all out
logNetlifyLogo(notifications);
console.log(log);
})
.catch(e => {
logNetlifyLogo();
console.log("Whoops, caught an error.");
console.log(e);
});
/**
* Outputs just the netlify logo in the menubar
*/
function logNetlifyLogo(notifications = 0) {
console.log(
`${notifications > 0 ? notifications : ""}|templateImage=${imgLogo}`
);
console.log("---");
}
/**
* Take a path to a Netlify API endpoint and return a promise which resolves
* to the data of that endpoint.
* @param {String} endpoint
*/
function fetchNetlify(endpoint, params = {}) {
return new Promise((resolve, reject) => {
let uri = `https://api.netlify.com/api/v1/${endpoint}`;
const query = querystring.stringify(params)
if(query) {
uri += `?${query}`
}
const options = {
headers: { "Authorization": "Bearer YOUR_TOKEN_HERE" }
}
https
.get(uri, options, res => {
let data = "";
// A chunk of data has been recieved.
res.on("data", chunk => {
data += chunk;
});
// The whole response has been received. Resolve it.
res.on("end", () => {
resolve(JSON.parse(data));
});
})
.on("error", err => {
reject("Error: " + err.message);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.