From 04eabd84ac51893013e12d83440d34d6bd3d59ed Mon Sep 17 00:00:00 2001 From: Joe Biellik Date: Sat, 27 Jul 2019 20:30:12 +0100 Subject: [PATCH] Cleanup lint --- controllers/api.js | 3 ++- controllers/error.js | 22 ++++++++++---------- controllers/github.js | 46 ++++++++++++++++++++++------------------- controllers/index.js | 10 ++++----- controllers/owners.js | 10 ++++----- controllers/projects.js | 10 ++++----- controllers/search.js | 2 +- db.js | 14 ++++--------- models/plugins.js | 4 ++-- server.js | 3 +-- 10 files changed, 61 insertions(+), 63 deletions(-) diff --git a/controllers/api.js b/controllers/api.js index 6d781b3..abfae52 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -1,3 +1,4 @@ +/* eslint-disable require-atomic-updates */ const Plugins = require('../models/plugins'); module.exports = { @@ -124,7 +125,7 @@ module.exports = { return { plugin: d.plugin, version: d.version - } + }; }), createdAt: v.createdAt, updatedAt: v.updatedAt, diff --git a/controllers/error.js b/controllers/error.js index 205dbe9..5696ec7 100644 --- a/controllers/error.js +++ b/controllers/error.js @@ -1,14 +1,14 @@ const config = require('config'); -const util = require('util') +const util = require('util'); exports.show = async (ctx, error) => { - try { - return await ctx.render('error', { - pretty: config.prettyHtml, - title: config.name, - error: error - }); - } catch (ex) { - util.log(ex) - } -} + try { + return await ctx.render('error', { + pretty: config.prettyHtml, + title: config.name, + error: error + }); + } catch (ex) { + util.log(ex); + } +}; diff --git a/controllers/github.js b/controllers/github.js index 8611d51..959eb72 100644 --- a/controllers/github.js +++ b/controllers/github.js @@ -1,3 +1,4 @@ +/* eslint-disable require-atomic-updates */ const config = require('config'); const unparsed = require('koa-body/unparsed.js'); const yaml = require('js-yaml'); @@ -7,7 +8,7 @@ const { App } = require('@octokit/app'); const Webhooks = require('@octokit/webhooks'); const Octokit = require('@octokit/rest'); const semver = require('semver'); -const util = require('util') +const util = require('util'); const app = new App({ id: config.github.appId, @@ -64,10 +65,10 @@ const createPlugin = async (data) => { throw new Error(`Unable to get ${repo.owner}/${repo.project} details, no update occurred`); } - let validReleases = [] + let validReleases = []; for (var release of releases.data) { const result = await validateReleases(client, repo, release); - if (result) validReleases.push(result) + if (result) validReleases.push(result); } if (validReleases.length < 1) { throw new Error(`${repo.owner}/${repo.project} has no valid releases, no update occurred`); @@ -119,9 +120,9 @@ const deletePlugin = async (data) => { deletedAt: Date.now() } } - ) + ); console.log(`${repo.owner}/${repo.project} deleted.`); -} +}; const updatePlugin = async (data) => { const repo = { @@ -180,10 +181,10 @@ const updatePlugin = async (data) => { }, { upsert: true } - ) + ); console.log(`${repo.owner}/${repo.project} updated, ${data.release.tag_name} added to releases`); -} +}; const deleteRelease = async (data) => { const repo = { @@ -202,15 +203,18 @@ const deleteRelease = async (data) => { throw new Error(`${repo.owner}/${repo.project} release(${data.release.tag_name}) isn't valid, no deletion occurred`); } - await Plugins.findOneAndUpdate( - { 'install_id': data.installation.id, 'releases.version': release.tag_name }, - { - $set: { 'releases.$.deletedAt': Date.now() } - }, { - upsert: true + await Plugins.findOneAndUpdate({ + 'install_id': data.installation.id, + 'releases.version': release.tag_name + }, + { + $set: { + 'releases.$.deletedAt': Date.now() } - ) -} + }, { + upsert: true + }); +}; const validateReleases = async (client, repo, release) => { if (release.draft) return null; @@ -225,10 +229,10 @@ const validateReleases = async (client, repo, release) => { release.readme = await getReadme(client, repo, release.tag_name); - release.dependencies = await getDependencies(release.definition.dependencies) + release.dependencies = await getDependencies(release.definition.dependencies); - return release -} + return release; +}; const getDefinition = async (client, repo, ref) => { const definition = await client.repos.getContents({ @@ -274,10 +278,10 @@ const getDependencies = async (dependencies) => { version: dependencies[key] }); }); - }; + } return output; -} +}; webhooks.on('ping', async ({ id, name, payload }) => { console.log(`[${id} | ${name}] received "${payload.zen}"`); @@ -291,7 +295,7 @@ webhooks.on('installation.created', async ({ id, name, payload }) => { webhooks.on('installation.deleted', async ({ id, name, payload }) => { console.log(`[${id} | ${name}] action "${payload.action}" on installation ID ${payload.installation.id}`); await deletePlugin(payload); -}) +}); webhooks.on('release.published', async ({ id, name, payload }) => { console.log(`[${id} | ${name}] action "${payload.action}" on "${payload.repository.full_name}"`); diff --git a/controllers/index.js b/controllers/index.js index 61b9e54..7aa4f2f 100644 --- a/controllers/index.js +++ b/controllers/index.js @@ -1,5 +1,5 @@ const config = require('config'); -const util = require('util') +const util = require('util'); const moment = require('moment'); const Plugins = require('../models/plugins'); @@ -37,7 +37,7 @@ module.exports = { } }]); - const developers = (await Plugins.distinct('owner')).length + const developers = (await Plugins.distinct('owner')).length; const top = await Plugins.aggregate([{ $unwind: '$releases' @@ -74,14 +74,14 @@ module.exports = { pretty: config.prettyHtml, title: config.name, uniquePlugins: totalPlugins.toLocaleString(), - pluginInstalls: installs[0].total.toLocaleString(), - pluginVersions: versions[0].total.toLocaleString(), + pluginInstalls: installs[0] && installs[0].total ? installs[0].total.toLocaleString() : '0', + pluginVersions: versions[0] && versions[0].total ? versions[0].total.toLocaleString() : '0', pluginDevelopers: developers.toLocaleString(), top: top.map(p => new Plugins(p)), moment: moment }); } catch (ex) { - util.log(ex) + util.log(ex); } } }; diff --git a/controllers/owners.js b/controllers/owners.js index 5e73a26..7bbf973 100644 --- a/controllers/owners.js +++ b/controllers/owners.js @@ -1,5 +1,5 @@ const config = require('config'); -const util = require('util') +const util = require('util'); const Plugins = require('../models/plugins'); const errorPage = require('./error'); @@ -14,9 +14,9 @@ module.exports = { if (ctx.query.page) page = Number(ctx.query.page); - if (!Number.isInteger(page)) await errorPage.show(ctx, 'Page not Found!') - if (page < 1 || page > totalPages) await errorPage.show(ctx, 'Page not Found!') - if (plugins.length < 1) await errorPage.show(ctx, 'Owner not Found!') + if (!Number.isInteger(page)) await errorPage.show(ctx, 'Page not Found!'); + if (page < 1 || page > totalPages) await errorPage.show(ctx, 'Page not Found!'); + if (plugins.length < 1) await errorPage.show(ctx, 'Owner not Found!'); const pagedResults = plugins.slice( perPage * page - perPage, @@ -37,7 +37,7 @@ module.exports = { next: page + 1 }); } catch (ex) { - util.log(ex) + util.log(ex); } } }; diff --git a/controllers/projects.js b/controllers/projects.js index e0d7f45..88ed887 100644 --- a/controllers/projects.js +++ b/controllers/projects.js @@ -1,10 +1,10 @@ const config = require('config'); -const util = require('util') +const util = require('util'); const moment = require('moment'); const semver = require('semver'); const Plugins = require('../models/plugins'); -const errorPage = require('./error') +const errorPage = require('./error'); module.exports = { async view(ctx) { @@ -12,7 +12,7 @@ module.exports = { const version = ctx.params.version; const plugin = await Plugins.findOne({ project: ctx.params.project }); - if (plugin == null) await errorPage.show(ctx, 'Plugin not found!') + if (plugin == null) await errorPage.show(ctx, 'Plugin not found!'); let releases = plugin.releases; if (plugin.has_release) { @@ -20,7 +20,7 @@ module.exports = { } let selectedRelease = releases[0]; - if (version && version !== "*") { + if (version && version !== '*') { selectedRelease = plugin.releases.filter(r => r.version == version)[0]; } @@ -39,7 +39,7 @@ module.exports = { moment: moment }); } catch (ex) { - util.log(ex) + util.log(ex); } } }; diff --git a/controllers/search.js b/controllers/search.js index 95b9287..3c1bdec 100644 --- a/controllers/search.js +++ b/controllers/search.js @@ -1,7 +1,7 @@ const config = require('config'); const Plugins = require('../models/plugins'); -const errorPage = require('./error') +const errorPage = require('./error'); module.exports = { async view(ctx) { diff --git a/db.js b/db.js index 2fe3e2c..b5def91 100644 --- a/db.js +++ b/db.js @@ -1,19 +1,13 @@ const config = require('config'); -const util = require('util'); const mongoose = require('mongoose'); module.exports = () => { - mongoose.Promise = global.Promise; - - mongoose.connection.on('open', util.log.bind(util, 'MongoDB connection open')); - mongoose.connection.on('disconnected', util.log.bind(util, 'MongoDB connection disconnected')); mongoose.connection.on('error', console.error.bind(console, 'MongoDB connection error:')); - mongoose.set('useCreateIndex', true); - mongoose.set('useFindAndModify', false); - //mongoose.set('debug', true); - - mongoose.connect(`mongodb://${config.database.host}/${config.database.db}`, { useNewUrlParser: true }); + mongoose.connect(`mongodb://${config.database.host}/${config.database.db}`, { + useCreateIndex: true, + useNewUrlParser: true + }); return mongoose.connection; }; diff --git a/models/plugins.js b/models/plugins.js index 409b2a9..8ff4a63 100644 --- a/models/plugins.js +++ b/models/plugins.js @@ -4,12 +4,12 @@ const lodash = require('lodash'); const Dependency = new mongoose.Schema({ plugin: { type: String, require: true}, version: { type: String, require: true} -}) +}); const Release = new mongoose.Schema({ version: { type: String, required: true }, download_url: { type: String, required: true }, - compatible: { type: Boolean, required: true, default: true }, //TODO Remove `default: true` when capable of detecing NFive compatibility + compatible: { type: Boolean, required: true, default: true }, //TODO Remove `default: true` when capable of detecting NFive compatibility downloads: { type: Number }, notes: String, readme: String, diff --git a/server.js b/server.js index 0864926..0e059c0 100644 --- a/server.js +++ b/server.js @@ -1,9 +1,8 @@ const config = require('config'); -const util = require('util'); const app = require('./app'); require('./db')(); module.exports = app.listen(process.env.PORT || config.port || 3000, function() { - util.log('Server started: http://localhost:%s/', this.address().port); + console.log('Server started: http://localhost:%s/', this.address().port); });