All files / src/modules showPackage.js

100% Statements 6/6
100% Branches 2/2
100% Functions 1/1
100% Lines 6/6

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                                    5x   2x   2x 1x   1x     2x            
import validateOptions from './validateOptions';
/**
 * Get package information for Debian and RPM packages.
 * @module src/modules/showPackage
 * @param {Object} superagent request object.
 * @param {Object} options - Repository options.
 * @param {string} options.repo - The fully-qualified repository name, i.e., 'username/reponame'.
 * @param {string} options.type - The type of package, supported: deb, rpm.
 * @param {string} options.distro - The distribution name, i.e., 'ubuntu'.
 * @param {string} options.distroVersion - The distribution version, i.e., 'precise'.
 * @param {string} options.packageName - The name of the package.
 * @param {string} options.arch - The architecture of the package. NOTE: debs use amd64 while rpms use x86_64 for arch.
 * @param {string} options.version - The version of the package without epoch.
 * @param {string} options.release - <Optional> The release, if the package contains one.
 * @return {Promise} The superagent promise object.
 */
export default (request, options) => {
 
  validateOptions(options, ['repo', 'type', 'distro', 'distroVersion', 'packageName', 'arch', 'version']);
 
  let [version, release] = [options.version, options.release];
 
  if(options.release) {
    release = options.release + ".json";
  } else {
    version = options.version + ".json";
  }
 
  return request.get([options.baseUrl + "repos",
                      options.repo, "package",
                      options.type, options.distro,
                      options.distroVersion, options.packageName,
                      options.arch, version, release].join("/").replace(/\/+$/, ""));
}