All files / lib/api view.js

100% Statements 72/72
100% Branches 6/6
100% Functions 5/5
100% Lines 72/72

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 721x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x
"use strict";
import _ from 'lodash';
import RssParser from 'rss-parser';
 
/**
 * Create a view with specified configuration.
 *
 * @param {String} name: Jenkins view name
 * @param {String} config: Jenkins view config.xml
 * @param {Function} cb: standard cb(err, result) callback
 */
function create(name, config, cb) {
  const opts = {
    body: config,
    contentType: 'application/xml',
  };
  this.remoteAccessApi.postCreateView(name, _.merge(opts, this.opts.headers), cb);
}
 
/**
 * Retrieve information about a view.
 *
 * @param {String} name: Jenkins view name
 * @param {Function} cb: standard cb(err, result) callback
 */
function read(name, cb) {
  this.remoteAccessApi.getView(name, cb);
}
 
/**
 * Update a view with specified configuration
 *
 * @param {String} name: Jenkins view name
 * @param {String} config: Jenkins view config.xml
 * @param {Function} cb: standard cb(err, result) callback
 */
function update(name, config, cb) {
  this.remoteAccessApi.postViewConfig(name, config, this.opts.headers, cb);
}
 
/**
 * Fetch a view configuration.
 *
 * @param {String} name: Jenkins view name
 * @param {Function} cb: standard cb(err, result) callback
 */
function fetchConfig(name, cb) {
  this.remoteAccessApi.getViewConfig(name, cb);
}
 
/**
 * Parse view feed.
 *
 * @param {String} name: Jenkins view name
 * @param {Function} cb: standard cb(err, result) callback
 */
function parseFeed(name, cb) {
  const url = this.url + '/view/' + name + '/rssAll';
  new RssParser().parseURL(url, cb);
}
 
const exports = {
  create: create,
  read: read,
  update: update,
  fetchConfig: fetchConfig,
  parseFeed: parseFeed
};
 
export {
  exports as default
};