[refactor] Add eslint and do dependency injection
This commit is contained in:
parent
dce4394ff6
commit
968f1a8e1e
|
@ -0,0 +1,29 @@
|
|||
module.exports = {
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"rules": {
|
||||
"indent": [ "error", "tab" ],
|
||||
"operator-linebreak": [ "error", "before" ],
|
||||
"semi": [ "error", "always" ],
|
||||
"comma-dangle": [ "error", "only-multiline" ],
|
||||
"quotes": [ "error", "double" ],
|
||||
"no-tabs": [ "error", { "allowIndentationTabs": true } ],
|
||||
"padded-blocks": 2,
|
||||
"space-before-blocks": 2,
|
||||
"comma-style": 2,
|
||||
"no-console": 0,
|
||||
"valid-typeof": 0,
|
||||
"arrow-parens": 0,
|
||||
"generator-star-spacing": 0,
|
||||
"space-before-function-paren": 0,
|
||||
"object-property-newline": 0,
|
||||
"new-cap": 0,
|
||||
"no-eval": 0
|
||||
}
|
||||
};
|
|
@ -1,2 +1,3 @@
|
|||
node_modules
|
||||
config.js
|
||||
store
|
||||
|
|
6
bot.js
6
bot.js
|
@ -1,5 +1,9 @@
|
|||
const Telegraf = require("telegraf");
|
||||
const config = require("./config");
|
||||
const Sequelize = require("sequelize");
|
||||
|
||||
const main = require("./bot");
|
||||
const config = require("./config");
|
||||
const db = require("./data")(Sequelize, config);
|
||||
const bot = new Telegraf(config.botApiKey);
|
||||
|
||||
Promise.all([ bot, db, config ]).then(main);
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = ([ bot, db, config ]) => {
|
||||
|
||||
};
|
|
@ -1,8 +1,8 @@
|
|||
const Sequelize = require("sequelize");
|
||||
const config = require("../config");
|
||||
module.exports = (Sequelize, config) => {
|
||||
|
||||
const { database, username, password, options } = config.sequelize;
|
||||
const sequelize = new Sequelize(database, username, password, options);
|
||||
const models = require("../models")(sequelize);
|
||||
const { database, username, password, options } = config.sequelize;
|
||||
const sequelize = new Sequelize(database, username, password, options);
|
||||
const models = require("../models")(sequelize);
|
||||
return sequelize.sync().then(() => models);
|
||||
|
||||
module.exports = sequelize.sync().then(() => models);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const Sequelize = require("sequelize");
|
||||
module.exports = sequelize => {
|
||||
const integrations = sequelize.define("integrations", {
|
||||
module.exports = sequelize =>
|
||||
sequelize.define("integrations", {
|
||||
chatID: { type: Sequelize.INTEGER, allowNull: false, unique: "com"},
|
||||
repoURL: {type: Sequelize.STRING, allowNull: false, unique: "com"},
|
||||
chatType: {type: Sequelize.STRING},
|
||||
|
@ -8,5 +8,3 @@ module.exports = sequelize => {
|
|||
pullRequests: {type: Sequelize.BOOLEAN, defaultValue: false},
|
||||
commits: {type: Sequelize.BOOLEAN, defaultValue: true},
|
||||
});
|
||||
integrations.sync().then(return integration);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "git-alerts-bot",
|
||||
"version": "1.0.0",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "git-alerts-bot",
|
||||
"version": "1.0.0",
|
||||
"version": "0.1.0",
|
||||
"description": "TG Bot for Gitlab/Github",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -12,7 +12,7 @@ module.exports = {
|
|||
host: "localhost",
|
||||
dialect: "sqlite",
|
||||
// SQLite only
|
||||
storage: "./git-alerts-bot.sqlite"
|
||||
storage: "./store/git-alerts-bot.sqlite"
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -4,7 +4,9 @@ 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"));
|
||||
|
|
|
@ -1,16 +1,24 @@
|
|||
const github = function (data) {
|
||||
const noun = "commit" + data.commits.length > 1?"s":"";
|
||||
|
||||
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`;
|
||||
|
||||
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;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
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};
|
||||
|
|
Loading…
Reference in New Issue