use of org.jboss.pnc.dto.requests.BuildConfigWithSCMRequest in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method shouldCreateWithInternalUrlMatchingPattern.
@Test
@InSequence(62)
public void shouldCreateWithInternalUrlMatchingPattern() throws ClientException {
// given
BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
BuildConfiguration bc = client.getSpecific(configurationId);
BuildConfiguration newBC = BuildConfiguration.builder().name("othernameforbc").buildScript(bc.getBuildScript()).project(bc.getProject()).environment(bc.getEnvironment()).parameters(bc.getParameters()).buildType(bc.getBuildType()).build();
BuildConfigWithSCMRequest request = BuildConfigWithSCMRequest.builder().buildConfig(newBC).scmUrl("ssh://git@github.com:22/newUser/newRepo.git").build();
BuildConfigCreationResponse received = client.createWithSCM(request);
assertThat(received).isNotNull();
assertThat(received.getBuildConfig().getId()).isNotNull();
assertThat(client.getSpecific(received.getBuildConfig().getId())).hasFieldOrPropertyWithValue("name", "othernameforbc");
}
use of org.jboss.pnc.dto.requests.BuildConfigWithSCMRequest in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method createWithScm.
@Override
public BuildConfigCreationResponse createWithScm(BuildConfigWithSCMRequest request) {
ValidationBuilder.validateObject(request, WhenCreatingNew.class).validateNotEmptyArgument().validateAnnotations();
BuildConfiguration buildConfiguration = request.getBuildConfig();
validateBeforeSaving(buildConfiguration.toBuilder().scmRepository(FAKE_REPOSITORY).build());
Long buildConfigurationId = sequenceHandlerRepository.getNextID(org.jboss.pnc.model.BuildConfiguration.SEQUENCE_NAME);
MDCUtils.addProcessContext(buildConfigurationId.toString());
BuildConfiguration newBuildConfigurationWithId = buildConfiguration.toBuilder().id(buildConfigurationId.toString()).build();
RepositoryCreationResponse rcResponse = scmRepositoryProvider.createSCMRepository(request.getScmUrl(), request.getBuildConfig().getScmRevision(), request.getPreBuildSyncEnabled(), JobNotificationType.BUILD_CONFIG_CREATION, // consumer is deprecated with new stateless approach
MDCWrappers.wrap(event -> {
createBuildConfigurationWithRepository(event.getTaskId() == null ? null : event.getTaskId().toString(), event.getRepositoryId(), newBuildConfigurationWithId);
}), Optional.of(newBuildConfigurationWithId));
BuildConfigCreationResponse response;
if (rcResponse.getTaskId() == null) {
// scm is internal, not running a RepositoryCreationTask.
// onRCCreationSuccess already called with id = rcResponse.getRepository().getId()
org.jboss.pnc.model.BuildConfiguration buildConfigurationFromDB = repository.queryByPredicates(withName(newBuildConfigurationWithId.getName()), isNotArchived());
response = new BuildConfigCreationResponse(mapper.toDTO(buildConfigurationFromDB));
} else {
response = new BuildConfigCreationResponse(rcResponse.getTaskId().toString());
}
MDCUtils.removeProcessContext();
return response;
}
use of org.jboss.pnc.dto.requests.BuildConfigWithSCMRequest in project pnc by project-ncl.
the class DeserializerTest method testDTOAsRefDeserialization.
@Test
public void testDTOAsRefDeserialization() throws IOException {
String json = "{" + " \"scmUrl\":\"https://github.com/matedo1/empty_19082666\"," + " \"preBuildSyncEnabled\":true," + " \"buildConfig\":{" + " \"name\":\"mtest190826\"," + " \"environment\":{" + " \"id\":8," + " \"name\":\"OpenJDK 1.8.0; Mvn 3.5.2\"," + " \"description\":\"OpenJDK 1.8.0; Mvn 3.5.2\"," + " \"systemImageRepositoryUrl\":\"docker-registry-default.cloud.registry.upshift.redhat.com\"," + " \"systemImageId\":\"newcastle/builder-rhel-7-j8-mvn3.5.2:latest\"," + " \"attributes\":{" + " \"JDK\":\"1.8.0\"," + " \"MAVEN\":\"3.5.2\"," + " \"OS\":\"Linux\"" + " }," + " \"systemImageType\":\"DOCKER_IMAGE\"," + " \"deprecated\":false" + " }," + " \"buildType\":\"MVN\"," + " \"buildScript\":\"mvn clean deploy\"," + " \"parameters\":{ }," + " \"dependencies\":{}," + " \"scmRevision\":\"master\"," + " \"project\":{" + " \"id\":122," + " \"name\":\"mtest180719\"," + " \"description\":null," + " \"issueTrackerUrl\":null," + " \"projectUrl\":null," + " \"buildConfigs\":{" + " \"134\": {" + " \"id\":134," + " \"name\":\"mtest1907252\"," + " \"description\":null," + " \"buildScript\":\"mvn clean deploy\"," + " \"scmRevision\":\"master\"," + " \"creationTime\":\"2019-07-25T09:32:44.206Z\"," + " \"modificationTime\":\"2019-08-14T11:37:51.355Z\"," + " \"archived\":false," + " \"buildType\":\"MVN\"" + " }" + " }" + " }," + " \"groupConfigs\":{}" + " }" + "}";
ObjectMapper mapper = provider.getContext(null);
BuildConfigWithSCMRequest obj = mapper.readValue(json, BuildConfigWithSCMRequest.class);
}
use of org.jboss.pnc.dto.requests.BuildConfigWithSCMRequest in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method shouldNotCreateWithInternalUrlNotMatchingPattern.
@Test
public void shouldNotCreateWithInternalUrlNotMatchingPattern() throws ClientException {
BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
BuildConfiguration bc = client.getSpecific(configurationId);
BuildConfiguration newBC = BuildConfiguration.builder().name("othername").buildScript(bc.getBuildScript()).project(bc.getProject()).environment(bc.getEnvironment()).parameters(bc.getParameters()).buildType(bc.getBuildType()).build();
BuildConfigWithSCMRequest request = BuildConfigWithSCMRequest.builder().buildConfig(newBC).scmUrl("ssh://git@github.com:22/gerrit/newRepo.git").build();
assertThatThrownBy(() -> client.createWithSCM(request)).hasCauseInstanceOf(BadRequestException.class);
BuildConfigWithSCMRequest request2 = BuildConfigWithSCMRequest.builder().buildConfig(newBC).scmUrl("ssh://git@github.com:22/foo/newRepo").build();
assertThatThrownBy(() -> client.createWithSCM(request2)).hasCauseInstanceOf(BadRequestException.class);
}
Aggregations