Add github commit coverter. Change to double quotes

This commit is contained in:
Ceda EI 2018-11-26 01:39:48 +05:30
parent bd0a88c7dc
commit a006277f26
4 changed files with 22 additions and 9 deletions

View File

@ -1,10 +1,10 @@
const express = require('express');
const express = require("express");
const app = express();
app.use(express.json());
const convert = require('./util/convert');
const convert = require("./util/convert");
app.get('/webhook/:provider', (req) => {
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'));
app.listen(2000, () => console.log("Listening on port 2000"));

View File

@ -1,4 +1,16 @@
const github = function (body) {
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;

View File

@ -1,6 +1,7 @@
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.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};

View File

@ -1,4 +1,4 @@
module.exports = {
getEvent: require('./event'),
commit: require('./commit'),
getEvent: require("./event"),
commit: require("./commit"),
};