Skip to content

Commit

Permalink
Cleanup lint
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeBiellik committed Jul 27, 2019
1 parent 8e824e0 commit 04eabd8
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 63 deletions.
3 changes: 2 additions & 1 deletion controllers/api.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable require-atomic-updates */
const Plugins = require('../models/plugins');

module.exports = {
Expand Down Expand Up @@ -124,7 +125,7 @@ module.exports = {
return {
plugin: d.plugin,
version: d.version
}
};
}),
createdAt: v.createdAt,
updatedAt: v.updatedAt,
Expand Down
22 changes: 11 additions & 11 deletions controllers/error.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
46 changes: 25 additions & 21 deletions controllers/github.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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,
Expand Down Expand Up @@ -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`);
Expand Down Expand Up @@ -119,9 +120,9 @@ const deletePlugin = async (data) => {
deletedAt: Date.now()
}
}
)
);
console.log(`${repo.owner}/${repo.project} deleted.`);
}
};

const updatePlugin = async (data) => {
const repo = {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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;
Expand All @@ -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({
Expand Down Expand Up @@ -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}"`);
Expand All @@ -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}"`);
Expand Down
10 changes: 5 additions & 5 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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);
}
}
};
10 changes: 5 additions & 5 deletions controllers/owners.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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,
Expand All @@ -37,7 +37,7 @@ module.exports = {
next: page + 1
});
} catch (ex) {
util.log(ex)
util.log(ex);
}
}
};
10 changes: 5 additions & 5 deletions controllers/projects.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
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) {
try {
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) {
releases = releases.sort((a, b) => semver.rcompare(a.version, b.version));
}

let selectedRelease = releases[0];
if (version && version !== "*") {
if (version && version !== '*') {
selectedRelease = plugin.releases.filter(r => r.version == version)[0];
}

Expand All @@ -39,7 +39,7 @@ module.exports = {
moment: moment
});
} catch (ex) {
util.log(ex)
util.log(ex);
}
}
};
2 changes: 1 addition & 1 deletion controllers/search.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
14 changes: 4 additions & 10 deletions db.js
Original file line number Diff line number Diff line change
@@ -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;
};
4 changes: 2 additions & 2 deletions models/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 04eabd8

Please sign in to comment.