Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Did this on holiday; loads to talk about.
- Added support for setting a secret - Refactored the whole project into a module - Added a bin script to connect and monitor on demand - Added a gulp script to build with browserify (see dist directory)
- Loading branch information
1 parent
bf07be8
commit ca8b07c
Showing
7 changed files
with
7,202 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env node | ||
|
||
var log = require('../logger'), | ||
pushclient = require('../index'), | ||
request = require('request'), | ||
minimist = require('minimist'); | ||
|
||
var argv = minimist(process.argv.slice(2), { | ||
string: 'secret', | ||
default: { | ||
secret: false, | ||
url: 'https://push-broker.herokuapp.com' | ||
} | ||
}); | ||
|
||
if (!argv.secret) { | ||
log.error('Please specify a secret with: --secret "your secret"') | ||
process.exit(1); | ||
} | ||
|
||
var client = pushclient.create({ | ||
url: argv.url, | ||
secret: argv.secret, | ||
onsecret: function () { | ||
log.info('Secret has been set.'); | ||
}, | ||
onpush: function (data) { | ||
console.log('PushEvent received: %s', data); | ||
|
||
var options = { | ||
url: 'http://localhost:3000/pushed-it', | ||
headers: { | ||
'X-Github-Event' : 'push', | ||
'X-Github-Delivery' : data.headers['X-Github-Delivery'], | ||
'X-Hub-Signature' : data.headers['X-Hub-Signature'], | ||
'User-Agent' : data.headers['User-Agent'] | ||
}, | ||
form: { | ||
payload: data.body | ||
} | ||
}; | ||
|
||
log.info('Sending PushEvent to CI...'); | ||
request.post(options, function (err, res, body) { | ||
if (err) | ||
return log.error('CI error:', err); | ||
|
||
if (res.statusCode !== 200) { | ||
log.error('CI returned status code: %d', res.statusCode); | ||
log.error('body: %s', body); | ||
return; | ||
} | ||
|
||
log.info('Sent PushEvent to CI successfully.'); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pushclient = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var wdw = typeof window === 'undefined' ? {} : window; | ||
var io = wdw.io || require('socket.io-client'); | ||
|
||
var defaultUrl = 'https://push-broker.herokuapp.com'; | ||
|
||
function ConnectClient(url, secret, onpush, onsecret) { | ||
var socket = io(url, { multiplex: true }); | ||
|
||
socket.on('connect', function () { | ||
socket.emit('secret', secret, function () { | ||
onsecret(secret); | ||
}); | ||
}) | ||
|
||
socket.on('PushEvent', function (data) { | ||
onpush(data); | ||
}); | ||
|
||
this.socket = socket; | ||
}; | ||
|
||
function PushClient() { | ||
} | ||
|
||
PushClient.prototype.disconnect = function() { | ||
this.socket.disconnect(); | ||
}; | ||
|
||
|
||
module.exports.create = function (options) { | ||
options = options || {}; | ||
url = options.url || defaultUrl; | ||
secret = options.secret || ''; | ||
onpush = options.onpush || function () {}; | ||
onsecret = options.onsecret || function () {}; | ||
|
||
var client = new PushClient(); | ||
ConnectClient.call(client, url, secret, onpush, onsecret); | ||
return client; | ||
} | ||
},{"socket.io-client":undefined}]},{},[1])(1) | ||
}); |
Oops, something went wrong.