{"size": 1699, "ext": "js", "max_stars_repo_path": "scripts/type/collection/_CheckoutRepositories.js", "max_stars_repo_name": "trujs/TruJS.compile", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "scripts/type/collection/_CheckoutRepositories.js", "max_issues_repo_name": "trujs/TruJS.compile", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scripts/type/collection/_CheckoutRepositories.js", "max_forks_repo_name": "trujs/TruJS.compile", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.9852941176, "max_line_length": 79, "alphanum_fraction": 0.5167745733}
/**
*
* @factory
*/
function _CheckoutRepositories(promise, type_collection_repository) {
    var SEP_PATT = /[/\\]/;
    
    /**
    * Loops through the entry's repos property and checks out the branch's that
    * are required for the
    * @function
    */
    function checkoutRepositories(resolve, reject, base, entry) {
        var procs = []
        , repos = entry.repos || []
        , basePath = getWorkspacePath(base)
        ;

        //create all of the repo processes
        repos.forEach(function forEachRepo(repoObj) {
            var type = repoObj.type || "git"
            , dir = repoObj.isProject && "projects" || "repos"
            , path = basePath + "/" + dir
            , repo = type_collection_repository[type]
            ;
            procs.push(repo(path, repoObj));
        });

        //run all of the repo processes
        promise.all(procs)
        .then(function () {
            resolve();
        })
        .catch(function (ex) {
            reject(ex);
        });
    }
    /**
    * Extracts the workspace path from the base
    * @function
    */
    function getWorkspacePath(base) {
        var segs = base.split(SEP_PATT)
        , indx = segs.indexOf("repos");

        if (indx === -1) {
            indx = segs.indexOf("projects");
        }

        return segs.slice(0, indx).join("/");
    }

    /**
    * @worker
    */
    return function CheckoutRepositories(base, entry) {

        if (isArray(entry.repos)) {
            return  new Promise(function (resolve, reject) {
                checkoutRepositories(resolve, reject, base, entry);
            });
        }
        else {
            return promise.resolve();
        }

    };
}