use of org.jboss.pnc.dto.SCMRepository 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.SCMRepository in project bacon by project-ncl.
the class PncEntitiesImporter method generatePncBuildConfig.
/**
* @param buildConfig PiG buildconfig to generate
* @param existing if present, we'll use it as the buildconfig to modify if null: we'll use a fresh buildconfig
* object
*
* @return BuildConfiguration generated
*/
private BuildConfiguration generatePncBuildConfig(BuildConfig buildConfig, BuildConfiguration existing) {
ProjectRef project = getOrGenerateProject(buildConfig.getProject());
SCMRepository repository = getOrGenerateRepository(buildConfig);
Environment environment = Environment.builder().id(buildConfig.getEnvironmentId()).build();
BuildConfiguration.Builder builder = BuildConfiguration.builder();
if (existing != null) {
builder = existing.toBuilder();
}
return builder.productVersion(version).parameters(buildConfig.getGenericParameters(null, false)).name(buildConfig.getName()).project(project).environment(environment).scmRepository(repository).scmRevision(buildConfig.getScmRevision()).buildScript(buildConfig.getBuildScript()).buildType(BuildType.valueOf(buildConfig.getBuildType())).brewPullActive(buildConfig.getBrewPullActive()).build();
}
use of org.jboss.pnc.dto.SCMRepository in project bacon by project-ncl.
the class PigTest method shouldCreateProduct.
@Test
@Order(1)
void shouldCreateProduct() throws IOException {
final Path configFile = CONFIG_LOCATION;
replaceSuffixInConfigFile(configFile.resolve("build-config.yaml"));
final Product product = Product.builder().id(UNIVERSAL_ID).name(PRODUCT_NAME).abbreviation(PRODUCT_ABBREVIATION).build();
final ProductVersion productVersion = ProductVersion.builder().id(UNIVERSAL_ID).version(VERSION).product(product).build();
final ProductMilestone productMilestone = ProductMilestone.builder().id(UNIVERSAL_ID).productVersion(productVersion).version(MILESTONE).build();
final ProductVersion productVersionWithCurrentMilestone = productVersion.toBuilder().currentProductMilestone(productMilestone).build();
final GroupConfiguration groupConfig = GroupConfiguration.builder().id(UNIVERSAL_ID).name(GROUP_NAME).productVersion(productVersionWithCurrentMilestone).build();
final Project project = Project.builder().id(UNIVERSAL_ID).name(PROJECT_NAME).build();
final SCMRepository scmRepository = SCMRepository.builder().id(UNIVERSAL_ID).internalUrl(SCM_URL).preBuildSyncEnabled(true).build();
final Environment environment = Environment.builder().id(UNIVERSAL_ID).deprecated(false).build();
final BuildConfiguration buildConfig = BuildConfiguration.builder().id(UNIVERSAL_ID).name(BC_NAME).buildScript(BUILD_SCRIPT).scmRevision(SCM_REVISION).creationTime(Instant.now()).modificationTime(Instant.now()).scmRepository(scmRepository).environment(environment).project(project).productVersion(productVersionWithCurrentMilestone).build();
final GroupConfiguration groupConfigWithBuildConfig = groupConfig.toBuilder().buildConfigs(Collections.singletonMap(UNIVERSAL_ID, buildConfig)).build();
wmock.list(PRODUCT, new Page<Product>());
wmock.creation(PRODUCT, product);
wmock.list(PRODUCT_VERSIONS.apply(UNIVERSAL_ID), new Page<ProductVersion>());
wmock.creation(PRODUCT_VERSION, productVersion);
wmock.list(PRODUCT_VERSION_MILESTONES.apply(UNIVERSAL_ID), new Page<ProductMilestone>());
wmock.creation(PRODUCT_MILESTONE, productMilestone);
wmock.update(PRODUCT_VERSION, productVersion, productVersionWithCurrentMilestone);
wmock.list(GROUP_CONFIG, new Page<GroupConfiguration>());
wmock.creation(GROUP_CONFIG, groupConfig);
wmock.list(GROUP_CONFIG_BUILD_CONFIGS.apply(UNIVERSAL_ID), new Page<BuildConfiguration>());
wmock.list(BUILD_CONFIG, new Page<BuildConfiguration>());
wmock.list(PROJECT, new Page<Project>());
wmock.creation(PROJECT, project);
wmock.list(SCM_REPOSITORY, new Page<SCMRepository>());
wmock.creation(SCM_REPOSITORY_CREATE, RepositoryCreationResponse.builder().repository(scmRepository).build());
wmock.get(ENVIRONMENT, environment);
wmock.creation(BUILD_CONFIG, buildConfig);
wmock.list(BUILD_CONFIG_DEPENDENCIES.apply(UNIVERSAL_ID), new Page<BuildConfiguration>());
wmock.get(BUILD_CONFIG, buildConfig);
wmock.creation(BUILD_CONFIG, buildConfig);
wmock.scenario("add BC to GC").getEntity(GROUP_CONFIG, groupConfig).when().post(GROUP_CONFIG_BUILD_CONFIGS.apply(UNIVERSAL_ID)).then().getEntity(GROUP_CONFIG, groupConfigWithBuildConfig);
ExecutionResult output = executeAndGetResult("pig", "configure", configFile.toString());
assertThat(output.getOutput()).contains("name: \"Product Foobar " + SUFFIX + "\"");
}
use of org.jboss.pnc.dto.SCMRepository in project pnc by project-ncl.
the class SecondLevelCacheStoreTest method prepareData.
/**
* At first we need to create testing data and commit it.
*/
@Test
@InSequence(-2)
public void prepareData() throws Exception {
EnvironmentClient client = new EnvironmentClient(RestClientConfiguration.asAnonymous());
environmentId = client.getAll().iterator().next().getId();
SCMRepositoryClient scmrc = new SCMRepositoryClient(RestClientConfiguration.asAnonymous());
final Iterator<SCMRepository> scmrIt = scmrc.getAll(null, null).iterator();
repositoryConfigurationBCId = scmrIt.next().getId();
repositoryConfigurationDepBCId = scmrIt.next().getId();
Project projectBC = createProjectAndValidateResults("https://github.com/project-ncl/dependency-analysis", null, "Dependency Analysis New", "Dependency Analysis - Analise project dependencies.");
Project projectDepBC = createProjectAndValidateResults("https://github.com/project-ncl/pnc", null, "Project Newcastle Demo Project 1 New", "Example Project for Newcastle Demo");
projectBCId = projectBC.getId();
projectDepBCId = projectDepBC.getId();
BuildConfiguration dependencyBC = createBuildConfigurationAndValidateResults(projectDepBCId, environmentId, repositoryConfigurationDepBCId, "pnc-1.0.0.DR1-new", UUID.randomUUID().toString());
BuildConfiguration buildConfiguration = createBuildConfigurationAndValidateResults(projectBCId, environmentId, repositoryConfigurationBCId, "dependency-analysis-master-new", UUID.randomUUID().toString());
dependencyBCId = dependencyBC.getId();
buildConfigurationId = buildConfiguration.getId();
}
use of org.jboss.pnc.dto.SCMRepository in project pnc by project-ncl.
the class SCMRepositoryEndpointTest method testGetBuildConfigurationForARepository.
@Test
public void testGetBuildConfigurationForARepository() throws ClientException {
BuildConfigurationClient buildConfigurationClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
SCMRepository scmRepository = repositoryClient.getAll(null, null).iterator().next();
Iterator<BuildConfiguration> allConfigsIterator = buildConfigurationClient.getAll().iterator();
BuildConfiguration buildConfiguration1 = allConfigsIterator.next().toBuilder().scmRepository(scmRepository).build();
BuildConfiguration buildConfiguration2 = allConfigsIterator.next().toBuilder().scmRepository(scmRepository).build();
buildConfigurationClient.update(buildConfiguration1.getId(), buildConfiguration1);
buildConfigurationClient.update(buildConfiguration2.getId(), buildConfiguration2);
RemoteCollection<BuildConfiguration> buildConfigs = repositoryClient.getBuildConfigs(scmRepository.getId());
assertThat(buildConfigs).usingElementComparatorIgnoringFields("modificationTime", "creationUser", "modificationUser").contains(buildConfiguration1, buildConfiguration2).allSatisfy((bc -> scmRepository.equals(bc.getScmRepository())));
}
Aggregations