All files / src/modules searchPackages.js

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

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                              2x   2x         2x        
import validateOptions from './validateOptions';
/**
 * Search for packages in a repository.
 * @module src/modules/searchPackages
 * @param {Object} superagent request object.
 * @param {Object} options - Search options.
 * @param {string} options.repo - The fully-qualified repository name, i.e., 'username/reponame'.
 * @param {string} options.filename - The query string to search for package filename.
 * @param {string} options.type - The type of package to search, supports: all, debs, gems, rpms, python, dscs, java.
 * @param {string} options.dist - Overrides options.type. The name of the distribution the package is intended for. (i.e., ubuntu, el/6)
 * @param {string} options.perPage - The number of packages to return from the results set, default is 30.
 * @return {Promise} The superagent promise object.
 */
export default (request, options) => {
 
  validateOptions(options, ['repo']);
 
  let payload = { 'q': options.filename || '',
                  'filter': options.type,
                  'dist': options.dist,
                  'perPage': options.perPage };
 
  return request
    .get([options.baseUrl + "repos", options.repo, "search.json"].join("/"))
    .query(payload);
}