Support `refspec` in the devfile to specify what should be checked out
after a clone. Signed-off-by: Lukas Krejci <lkrejci@redhat.com>7.20.x
parent
3af6ab1151
commit
4e3e7c3cb5
|
|
@ -16,6 +16,12 @@ import java.util.Map;
|
|||
/** @author gazarenkov */
|
||||
public interface SourceStorage {
|
||||
|
||||
/**
|
||||
* The key with this name in the parameters designates the exact revision the source corresponds
|
||||
* to. This can be a branch, tag, commit id or anything the particular VCS type understands.
|
||||
*/
|
||||
String REFSPEC_PARAMETER_NAME = "refspec";
|
||||
|
||||
String getType();
|
||||
|
||||
String getLocation();
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
*/
|
||||
package org.eclipse.che.api.devfile.server.convert;
|
||||
|
||||
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.REFSPEC_PARAMETER_NAME;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.eclipse.che.api.devfile.model.Project;
|
||||
import org.eclipse.che.api.devfile.model.Source;
|
||||
import org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl;
|
||||
|
|
@ -31,10 +34,13 @@ public class ProjectConverter {
|
|||
* @return created devfile project based on the specified workspace project
|
||||
*/
|
||||
public Project toDevfileProject(ProjectConfigImpl projectConfig) {
|
||||
String refspec = projectConfig.getSource().getParameters().get(REFSPEC_PARAMETER_NAME);
|
||||
Source source =
|
||||
new Source()
|
||||
.withType(projectConfig.getSource().getType())
|
||||
.withLocation(projectConfig.getSource().getLocation());
|
||||
.withLocation(projectConfig.getSource().getLocation())
|
||||
.withRefspec(refspec);
|
||||
|
||||
return new Project().withName(projectConfig.getName()).withSource(source);
|
||||
}
|
||||
|
||||
|
|
@ -49,10 +55,21 @@ public class ProjectConverter {
|
|||
projectConfig.setName(devProject.getName());
|
||||
projectConfig.setPath("/" + projectConfig.getName());
|
||||
|
||||
SourceStorageImpl sourceStorage = new SourceStorageImpl();
|
||||
sourceStorage.setType(devProject.getSource().getType());
|
||||
sourceStorage.setLocation(devProject.getSource().getLocation());
|
||||
projectConfig.setSource(sourceStorage);
|
||||
projectConfig.setSource(toSourceStorage(devProject.getSource()));
|
||||
return projectConfig;
|
||||
}
|
||||
|
||||
private SourceStorageImpl toSourceStorage(Source source) {
|
||||
SourceStorageImpl sourceStorage = new SourceStorageImpl();
|
||||
|
||||
sourceStorage.setType(source.getType());
|
||||
sourceStorage.setLocation(source.getLocation());
|
||||
String refspec = source.getRefspec();
|
||||
|
||||
if (!Strings.isNullOrEmpty(refspec)) {
|
||||
sourceStorage.getParameters().put(REFSPEC_PARAMETER_NAME, refspec);
|
||||
}
|
||||
|
||||
return sourceStorage;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,11 @@
|
|||
"examples": [
|
||||
"git@github.com:spring-projects/spring-petclinic.git"
|
||||
]
|
||||
},
|
||||
"refspec": {
|
||||
"type": "string",
|
||||
"description": "The name of the refspec to check out after the clone. This can be a branch, tag, commit id or anything the particular source type understands.",
|
||||
"examples": [ "master", "feature-42", "304df5a" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@
|
|||
*/
|
||||
package org.eclipse.che.api.devfile.server.convert;
|
||||
|
||||
import static org.eclipse.che.api.core.model.workspace.config.SourceStorage.REFSPEC_PARAMETER_NAME;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.eclipse.che.api.devfile.model.Project;
|
||||
import org.eclipse.che.api.devfile.model.Source;
|
||||
import org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl;
|
||||
|
|
@ -36,7 +38,10 @@ public class ProjectConverterTest {
|
|||
new Project()
|
||||
.withName("myProject")
|
||||
.withSource(
|
||||
new Source().withLocation("https://github.com/eclipse/che.git").withType("git"));
|
||||
new Source()
|
||||
.withLocation("https://github.com/eclipse/che.git")
|
||||
.withType("git")
|
||||
.withRefspec("master"));
|
||||
|
||||
ProjectConfigImpl workspaceProject = projectConverter.toWorkspaceProject(devfileProject);
|
||||
|
||||
|
|
@ -45,23 +50,26 @@ public class ProjectConverterTest {
|
|||
SourceStorageImpl source = workspaceProject.getSource();
|
||||
assertEquals(source.getType(), "git");
|
||||
assertEquals(source.getLocation(), "https://github.com/eclipse/che.git");
|
||||
assertEquals(source.getParameters().get(REFSPEC_PARAMETER_NAME), "master");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertingProjectConfigToDevfileProject() {
|
||||
ProjectConfigImpl workpsaceProject = new ProjectConfigImpl();
|
||||
workpsaceProject.setName("myProject");
|
||||
workpsaceProject.setPath("/ignored");
|
||||
ProjectConfigImpl workspaceProject = new ProjectConfigImpl();
|
||||
workspaceProject.setName("myProject");
|
||||
workspaceProject.setPath("/ignored");
|
||||
SourceStorageImpl sourceStorage = new SourceStorageImpl();
|
||||
sourceStorage.setType("git");
|
||||
sourceStorage.setLocation("https://github.com/eclipse/che.git");
|
||||
workpsaceProject.setSource(sourceStorage);
|
||||
sourceStorage.setParameters(ImmutableMap.of(REFSPEC_PARAMETER_NAME, "master"));
|
||||
workspaceProject.setSource(sourceStorage);
|
||||
|
||||
Project devfileProject = projectConverter.toDevfileProject(workpsaceProject);
|
||||
Project devfileProject = projectConverter.toDevfileProject(workspaceProject);
|
||||
|
||||
assertEquals(devfileProject.getName(), "myProject");
|
||||
Source source = devfileProject.getSource();
|
||||
assertEquals(source.getType(), "git");
|
||||
assertEquals(source.getLocation(), "https://github.com/eclipse/che.git");
|
||||
assertEquals(source.getRefspec(), "master");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue