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;
}
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");
}
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());
}
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());
}
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());
}
Aggregations