-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |