Search in sources :

Example 1 with GitHubEngineConfiguration

use of net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration in project ontrack by nemerosa.

the class GitHubEngineConfigurationMigrationAction method migrateConfigurations.

private Map<String, OldConfiguration> migrateConfigurations(Connection connection) throws Exception {
    // Index of configurations
    Map<String, OldConfiguration> oldConfigurations = new HashMap<>();
    // For all GitHub configurations
    try (PreparedStatement ps = connection.prepareStatement("SELECT * FROM CONFIGURATIONS WHERE TYPE = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) {
        ps.setString(1, "net.nemerosa.ontrack.extension.github.model.GitHubConfiguration");
        try (ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                String name = rs.getString("NAME");
                logger.info("Migrating GitHub configuration: {}", name);
                // Configuration as JSON
                String json = rs.getString("CONTENT");
                // Parses the configuration
                OldConfiguration oldConfiguration = objectMapper.readValue(json, OldConfiguration.class);
                // New configuration
                GitHubEngineConfiguration newConfiguration = new GitHubEngineConfiguration(oldConfiguration.getName(), GitHubEngineConfiguration.GITHUB_COM, oldConfiguration.getUser(), oldConfiguration.getPassword(), oldConfiguration.getOauth2Token());
                // Updates the configuration
                rs.updateString("TYPE", GitHubEngineConfiguration.class.getName());
                rs.updateString("CONTENT", objectMapper.writeValueAsString(newConfiguration));
                rs.updateRow();
                // Indexation
                oldConfigurations.put(oldConfiguration.getName(), oldConfiguration);
            }
        }
    }
    // OK
    return oldConfigurations;
}
Also used : HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) GitHubEngineConfiguration(net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration)

Example 2 with GitHubEngineConfiguration

use of net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration in project ontrack by nemerosa.

the class GitHubIssueServiceExtensionTest method init.

@Before
public void init() {
    configurationService = mock(GitHubConfigurationService.class);
    OntrackGitHubClientFactory gitHubClientFactory = mock(OntrackGitHubClientFactory.class);
    IssueExportServiceFactory issueExportServiceFactory = mock(IssueExportServiceFactory.class);
    extension = new GitHubIssueServiceExtension(new GitHubExtensionFeature(new GitExtensionFeature(new SCMExtensionFeature())), configurationService, gitHubClientFactory, issueExportServiceFactory);
    GitHubEngineConfiguration engineConfiguration = new GitHubEngineConfiguration("test", "url", "", "", "");
    configuration = new GitHubIssueServiceConfiguration(engineConfiguration, "nemerosa/ontrack");
}
Also used : IssueExportServiceFactory(net.nemerosa.ontrack.extension.issues.export.IssueExportServiceFactory) GitHubConfigurationService(net.nemerosa.ontrack.extension.github.service.GitHubConfigurationService) SCMExtensionFeature(net.nemerosa.ontrack.extension.scm.SCMExtensionFeature) GitHubEngineConfiguration(net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration) GitHubIssueServiceConfiguration(net.nemerosa.ontrack.extension.github.service.GitHubIssueServiceConfiguration) GitExtensionFeature(net.nemerosa.ontrack.extension.git.GitExtensionFeature) OntrackGitHubClientFactory(net.nemerosa.ontrack.extension.github.client.OntrackGitHubClientFactory) Before(org.junit.Before)

Example 3 with GitHubEngineConfiguration

use of net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration in project ontrack by nemerosa.

the class GitHubIssueServiceExtensionTest method issueServiceIdentifierContainsBothConfigurationAndRepository.

@Test
public void issueServiceIdentifierContainsBothConfigurationAndRepository() {
    when(configurationService.getConfiguration("Test")).thenReturn(new GitHubEngineConfiguration("Test", null, null, null, null));
    IssueServiceConfiguration configuration = extension.getConfigurationByName("Test:nemerosa/ontrack");
    assertEquals("github", configuration.getServiceId());
    assertEquals("Test:nemerosa/ontrack", configuration.getName());
    assertTrue(configuration instanceof GitHubIssueServiceConfiguration);
    GitHubIssueServiceConfiguration issueServiceConfiguration = (GitHubIssueServiceConfiguration) configuration;
    assertEquals("Test", issueServiceConfiguration.getConfiguration().getName());
    assertEquals("https://github.com", issueServiceConfiguration.getConfiguration().getUrl());
    assertEquals("nemerosa/ontrack", issueServiceConfiguration.getRepository());
}
Also used : GitHubIssueServiceConfiguration(net.nemerosa.ontrack.extension.github.service.GitHubIssueServiceConfiguration) IssueServiceConfiguration(net.nemerosa.ontrack.extension.issues.model.IssueServiceConfiguration) GitHubEngineConfiguration(net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration) GitHubIssueServiceConfiguration(net.nemerosa.ontrack.extension.github.service.GitHubIssueServiceConfiguration) Test(org.junit.Test)

