Skip to content
This repository has been archived by the owner on Jul 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from ember-learn/setting-up
Browse files Browse the repository at this point in the history
Setting up
acorncom committed May 6, 2016
2 parents 90e7241 + fcce37f commit 200e4ab
Showing 6 changed files with 124 additions and 15 deletions.
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
language: node_js
node_js:
- "0.10"

sudo: false

cache:
directories:
- node_modules

before_install:
- "npm config set spin false"
- "npm install -g npm@^2"

install:
- npm install

script:
- npm test
8 changes: 1 addition & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -13,12 +13,6 @@ var config = {
secret: process.env.WEBHOOK_SECRET || 'oursecrethere'
};

//if (process.env.WEBHOOK_SECRET === undefined) {
// console.error('No webhook secret defined, stopping now');
// return;
//}


var handler = createHandler({ path: config.path, secret: config.secret });

http.createServer(function (req, res) {
@@ -33,7 +27,7 @@ handler.on('error', function (err) {
});

handler.on('ping', function (event) {
console.log('Received a ping event for %s to %s',
console.log('Received ping event for %s to %s',
event.payload.repository.name,
util.inspect(event.payload.hook, false, null)
);
38 changes: 38 additions & 0 deletions lib/datastore-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Created by dbaker on 5/2/16.
*/
var firebase = require("firebase");
var firebaseHost = process.env.FIREBASE_APP || '"https://<app-name>.firebaseio.com/";';

module.exports = {
addIssue: function(repo, issueId, payload) {
var ref = this._setupFirebase(firebaseHost);
//ref.authWithCustomToken(AUTH_TOKEN, function(error, authData) {

repo = this._modifyRepoNameIfNeeded(repo);
var path = 'issues/' + repo + '/' + issueId
var issueRef = this._getStoreReference(ref, path);
issueRef.set(payload, function(error) {
if (error) {
console.log('failures' + error);
return false;
}
return true;
});

return true;
// return process.env['FIREBASE_SECRET'];
},

_setupFirebase: function(host) {
return new firebase(host);
},

_modifyRepoNameIfNeeded: function(repo) {
return repo.replace('.', '');
},

_getStoreReference: function(ref, path) {
return ref.child(path);
}
};
22 changes: 14 additions & 8 deletions lib/issue-handler.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/* jshint node: true */
'use strict';

var DataStore = require('./datastore-client');

module.exports = {

watching: {
'acorncom/ember-hitlist-tester': {
labels: [
'Help Wanted'
]
},
'emberjs/ember.js': {
labels: [
'Needs Help',
@@ -13,13 +20,13 @@ module.exports = {
},

issueLabeled: function (event) {

if (this.hasOneOfDesiredLabels(event.payload)) {

var issueHash = this.constructIssueHash(event.payload);

return this.addIssueToDatastore(issueHash);
var results = this.hasOneOfDesiredLabels(event.payload);
if (!results) {
return false;
}

var issueHash = this.constructIssueHash(event.payload);
return this.addIssueToDatastore(issueHash);
},

issueUnlabeled: function (event) {
@@ -61,8 +68,7 @@ module.exports = {
addIssueToDatastore: function (internalIssueHash) {

// send our issue hash to Firebase (not the original Github issue)

return true;
return DataStore.addIssue(internalIssueHash.repo, internalIssueHash.id, internalIssueHash);
},

/**
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
"sinon": "^1.17.3"
},
"dependencies": {
"firebase": "^2.4.2",
"github-webhook-handler": "^0.5.0"
}
}
50 changes: 50 additions & 0 deletions tests/unit/datastore-client-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* jshint node: true */
/* jshint mocha: true */
'use strict';

var assert = require('assert');
var path = require('path');
var sinon = require('sinon');

var DataStore = require('../../lib/datastore-client');

describe('adding an issue works', function() {

it('generates appropriate path for a normal repo name', function() {

var clientStub = sinon.stub(DataStore, '_setupFirebase', fakeHost);
var referenceStub = sinon.stub(DataStore, '_getStoreReference', fakeIssueRef);

var result = DataStore.addIssue('ember-cli/ember-cli', 10, {name: 'fakeData'});

clientStub.restore();
referenceStub.restore();
sinon.assert.calledWith(referenceStub, 'host-name', 'issues/ember-cli/ember-cli/10');

assert.ok(result, 'issue not properly sent to client');
});

it('generates modified path if we have a period in the name', function() {

var clientStub = sinon.stub(DataStore, '_setupFirebase', fakeHost);
var referenceStub = sinon.stub(DataStore, '_getStoreReference', fakeIssueRef);

var result = DataStore.addIssue('emberjs/ember.js', 10, {name: 'fakeData'});

clientStub.restore();
referenceStub.restore();
sinon.assert.calledWith(referenceStub, 'host-name', 'issues/emberjs/emberjs/10');

assert.ok(result, 'issue not properly sent to client');
});
});

function fakeHost() {
return 'host-name';
}

function fakeIssueRef() {
return {
set: sinon.stub().returns(true)
}
}

0 comments on commit 200e4ab

Please sign in to comment.