From bd0a88c7dca7ef1c529e5e0305d082e8f5f6567d Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 25 Nov 2018 23:14:07 +0530 Subject: [PATCH] Create base structure --- .gitignore | 1 + bot.js | 0 server.js | 10 ++++++++++ util/convert/commit.js | 6 ++++++ util/convert/event.js | 6 ++++++ util/convert/index.js | 4 ++++ 6 files changed, 27 insertions(+) create mode 100644 .gitignore create mode 100644 bot.js create mode 100644 server.js create mode 100644 util/convert/commit.js create mode 100644 util/convert/event.js create mode 100644 util/convert/index.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/bot.js b/bot.js new file mode 100644 index 0000000..e69de29 diff --git a/server.js b/server.js new file mode 100644 index 0000000..ef114bb --- /dev/null +++ b/server.js @@ -0,0 +1,10 @@ +const express = require('express'); +const app = express(); +app.use(express.json()); +const convert = require('./util/convert'); + +app.get('/webhook/:provider', (req) => { + const strategy = req.params.provider; + const eventType = convert.getEvent[strategy](req.body); +}); +app.listen(2000, () => console.log('Listening on port 2000')); diff --git a/util/convert/commit.js b/util/convert/commit.js new file mode 100644 index 0000000..6cd4aa9 --- /dev/null +++ b/util/convert/commit.js @@ -0,0 +1,6 @@ +const github = function (body) { +}; + +const gitlab = github; + +module.exports = { github, gitlab }; diff --git a/util/convert/event.js b/util/convert/event.js new file mode 100644 index 0000000..0982b78 --- /dev/null +++ b/util/convert/event.js @@ -0,0 +1,6 @@ +const github = function (body) { + if (body.commits && body.ref.match("^/refs/heads/") return "commit"; + if (body.commits && body.ref.match("^/refs/tags/") return "tag"; +}; + +module.exports = {github}; diff --git a/util/convert/index.js b/util/convert/index.js new file mode 100644 index 0000000..2a65f54 --- /dev/null +++ b/util/convert/index.js @@ -0,0 +1,4 @@ +module.exports = { + getEvent: require('./event'), + commit: require('./commit'), +};