[refactor] /util to /strategies
This commit is contained in:
parent
1199d4e20d
commit
abf043a27a
|
@ -1,6 +1,6 @@
|
|||
const express = require("express");
|
||||
const main = require("./server/index");
|
||||
const convert = require("./util/convert");
|
||||
const main = require("./server/main");
|
||||
const strategies = require("./strategies");
|
||||
const { server: config } = require("./config");
|
||||
const PORT = config.server.port;
|
||||
|
||||
|
@ -9,7 +9,8 @@ const app = express();
|
|||
app.use(express.json());
|
||||
app.use((req, res, next) => {
|
||||
|
||||
req.convert = convert;
|
||||
// Add our strategies object to request
|
||||
req.strategies = strategies;
|
||||
next();
|
||||
|
||||
});
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
module.exports = app => {
|
||||
|
||||
app.get("/webhook/:provider", (req, res) => {
|
||||
|
||||
const strategy = req.params.provider;
|
||||
const eventType = req.convert.getEvent[strategy](req.body);
|
||||
|
||||
});
|
||||
|
||||
};
|
|
@ -0,0 +1,10 @@
|
|||
module.exports = app => {
|
||||
|
||||
app.get("/webhook/:provider", (req, res) => {
|
||||
|
||||
const { provider } = req.params;
|
||||
const eventType = req.strategies[provider].getEvent(req.body);
|
||||
|
||||
});
|
||||
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
module.exports = {
|
||||
|
||||
event (data) {
|
||||
|
||||
if (data.commits && data.ref.match("^/refs/heads/")) return "commit";
|
||||
if (data.commits && data.ref.match("^/refs/tags/")) return "tag";
|
||||
if (data.issue) return "issue";
|
||||
|
||||
},
|
||||
|
||||
commit (data) {
|
||||
|
||||
const noun = "commit" + data.commits.length > 1 ? "s" : "";
|
||||
var text = data.commits.reduce((acc, curr, index) => {
|
||||
|
||||
if (index < 6) {
|
||||
|
||||
acc += `<a href='${curr.url}'>${curr.id.slice(0,6)}: `
|
||||
+ `${curr.message}</a>\n`;
|
||||
|
||||
}
|
||||
return acc;
|
||||
|
||||
}, `🔨 ${data.commits.length} ${noun}\n`);
|
||||
if (data.commits.length > 6) {
|
||||
|
||||
text += `${data.commits.length - 6} more ${noun}.`;
|
||||
|
||||
}
|
||||
|
||||
return text;
|
||||
|
||||
},
|
||||
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
|
||||
github: require("./github"),
|
||||
|
||||
};
|
|
@ -1,26 +0,0 @@
|
|||
const github = function (data) {
|
||||
|
||||
const noun = "commit" + data.commits.length > 1 ? "s" : "";
|
||||
var text = data.commits.reduce((acc, curr, index) => {
|
||||
|
||||
if (index < 6) {
|
||||
|
||||
acc += `<a href='${curr.url}'>${curr.id.slice(0,6)}: `
|
||||
+ `${curr.message}</a>\n`;
|
||||
|
||||
}
|
||||
return acc;
|
||||
|
||||
}, `🔨 ${data.commits.length} ${noun}\n`);
|
||||
if (data.commits.length > 6) {
|
||||
|
||||
text += `${data.commits.length - 6} more ${noun}.`;
|
||||
|
||||
}
|
||||
return text;
|
||||
|
||||
};
|
||||
|
||||
const gitlab = github;
|
||||
|
||||
module.exports = { github, gitlab };
|
|
@ -1,9 +0,0 @@
|
|||
const github = function (body) {
|
||||
|
||||
if (body.commits && body.ref.match("^/refs/heads/")) return "commit";
|
||||
if (body.commits && body.ref.match("^/refs/tags/")) return "tag";
|
||||
if (body.issue) return "issue";
|
||||
|
||||
};
|
||||
|
||||
module.exports = {github};
|
|
@ -1,4 +0,0 @@
|
|||
module.exports = {
|
||||
getEvent: require("./event"),
|
||||
commit: require("./commit"),
|
||||
};
|
Loading…
Reference in New Issue