From a9ef02cd957537310371fc0447b1469b5a3bde41 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Wed, 12 Oct 2016 20:44:13 -0500 Subject: [PATCH] Fix lint errors --- lib/installations.js | 22 +++++++++++----------- lib/jwt.js | 12 ++++++------ package.json | 4 +++- server.js | 4 ++-- test/installation.js | 6 +++--- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/installations.js b/lib/installations.js index d90d271b..a2f6e443 100644 --- a/lib/installations.js +++ b/lib/installations.js @@ -1,11 +1,11 @@ -const jwt = require('./jwt'); const GitHubApi = require('github'); +const jwt = require('./jwt'); const github = new GitHubApi(); const installations = {}; module.exports = { - load: function() { + load: () => { github.authenticate({type: 'integration', token: jwt()}); // Get all installations. Eventually loading all installations on startup @@ -16,32 +16,32 @@ module.exports = { }); }, - register: function(installation) { + register: installation => { installations[installation.account.login] = installation; }, - unregister: function(installation) { + unregister: installation => { delete installations[installation.account.login]; }, // Get the installation for an account - for: function(account) { + for: account => { return installations[account]; }, // listen for installations or uninstallations - listen: function(webhook) { - webhook.on('integration_installation', function(event) { - if (event.payload.action == 'create') { + listen: webhook => { + webhook.on('integration_installation', event => { + if (event.payload.action === 'create') { this.register(event.payload.installation); - } else if (event.payload.action == 'deleted') { + } else if (event.payload.action === 'deleted') { this.unregister(event.payload.installation); } }); }, // https://developer.github.com/early-access/integrations/authentication/#as-an-installation - authAs: function(installation) { + authAs: installation => { const github = new GitHubApi(); github.authenticate({type: 'integration', token: jwt()}); return github.integrations.createInstallationToken({ @@ -52,4 +52,4 @@ module.exports = { return github; }); } -} +}; diff --git a/lib/jwt.js b/lib/jwt.js index 1a2ed67d..ece9dcb1 100644 --- a/lib/jwt.js +++ b/lib/jwt.js @@ -1,6 +1,6 @@ const fs = require('fs'); -const jwt = require('jsonwebtoken'); const process = require('process'); +const jwt = require('jsonwebtoken'); // sign with RSA SHA256 // FIXME: move to env var @@ -8,15 +8,15 @@ const cert = fs.readFileSync('private-key.pem'); // get private key module.exports = generate; -function generate () { - var payload = { +function generate() { + const payload = { // issued at time iat: Math.floor(new Date() / 1000), // JWT expiration time - exp: Math.floor(new Date() / 1000) + 60 * 5, + exp: (Math.floor(new Date() / 1000) + 60) * 5, // Integration's GitHub identifier iss: process.env.INTEGRATION_ID - } + }; - return jwt.sign(payload, cert, { algorithm: 'RS256'}); + return jwt.sign(payload, cert, {algorithm: 'RS256'}); } diff --git a/package.json b/package.json index a3b08ffd..a6bd6a9d 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,9 @@ "xo": { "esnext": true, "space": true, - "rules": {}, + "rules": { + "camelcase": 1 + }, "ignores": [], "envs": [ "node", diff --git a/server.js b/server.js index ccda37ad..15fe1711 100644 --- a/server.js +++ b/server.js @@ -40,11 +40,11 @@ http.createServer((req, res) => { webhook.on('*', event => { if (event.payload.repository) { - var installation = installations.for(event.payload.repository.owner.login); + const installation = installations.for(event.payload.repository.owner.login); installations.authAs(installation).then(github => { const dispatcher = new Dispatcher(github, event); return Configuration.load(github, event.payload.repository).then(config => { - dispatcher.call(config) + dispatcher.call(config); }); }); } diff --git a/test/installation.js b/test/installation.js index 310e4660..58572697 100644 --- a/test/installation.js +++ b/test/installation.js @@ -1,13 +1,13 @@ const expect = require('expect'); const installations = require('../lib/installations'); -const payload = require ('./fixtures/webhook/installation.deleted'); +const payload = require('./fixtures/webhook/installation.deleted'); describe('installation', () => { describe('register', () => { it('registers the installation', () => { installations.register(payload.installation); expect(installations.for('bkeepers-inc')).toEqual(payload.installation); - }) + }); }); describe('unregister', () => { @@ -15,6 +15,6 @@ describe('installation', () => { installations.register(payload.installation); installations.unregister(payload.installation); expect(installations.for('bkeepers-inc')).toBe(undefined); - }) + }); }); });