From a006277f26ace2270f81450515711b9b920a3474 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Mon, 26 Nov 2018 01:39:48 +0530 Subject: [PATCH] Add github commit coverter. Change to double quotes --- server.js | 8 ++++---- util/convert/commit.js | 14 +++++++++++++- util/convert/event.js | 5 +++-- util/convert/index.js | 4 ++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/server.js b/server.js index ef114bb..439ff2c 100644 --- a/server.js +++ b/server.js @@ -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")); diff --git a/util/convert/commit.js b/util/convert/commit.js index 6cd4aa9..8a28a20 100644 --- a/util/convert/commit.js +++ b/util/convert/commit.js @@ -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 += `${curr.id.slice(0,6)}: ` + + `${curr.message}\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; diff --git a/util/convert/event.js b/util/convert/event.js index 0982b78..04fa8e8 100644 --- a/util/convert/event.js +++ b/util/convert/event.js @@ -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}; diff --git a/util/convert/index.js b/util/convert/index.js index 2a65f54..1a44571 100644 --- a/util/convert/index.js +++ b/util/convert/index.js @@ -1,4 +1,4 @@ module.exports = { - getEvent: require('./event'), - commit: require('./commit'), + getEvent: require("./event"), + commit: require("./commit"), };