Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Fix synchronization of the existing projects (#334)
Browse files Browse the repository at this point in the history
* CHE-13621 fix synchronization of the existing projects

Signed-off-by: Oleksii Orel <[email protected]>

* fix project.clonePath only defined if different from project.name

Signed-off-by: Sun Tan <[email protected]>
  • Loading branch information
olexii4 committed Jul 10, 2019
1 parent ab3132c commit b80dd8a
Show file tree
Hide file tree
Showing 2 changed files with 245 additions and 278 deletions.
64 changes: 33 additions & 31 deletions plugins/factory-plugin/src/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,43 @@ export function updateOrCreateGitProjectInDevfile(
projectGitLocation: string,
projectGitRemoteBranch: string
): cheApi.workspace.devfile.Project[] {

if (!projects) {
projects = [];
}

for (const project of projects) {
const currentProjectPath = project.clonePath ? project.clonePath : project.name;
if (currentProjectPath === projectPath) {
project.source.type = 'git';
project.source.location = projectGitLocation;
project.source.branch = projectGitRemoteBranch;

return projects;
const filteredProject = projects.filter(project => (project.clonePath ? project.clonePath : project.name) === projectPath);
if (filteredProject.length === 0) {
const projectName = projectPath.split('/').pop();
if (projectPath === projectName) {
projectPath = undefined;
}
// create a new one
projects.push({
name: projectName ? projectName : 'new-project',
source: {
location: projectGitLocation,
type: 'git',
branch: projectGitRemoteBranch
},
clonePath: projectPath
});
return projects;
}

// project not found in the list of existed, create a new one
const projectPathSegments = projectPath.split('/');
const isCustomPath = projectPathSegments.filter(segment => segment !== '').length !== 1;
const projectName = projectPathSegments.pop();

const newProject: cheApi.workspace.devfile.Project = {
'name': projectName ? projectName : 'new-project',
'source': {
'type': 'git',
'location': projectGitLocation,
'branch': projectGitRemoteBranch
filteredProject.forEach(project => {
if (!project.source) {
project.source = {
location: projectGitLocation,
type: 'git',
branch: projectGitRemoteBranch
};
}
};

if (isCustomPath) {
newProject.clonePath = projectPath;
}

projects.push(newProject);
project.source.location = projectGitLocation;
project.source.branch = projectGitRemoteBranch;
delete project.source.startPoint;
delete project.source.tag;
delete project.source.commitId;
});

return projects;
}
Expand All @@ -77,9 +79,8 @@ export function deleteProjectFromDevfile(
projects: cheApi.workspace.devfile.Project[],
projectPath: string
): cheApi.workspace.devfile.Project[] {

if (!projects || projects.length === 0) {
return [];
if (!projects) {
projects = [];
}

for (let i = 0; i < projects.length; i++) {
Expand Down Expand Up @@ -153,7 +154,8 @@ export function deleteProjectFromWorkspaceConfig(
): cheApi.workspace.ProjectConfig[] {
for (let i = 0; i < projects.length; i++) {
const project = projects[i];
if (project.path === projectPath) {
const currentProjectPath = project.path ? project.path : project.name;
if (currentProjectPath === projectPath) {
projects.splice(i, 1);
break;
}
Expand Down
Loading

0 comments on commit b80dd8a

Please sign in to comment.