From fccae7c10c1f378bcfb61c08b3fb9d2c1cabc681 Mon Sep 17 00:00:00 2001 From: jehfkemsy Date: Sat, 13 Jul 2019 20:38:14 -0400 Subject: [PATCH] added scripts --- hooks.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 hooks.js diff --git a/hooks.js b/hooks.js new file mode 100644 index 0000000..2c1888d --- /dev/null +++ b/hooks.js @@ -0,0 +1,45 @@ +//define our repos and secrets +const secret = "secret_key_which_is_also_stored_on_github"; +const repo = "path/to/local/repo"; + +const secret1 = "secret_key_which_is_also_stored_on_github1"; +const repo1 = "/path/to/local/repo"; + +//docs: https://nodejs.org/api/http.html +const http = require("http"); +//docs: https://nodejs.org/api/crypto.html#crypto_class_hmac +const crypto = require("crypto"); +//docs: https://nodejs.org/api/child_process.html +const exec = require("child_process").exec; + +http + .createServer(function(req, res) { + req.on("data", function(chunk) { + //get signatures for all repos...note: each repo must have a unique secrete + let sig = + "sha1=" + + crypto + .createHmac("sha1", secret) + .update(chunk.toString()) + .digest("hex"); + let sig1 = + "sha1=" + + crypto + .createHmac("sha1", secret1) + .update(chunk.toString()) + .digest("hex"); + + //choose which was updated ... posible bug: two repos get updated at the same time + switch (req.headers["x-hub-signature"]) { + case sig: + exec("cd " + repo + " && git pull && yarn build"); //execute whatever command you want + break; + case sig1: + exec("cd " + repo1 + " && git pull && yarn build"); + break; + } + }); + + res.end(); + }) + .listen(8080);