forked from mirrors/probot
Fix lint errors
This commit is contained in:
parent
318a3b435b
commit
a9ef02cd95
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
12
lib/jwt.js
12
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'});
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@
|
|||
"xo": {
|
||||
"esnext": true,
|
||||
"space": true,
|
||||
"rules": {},
|
||||
"rules": {
|
||||
"camelcase": 1
|
||||
},
|
||||
"ignores": [],
|
||||
"envs": [
|
||||
"node",
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue