Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Minor style changes, add changelog note, more unit tests coverage.

  • Loading branch information...
commit fca0ac72fb9dc08dfc84b02b0be5ee1090432d9a 1 parent 298a6f9
Cliffano Subagio authored
1  CHANGELOG.md
Source Rendered
@@ -2,6 +2,7 @@
2 2 * Move proxy environment variable handling to bag.http.request and bag.http.proxy
3 3 * Add feed command
4 4 * Add jenkins#monitor and ninja command
  5 +* Add jenkins#consoleStream (Whyme Lyu)
5 6
6 7 ### 0.1.1
7 8 * Move status colouring to cli so that when lib/jenkins is used programatically then it gets plain uncoloured text
10 lib/console_stream.js
... ... @@ -1,10 +0,0 @@
1   -var inherits = require('util').inherits,
2   - Stream = require('stream').Stream;
3   -
4   -function ConsoleStream() {}
5   -inherits(ConsoleStream, Stream);
6   -
7   -ConsoleStream.prototype.readable = true;
8   -ConsoleStream.prototype.writable = false;
9   -
10   -module.exports = ConsoleStream;
15 lib/consolestream.js
... ... @@ -0,0 +1,15 @@
  1 +var stream = require('stream'),
  2 + util = require('util');
  3 +
  4 +/**
  5 + * class ConsoleStream
  6 + * Used for streaming Jenkins console output.
  7 + */
  8 +function ConsoleStream() {}
  9 +
  10 +util.inherits(ConsoleStream, stream.Stream);
  11 +
  12 +ConsoleStream.prototype.readable = true;
  13 +ConsoleStream.prototype.writable = false;
  14 +
  15 +module.exports = ConsoleStream;
20 lib/jenkins.js
@@ -2,12 +2,12 @@
2 2 var _ = require('underscore'),
3 3 async = require('async'),
4 4 bag = require('bagofholding'),
  5 + ConsoleStream = require('./consolestream'),
5 6 cron = require('cron'),
6 7 dgram = require('dgram'),
7 8 feedparser = require('feedparser'),
8 9 request = require('request'),
9   - xml2js = require('xml2js'),
10   - ConsoleStream = require('./console_stream');
  10 + xml2js = require('xml2js');
11 11
12 12 /**
13 13 * class Jenkins
@@ -82,16 +82,12 @@ Jenkins.prototype.build = function (jobName, params, cb) {
82 82 * @param {String} jobName: Jenkins job name
83 83 * @param {Object} opts: optional interval in milliseconds
84 84 * @param {Function} cb: standard cb(err, result) callback
85   - * @return {ConsoleStream} Returns readable stream
  85 + * @return {ConsoleStream} readable console output stream
86 86 */
87 87 Jenkins.prototype.consoleStream = function(jobName, opts, cb) {
88   - if (!cb) {
89   - if (typeof opts === 'function') {
90   - cb = opts;
91   - opts = undefined;
92   - } else {
93   - cb = function(){};
94   - }
  88 + if (!cb && typeof opts === 'function') {
  89 + cb = opts;
  90 + opts = undefined;
95 91 }
96 92
97 93 const INTERVAL = 1000;
@@ -145,7 +141,7 @@ Jenkins.prototype.consoleStream = function(jobName, opts, cb) {
145 141 this.opts.handlers[200] = _success;
146 142 this.opts.handlers[404] = _notFound;
147 143
148   - process.nextTick(function() {
  144 + process.nextTick(function () {
149 145 bag.http.request('get', url, self.opts, cb);
150 146 });
151 147
@@ -161,7 +157,7 @@ Jenkins.prototype.consoleStream = function(jobName, opts, cb) {
161 157 */
162 158 Jenkins.prototype.console = function (jobName, opts, cb) {
163 159 var stream = this.consoleStream(jobName, opts, cb);
164   - stream.pipe(process.stdout, {end: false});
  160 + stream.pipe(process.stdout, { end: false });
165 161 };
166 162
167 163 /**
10 test/consolestream.js
... ... @@ -0,0 +1,10 @@
  1 +var buster = require('buster'),
  2 + ConsoleStream = require('../lib/consolestream');
  3 +
  4 +buster.testCase('consolestream - consolestream', {
  5 + 'should be readable but not writable': function () {
  6 + var consoleStream = new ConsoleStream();
  7 + assert.isTrue(consoleStream.readable);
  8 + assert.isFalse(consoleStream.writable);
  9 + }
  10 +});
18 test/jenkins.js
@@ -265,6 +265,24 @@ buster.testCase('jenkins - consoleStream', {
265 265 }
266 266 });
267 267
  268 +buster.testCase('jenkins - console', {
  269 + 'should pipe console stream to standard output': function (done) {
  270 + var jenkins = new Jenkins('http://localhost:8080');
  271 + jenkins.consoleStream = function (jobName, opts, cb) {
  272 + assert.equals(jobName, 'somejob');
  273 + assert.equals(opts.interval, 10000);
  274 + return {
  275 + pipe: function (dest, opts) {
  276 + assert.equals(dest, process.stdout);
  277 + assert.isFalse(opts.end);
  278 + done();
  279 + }
  280 + };
  281 + };
  282 + jenkins.console('somejob', { interval: 10000 });
  283 + }
  284 +});
  285 +
268 286 buster.testCase('jenkins - stop', {
269 287 'should pass error not found when job does not exist': function (done) {
270 288 var mockRequest = function (method, url, opts, cb) {

0 comments on commit fca0ac7

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