in src/app/teamcity/teamcity-convert.js [132:180]
export function asFlattenBuildTypeTree(rootProject, projectResponse, buildTypeResponse) {
const projects = filterNotArchivedAndNotRoot(projectResponse.project || []);
const projectMap = associateBy(projects, project => project.id);
const roots = asProjectTree(projects, projectMap);
const buildTypes = buildTypeResponse.buildType;
buildTypes.forEach(buildType => {
const parent = projectMap[buildType.projectId];
if (parent) {
const childBuildTypes = parent.buildTypes || [];
childBuildTypes.push(buildType);
parent.buildTypes = childBuildTypes;
buildType.parent = parent;
buildType.path = `${parent.path} :: ${buildType.name}`;
} else if (buildType.projectId === rootProject.id) {
roots.push(buildType);
buildType.path = buildType.name;
}
buildType.isBuildType = true;
});
const flattenProjectsAndBuildTypes = [];
let currentLevel = 0;
/**
* Flattens project tree
*
* @param {TeamcityProject} node - project to flatten
* @returns {undefined}
*/
function flattenTree(node) {
node.level = currentLevel;
flattenProjectsAndBuildTypes.push(node);
currentLevel++;
if (node.children) {
node.children.forEach(flattenTree);
}
if (node.buildTypes) {
node.buildTypes.forEach(flattenTree);
}
currentLevel--;
}
roots.forEach(flattenTree);
return flattenProjectsAndBuildTypes;
}