var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import repoOperations from "./vcses/operations.js";
import { getLocation } from "./helpers.js";
import repoHelpers from "./vcses/helpers.js";
const getBranchNames = (repoConfig) => {
if (repoConfig._type === 'darcs') {
return Object.keys(repoConfig.branches);
}
else if (repoConfig._type === 'git') {
return repoConfig.branchesToPull;
}
};
let cachedRepos = null;
const repos = (reposConfig) => __awaiter(void 0, void 0, void 0, function* () {
if (cachedRepos !== null) {
return cachedRepos;
}
const repoNames = Object.keys(reposConfig.repos);
const reposTuples = yield Promise.all(repoNames.map((repoName) => __awaiter(void 0, void 0, void 0, function* () {
const vcs = reposConfig.repos[repoName]._type;
const branchNames = getBranchNames(reposConfig.repos[repoName]);
const branchTuples = yield Promise.all(branchNames.map((branchName) => __awaiter(void 0, void 0, void 0, function* () {
const repoLocation = getLocation(reposConfig, branchName, repoName);
const files = yield repoOperations[vcs].getFileList(repoName, branchName, repoLocation);
const patches = yield repoOperations[vcs].getBranchInfo(repoName, branchName, repoLocation);
return [branchName, {
files,
patches,
}];
})));
const branchesObject = {};
for (let branchTuple of branchTuples) {
branchesObject[branchTuple[0]] = branchTuple[1];
}
return [repoName, branchesObject];
})));
const reposObject = {};
for (let repoTuple of reposTuples) {
const repoName = repoTuple[0];
const repoType = reposConfig.repos[repoName]._type;
reposObject[repoName] = {
branches: repoTuple[1],
cloneUrl: repoHelpers[repoType].cloneUrl(reposConfig.baseUrl + (reposConfig.path || ""), repoName)
};
}
cachedRepos = reposObject;
return reposObject;
});
export default repos;