Example 4 with GitHubEngineConfiguration

use of net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration in project ontrack by nemerosa.

the class GitHubEngineConfigurationMigrationActionIT method migration.

/**
 * Test of the migration.
 * <p>
 * An old GitHub configuration is created with name "OntrackTest"
 * (see {@link TestGitHubEngineConfigurationMigrationPreparationAction})
 * <p>
 * A project P is created, using this configuration.
 * <p>
 * The test must check that the old configuration has been migrated and that the project
 * is now using a configuration including the repository, the indexation interval.
 */
@Test
public void migration() throws Exception {
    // Gets the project
    Project project = asUser().with(ProjectList.class).call(() -> structureService.findProjectByName("GitHubEngineConfigurationMigrationAction")).orElseThrow(() -> new ProjectNotFoundException("GitHubEngineConfigurationMigrationAction"));
    // Gets the migrated configuration
    GitHubEngineConfiguration gitHubEngineConfiguration = configurationRepository.find(GitHubEngineConfiguration.class, "OntrackTest").orElseThrow(() -> new RuntimeException("Cannot find \"OntrackTest\" configuration"));
    assertEquals("OntrackTest", gitHubEngineConfiguration.getName());
    assertEquals("https://github.com", gitHubEngineConfiguration.getUrl());
    assertEquals("user", gitHubEngineConfiguration.getUser());
    assertEquals("password", encryptionService.decrypt(gitHubEngineConfiguration.getPassword()));
    assertEquals("token", gitHubEngineConfiguration.getOauth2Token());
    // Gets the GitHub project property
    GitHubProjectConfigurationProperty configurationProperty = asUser().withView(project).call(() -> propertyService.getProperty(project, GitHubProjectConfigurationPropertyType.class).option()).orElseThrow(() -> new RuntimeException("Missing GitHub property on project"));
    assertEquals("OntrackTest", configurationProperty.getConfiguration().getName());
    assertEquals("nemerosa/ontrack", configurationProperty.getRepository());
    assertEquals(30, configurationProperty.getIndexationInterval());
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) ProjectNotFoundException(net.nemerosa.ontrack.model.exceptions.ProjectNotFoundException) GitHubProjectConfigurationProperty(net.nemerosa.ontrack.extension.github.property.GitHubProjectConfigurationProperty) GitHubProjectConfigurationPropertyType(net.nemerosa.ontrack.extension.github.property.GitHubProjectConfigurationPropertyType) GitHubEngineConfiguration(net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration) Test(org.junit.Test)

Example 5 with GitHubEngineConfiguration

use of net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration in project ontrack by nemerosa.

the class GitHubProjectConfigurationPropertyType method fromStorage.

@Override
public GitHubProjectConfigurationProperty fromStorage(JsonNode node) {
    String configurationName = node.path("configuration").asText();
    // Looks the configuration up
    GitHubEngineConfiguration configuration = configurationService.getConfiguration(configurationName);
    // OK
    return new GitHubProjectConfigurationProperty(configuration, node.path("repository").asText(), node.path("indexationInterval").asInt(), node.path("issueServiceConfigurationIdentifier").asText());
}
Also used : GitHubEngineConfiguration(net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration)

Aggregations

GitHubEngineConfiguration (net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration)5 GitHubIssueServiceConfiguration (net.nemerosa.ontrack.extension.github.service.GitHubIssueServiceConfiguration)2 Test (org.junit.Test)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 HashMap (java.util.HashMap)1 GitExtensionFeature (net.nemerosa.ontrack.extension.git.GitExtensionFeature)1 OntrackGitHubClientFactory (net.nemerosa.ontrack.extension.github.client.OntrackGitHubClientFactory)1 GitHubProjectConfigurationProperty (net.nemerosa.ontrack.extension.github.property.GitHubProjectConfigurationProperty)1 GitHubProjectConfigurationPropertyType (net.nemerosa.ontrack.extension.github.property.GitHubProjectConfigurationPropertyType)1 GitHubConfigurationService (net.nemerosa.ontrack.extension.github.service.GitHubConfigurationService)1 IssueExportServiceFactory (net.nemerosa.ontrack.extension.issues.export.IssueExportServiceFactory)1 IssueServiceConfiguration (net.nemerosa.ontrack.extension.issues.model.IssueServiceConfiguration)1 SCMExtensionFeature (net.nemerosa.ontrack.extension.scm.SCMExtensionFeature)1 ProjectNotFoundException (net.nemerosa.ontrack.model.exceptions.ProjectNotFoundException)1 Project (net.nemerosa.ontrack.model.structure.Project)1 Before (org.junit.Before)1