Skip to content
Browse files

removed restler and use with request

added force deployment with bitbucket too
  • Loading branch information...
1 parent 0aee4f3 commit a2b0d18f92af89b68992b4203ab948ec1435ec7b @arunoda committed Dec 10, 2011
Showing with 51 additions and 28 deletions.
  1. +28 −9 bin/nariya.js
  2. +1 −1 lib/webhookListener.js
  3. +1 −2 package.json
  4. +21 −16 tests/webhookListener.js
View
37 bin/nariya.js
@@ -9,7 +9,7 @@ var ConfigurationManager = require('../lib/configurationManager');
var crypto = require('crypto');
var cjson = require('cjson');
var fs = require('fs');
-var rest = require('restler');
+var request = require('request');
var nariyaHome = path.resolve(process.env.HOME, '.nariya/');
var nariyaConfFile = path.resolve(nariyaHome, 'nariya.conf');
@@ -122,17 +122,26 @@ if(action == 'start') {
console.log('+ simulating github webhook call as'.bold.green);
console.log('\t' + uri);
- rest.post(uri, {
- data: {
- payload: '{"ref": "refs/heads/master"}'
+ var payload = getSamplePayload(repo.type, repo.branch);
+
+ request({
+ method: 'POST',
+ uri: uri,
+ headers: {'Content-Type': 'application/x-www-form-urlencoded'},
+ body: payload
+ }, function(error, response, data) {
+
+ console.log(response.statusCode);
+ if(!error && response.statusCode == 200) {
+ console.log('+ Project Deployment started'.green.bold);
+ } else {
+ console.error('+ Error Deploying Request'.bold.red);
+ console.error('\t' + JSON.stringify(error));
+ console.error('\t' + data);
}
- }).on('complete', function() {
- console.log('+ Project Deployment started'.green.bold);
- }).on('error', function(err) {
- console.error('+ Error Deploying Request'.bold.red);
- console.error('\t' + err.message);
});
+
} else {
console.log('This is not a valid nariya enabled project'.red.bold);
}
@@ -199,4 +208,14 @@ function startNariya() {
}
});
};
+}
+
+function getSamplePayload(repoType, branch) {
+
+ var payloads = {
+ github: 'payload=' + '{"ref": "refs/heads/' + branch + '"}',
+ bitbucket: 'payload=' + JSON.stringify({commits: [{branch: branch}]})
+ };
+
+ return payloads[repoType]
}
View
2 lib/webhookListener.js
@@ -11,7 +11,7 @@ function WebhookListener(configurationManager, repositories, deployer, notifiers
app.post('/deploy/:secret', function(req, res) {
- res.send();
+ res.send(' ');
var repoInfo = configurationManager.getRepositoryInfo(req.params.secret);
if(repoInfo) {
View
3 package.json
@@ -1,6 +1,6 @@
{
"name": "nariya",
- "version": "0.1.12",
+ "version": "0.1.13",
"directories": {
"lib": "./lib"
},
@@ -16,7 +16,6 @@
"nodemailer": ">= 0.2.2",
"cjson": ">= 0.0.5",
"request": ">= 2.1.1",
- "restler": ">= 0.2.1",
"colors": ">= 0.5.1"
},
"devDependencies": {
View
37 tests/webhookListener.js
@@ -1,7 +1,6 @@
var WebhookListener = require('webhookListener');
var nodemock = require('nodemock');
var request = require('request');
-var rest = require('restler');
var Notifiers = require('notifiers');
exports.testInvalidSecret = function(test) {
@@ -46,9 +45,7 @@ exports.testNoType = function(test) {
wl.listen(port, function() {
- rest.post('http://localhost:' + port + '/deploy/' + secret, {
-
- }).on('complete', function() {
+ request.post('http://localhost:' + port + '/deploy/' + secret, function(error, response, data) {
wl.close();
test.ok(configurationManager.assert());
@@ -80,10 +77,12 @@ exports.testAllowToDeployFalse = function(test) {
wl.listen(port, function() {
- rest.post('http://localhost:' + port + '/deploy/' + secret, {
- data: '{"ref": "aa/aa/master"}',
+ request.post({
+ uri: 'http://localhost:' + port + '/deploy/' + secret,
+ method: 'POST',
+ body: '{"ref": "aa/aa/master"}',
headers: {"Content-Type": "application/json"}
- }).on('complete', function() {
+ }, function(error, response, data) {
wl.close();
test.ok(configurationManager.assert());
@@ -115,10 +114,12 @@ exports.testGetUpdatesError = function(test) {
wl.listen(port, function() {
- rest.post('http://localhost:' + port + '/deploy/' + secret, {
- data: '{"ref": "aa/aa/master"}',
+ request.post({
+ uri: 'http://localhost:' + port + '/deploy/' + secret,
+ method: 'POST',
+ body: '{"ref": "aa/aa/master"}',
headers: {"Content-Type": "application/json"}
- }).on('complete', function() {
+ }, function(error, response, data) {
wl.close();
test.ok(configurationManager.assert());
@@ -153,10 +154,12 @@ exports.testGetDeployError = function(test) {
wl.listen(port, function() {
- rest.post('http://localhost:' + port + '/deploy/' + secret, {
- data: '{"ref": "aa/aa/master"}',
+ request.post({
+ uri: 'http://localhost:' + port + '/deploy/' + secret,
+ method: 'POST',
+ body: '{"ref": "aa/aa/master"}',
headers: {"Content-Type": "application/json"}
- }).on('complete', function() {
+ }, function(error, response, data) {
wl.close();
test.ok(configurationManager.assert());
@@ -190,10 +193,12 @@ exports.testGetDeployOK = function(test) {
wl.listen(port, function() {
- rest.post('http://localhost:' + port + '/deploy/' + secret, {
- data: '{"ref": "aa/aa/master"}',
+ request.post({
+ uri: 'http://localhost:' + port + '/deploy/' + secret,
+ method: 'POST',
+ body: '{"ref": "aa/aa/master"}',
headers: {"Content-Type": "application/json"}
- }).on('complete', function() {
+ }, function(error, response, data) {
wl.close();
test.ok(configurationManager.assert());

0 comments on commit a2b0d18

Please sign in to comment.
Something went wrong with that request. Please try again.