Fix esnext errors

This commit is contained in:
Brandon Keepers 2016-10-10 10:27:57 -05:00
parent a8370917b2
commit 11ab8be65f
No known key found for this signature in database
GPG Key ID: F9533396D5FACBF6
6 changed files with 41 additions and 41 deletions

View File

@ -1,5 +1,5 @@
module.exports = {
comment: require('./actions/comment'),
label: require('./actions/label'),
unlabel: require('./actions/unlabel'),
unlabel: require('./actions/unlabel')
};

View File

@ -21,7 +21,7 @@ module.exports = class Configuration {
return this.behaviors.filter(behavior => {
const parts = behavior.on.split('.');
return parts[0] === event.event &&
(!parts[1] || parts[1] == event.payload.action)
})
(!parts[1] || parts[1] === event.payload.action);
});
}
}
};

View File

@ -5,17 +5,17 @@ const GitHubApi = require('github');
const Configuration = require('./lib/configuration');
const Dispatcher = require('./lib/dispatcher');
let PORT = process.env.PORT || 3000;
let webhook = createHandler({path: '/', secret: process.env.WEBHOOK_SECRET || 'secret'});
const PORT = process.env.PORT || 3000;
const webhook = createHandler({path: '/', secret: process.env.WEBHOOK_SECRET || 'secret'});
let github = new GitHubApi();
const github = new GitHubApi();
github.authenticate({
type: 'oauth',
token: process.env.GITHUB_TOKEN
});
http.createServer(function (req, res) {
webhook(req, res, function (err) {
http.createServer((req, res) => {
webhook(req, res, err => {
if (err) {
console.log('ERROR', err);
res.statusCode = 500;
@ -27,7 +27,7 @@ http.createServer(function (req, res) {
});
}).listen(PORT);
webhook.on('*', function (event) {
webhook.on('*', event => {
if (event.payload.repository) {
const dispatcher = new Dispatcher(github, event);
return Configuration.load(github, event.payload.repository).then(
@ -36,4 +36,4 @@ webhook.on('*', function (event) {
}
});
console.log("Listening on http://localhost:" + PORT);
console.log('Listening on http://localhost:' + PORT);

View File

@ -29,7 +29,7 @@ describe('action.unlabel', () => {
number: 6,
name: 'hello'
});
expect(github.issues.removeLabel).toHaveBeenCalledWith({
user: 'bkeepers-inc',
repo: 'test',
@ -37,5 +37,4 @@ describe('action.unlabel', () => {
name: 'goodbye'
});
});
});

View File

@ -1,19 +1,19 @@
const expect = require('expect');
const Configuration = require('../lib/configuration');
const config = require ('./fixtures/content/probot.yml.json');
const config = require('./fixtures/content/probot.yml.json');
const createSpy = expect.createSpy;
describe('Configuration', function () {
describe('load', function() {
describe('Configuration', () => {
describe('load', () => {
let github;
const repo = {
owner: {login: 'bkeepers'},
name: 'test'
}
};
beforeEach(function() {
beforeEach(() => {
github = {
repos: {
getContent: createSpy().andReturn(Promise.resolve(config))
@ -21,38 +21,38 @@ describe('Configuration', function () {
};
});
it('loads from the repo', function(done) {
it('loads from the repo', done => {
Configuration.load(github, repo).then(config => {
expect(github.repos.getContent).toHaveBeenCalledWith({
user: 'bkeepers',
repo: 'test',
path: '.probot.yml'
})
});
expect(config.behaviors.length).toEqual(1)
expect(config.behaviors.length).toEqual(1);
done();
});
});
});
describe('behaviorsFor', function() {
describe('behaviorsFor', () => {
const config = new Configuration({behaviors: [
{on: 'issues', then: {comment: ''}},
{on: 'issues.created', then: {comment: ''}},
{on: 'pull_request.labeled', then: {comment: ''}},
{on: 'pull_request.labeled', then: {comment: ''}}
]});
it('returns behaviors for event', function () {
it('returns behaviors for event', () => {
expect(config.behaviorsFor({event: 'issues', payload: {}})).toEqual([
config.behaviors[0]
])
]);
});
it('returns behaviors for event and action', function () {
it('returns behaviors for event and action', () => {
expect(config.behaviorsFor({event: 'issues', payload: {action: 'created'}})).toEqual([
config.behaviors[0], config.behaviors[1]
])
]);
});
});
});

View File

@ -1,15 +1,16 @@
const expect = require('expect');
const Dispatcher = require('../lib/dispatcher');
const Configuration = require('../lib/configuration');
const payload = require ('./fixtures/webhook/comment.created.json');
const payload = require('./fixtures/webhook/comment.created.json');
const createSpy = expect.createSpy;
describe('dispatch', function () {
let event = {event: 'issues', payload: payload};
let github, dispatcher;
describe('dispatch', () => {
const event = {event: 'issues', payload};
let github;
let dispatcher;
beforeEach(function() {
beforeEach(() => {
github = {
issues: {
createComment: createSpy().andReturn(Promise.resolve())
@ -18,31 +19,31 @@ describe('dispatch', function () {
dispatcher = new Dispatcher(github, event);
});
describe('reply to new issue with a comment', function() {
describe('reply to new issue with a comment', () => {
const config = new Configuration({behaviors: [{on: 'issues', then: {comment: 'Hello World!'}}]});
it('posts a coment', function() {
return dispatcher.call(config).then(function() {
it('posts a coment', () => {
return dispatcher.call(config).then(() => {
expect(github.issues.createComment).toHaveBeenCalled();
});
});
});
describe('reply to new issue with a comment', function() {
describe('reply to new issue with a comment', () => {
const config = new Configuration({behaviors: [{on: 'issues.created', then: {comment: 'Hello World!'}}]});
it('calls the action', function() {
return dispatcher.call(config).then(function() {
it('calls the action', () => {
return dispatcher.call(config).then(() => {
expect(github.issues.createComment).toHaveBeenCalled();
});
});
});
describe('on an event with a different action', function() {
describe('on an event with a different action', () => {
const config = new Configuration({behaviors: [{on: 'issues.labeled', then: {comment: 'Hello World!'}}]});
it('does not perform behavior', function() {
return dispatcher.call(config).then(function() {
it('does not perform behavior', () => {
return dispatcher.call(config).then(() => {
expect(github.issues.createComment).toNotHaveBeenCalled();
});
});