Fix lint errors

This commit is contained in:
Brandon Keepers 2016-10-12 20:44:13 -05:00
parent 318a3b435b
commit a9ef02cd95
No known key found for this signature in database
GPG Key ID: F9533396D5FACBF6
5 changed files with 25 additions and 23 deletions

View File

@ -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;
});
}
}
};

View File

@ -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'});
}

View File

@ -26,7 +26,9 @@
"xo": {
"esnext": true,
"space": true,
"rules": {},
"rules": {
"camelcase": 1
},
"ignores": [],
"envs": [
"node",

View File

@ -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);
});
});
}

View File

@ -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);
})
});
});
});