Repository: societe-generale/github-crawler
Pull request #96 (2022-03-23 14:42:21)

renaming some config keys to make it more generic


Patch:
diff --git a/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/AzureDevopsConfiguration.kt b/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/AzureDevopsConfiguration.kt
index ab32083..e103d07 100644
--- a/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/AzureDevopsConfiguration.kt
+++ b/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/AzureDevopsConfiguration.kt
@@ -11,7 +11,7 @@ import org.springframework.context.annotation.Bean
 import org.springframework.context.annotation.Configuration
 
 @Configuration
-@ConditionalOnProperty(prefix = "github-crawler.githubConfig", name = ["type"], havingValue = "AZURE_DEVOPS")
+@ConditionalOnProperty(prefix = "github-crawler.source-control", name = ["type"], havingValue = "AZURE_DEVOPS")
 open class AzureDevopsConfiguration {
 
     val log = LoggerFactory.getLogger(this.javaClass)
@@ -21,18 +21,18 @@ open class AzureDevopsConfiguration {
 
         val targetUrl:String
 
-        if(gitHubCrawlerProperties.githubConfig.apiUrl.isEmpty()){
+        if(gitHubCrawlerProperties.sourceControl.url.isEmpty()){
             targetUrl=  AZURE_DEVOPS_URL
         }
         else{
-            targetUrl=gitHubCrawlerProperties.githubConfig.apiUrl
+            targetUrl=gitHubCrawlerProperties.sourceControl.url
         }
 
         log.info("URL for AzureDevops : $targetUrl")
 
         return RemoteAzureDevopsImpl(targetUrl,
-                                     gitHubCrawlerProperties.githubConfig.organizationName,
-                                     gitHubCrawlerProperties.githubConfig.oauthToken)
+                                     gitHubCrawlerProperties.sourceControl.organizationName,
+                                     gitHubCrawlerProperties.sourceControl.apiToken)
     }
 
 }
diff --git a/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubConfiguration.kt b/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubConfiguration.kt
index 90d2c63..d89bda8 100644
--- a/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubConfiguration.kt
+++ b/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubConfiguration.kt
@@ -9,13 +9,15 @@ import org.springframework.context.annotation.Bean
 import org.springframework.context.annotation.Configuration
 
 @Configuration
-@ConditionalOnProperty(prefix = "github-crawler.githubConfig", name = ["type"], havingValue = "GITHUB")
+@ConditionalOnProperty(prefix = "github-crawler.source-control", name = ["type"], havingValue = "GITHUB")
 open class GitHubConfiguration {
 
     @Bean
     open fun remoteGitHub(gitHubCrawlerProperties: GitHubCrawlerProperties): RemoteGitHub {
 
-        return RemoteGitHubImpl(gitHubCrawlerProperties.githubConfig.apiUrl,gitHubCrawlerProperties.githubConfig.crawlUsersRepoInsteadOfOrgasRepos,gitHubCrawlerProperties.githubConfig.oauthToken)
+        return RemoteGitHubImpl(gitHubCrawlerProperties.sourceControl.url,
+                                gitHubCrawlerProperties.sourceControl.crawlUsersRepoInsteadOfOrgasRepos,
+                                gitHubCrawlerProperties.sourceControl.apiToken)
     }
 
 }
diff --git a/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubCrawlerAutoConfiguration.kt b/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubCrawlerAutoConfiguration.kt
index aea779d..c62c65d 100644
--- a/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubCrawlerAutoConfiguration.kt
+++ b/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubCrawlerAutoConfiguration.kt
@@ -45,7 +45,7 @@ open class GitHubCrawlerAutoConfiguration {
 
         log.info("using repositoryEnricher "+repositoryEnricher+" when building the crawler...")
 
-        return GitHubCrawler(remoteGitHub, output, repositoryEnricher,gitHubCrawlerProperties,environment,gitHubCrawlerProperties.githubConfig.organizationName,configValidator,availableParsersAndTasks)
+        return GitHubCrawler(remoteGitHub, output, repositoryEnricher,gitHubCrawlerProperties,environment,gitHubCrawlerProperties.sourceControl.organizationName,configValidator,availableParsersAndTasks)
     }
 
     @Bean
diff --git a/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubCrawlerMiscTasksConfig.kt b/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubCrawlerMiscTasksConfig.kt
index 8343e43..ed53189 100644
--- a/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubCrawlerMiscTasksConfig.kt
+++ b/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitHubCrawlerMiscTasksConfig.kt
@@ -45,7 +45,7 @@ open class GitHubCrawlerMiscTasksConfig {
     @Bean
     open fun repoOwnershipComputer(remoteGitHub: RemoteGitHub, gitHubCrawlerProperties: GitHubCrawlerProperties): RepoOwnershipComputerBuilder {
 
-        val organizationName=gitHubCrawlerProperties.githubConfig.organizationName
+        val organizationName=gitHubCrawlerProperties.sourceControl.organizationName
 
         return RepoOwnershipComputerBuilder(remoteGitHub, MembershipParser(remoteGitHub, organizationName), organizationName,150);
     }
diff --git a/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitLabConfiguration.kt b/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitLabConfiguration.kt
index 31bacab..c097dca 100644
--- a/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitLabConfiguration.kt
+++ b/github-crawler-autoconfigure/src/main/kotlin/com/societegenerale/githubcrawler/config/GitLabConfiguration.kt
@@ -9,13 +9,13 @@ import org.springframework.context.annotation.Bean
 import org.springframework.context.annotation.Configuration
 
 @Configuration
-@ConditionalOnProperty(prefix = "github-crawler.githubConfig", name = ["type"], havingValue = "GITLAB")
+@ConditionalOnProperty(prefix = "github-crawler.source-control", name = ["type"], havingValue = "GITLAB")
 open class GitLabConfiguration {
 
     @Bean
     open fun remoteGitLab(gitHubCrawlerProperties: GitHubCrawlerProperties): RemoteGitHub {
 
-        return RemoteGitLabImpl(gitHubCrawlerProperties.githubConfig.apiUrl,gitHubCrawlerProperties.githubConfig.oauthToken)
+        return RemoteGitLabImpl(gitHubCrawlerProperties.sourceControl.url,gitHubCrawlerProperties.sourceControl.apiToken)
     }
 
 }
diff --git a/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/ConfigValidator.kt b/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/ConfigValidator.kt
index 1dbfebc..dcd13d2 100644
--- a/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/ConfigValidator.kt
+++ b/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/ConfigValidator.kt
@@ -18,12 +18,12 @@ class ConfigValidator(val properties : GitHubCrawlerProperties,
         val validationErrors = mutableListOf<String>()
 
         // there's a default url for AzureDevops, no need to configure it
-        if(properties.githubConfig.type!= SourceControlType.AZURE_DEVOPS &&
-           properties.githubConfig.apiUrl.isBlank()){
-            validationErrors.add("gitHub.apiUrl can't be empty")
+        if(properties.sourceControl.type!= SourceControlType.AZURE_DEVOPS &&
+           properties.sourceControl.url.isBlank()){
+            validationErrors.add("source-control.url can't be empty")
         }
 
-        if(properties.githubConfig.organizationName.isBlank()){
+        if(properties.sourceControl.organizationName.isBlank()){
             validationErrors.add("organization can't be empty")
         }
 
@@ -31,14 +31,14 @@ class ConfigValidator(val properties : GitHubCrawlerProperties,
             return ImmutableList.copyOf(validationErrors);
         }
 
-        val organizationName=properties.githubConfig.organizationName;
+        val organizationName=properties.sourceControl.organizationName;
 
         try{
             remoteGitHub.validateRemoteConfig(organizationName)
         }
         catch(e : NoReachableRepositories){
             //TODO make this GitLab ready..
-            val errorMessage = "Not able to fetch repositories from the organization ${organizationName} on URL ${properties.githubConfig.apiUrl}. This could be due to several things :\n"+
+            val errorMessage = "Not able to fetch repositories from the organization ${organizationName} on URL ${properties.sourceControl.url}. This could be due to several things :\n"+
                     "\t\t - URL should be the API URL. For github.com it's https://api.github.com, for Github Enterprise, it's usually https://myGHEserver/api/v3 (no trailing slash) \n"+
                     "\t\t - the organization doesn't exist\n"+
                     "\t\t - remote server is not reachable (are you using a proxy ?)\n\n"+
diff --git a/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/GitHubCrawlerProperties.kt b/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/GitHubCrawlerProperties.kt
index 1ea88d7..1f39d40 100644
--- a/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/GitHubCrawlerProperties.kt
+++ b/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/GitHubCrawlerProperties.kt
@@ -9,7 +9,7 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty
 @ConfigurationProperties("github-crawler")
 @EnableConfigurationProperties
 class GitHubCrawlerProperties(@NestedConfigurationProperty
-                              val githubConfig : GithubConfig=GithubConfig(),
+                              val sourceControl : SourceControlConfig=SourceControlConfig(),
                               val indicatorsToFetchByFile: Map<com.societegenerale.githubcrawler.FileToParse, List<IndicatorDefinition>> = HashMap(),
                               var repositoriesToExclude: List<String> = ArrayList(),
                               var publishExcludedRepositories: Boolean = false,
diff --git a/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/GithubConfig.kt b/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/GithubConfig.kt
deleted file mode 100644
index 3c5e23f..0000000
--- a/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/GithubConfig.kt
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.societegenerale.githubcrawler
-
-import org.springframework.boot.context.properties.ConfigurationProperties
-
-
-@ConfigurationProperties("github-crawler.githubConfig")
-class GithubConfig(var type: SourceControlType = SourceControlType.GITHUB,
-                   var apiUrl: String="",
-                   var oauthToken: String="",
-                   var organizationName: String="",
-                   var crawlUsersRepoInsteadOfOrgasRepos: Boolean=false)
-
-enum class SourceControlType {
-  GITLAB, GITHUB,AZURE_DEVOPS
-}
\ No newline at end of file
diff --git a/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/SourceControlConfig.kt b/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/SourceControlConfig.kt
new file mode 100644
index 0000000..cf37511
--- /dev/null
+++ b/github-crawler-core/src/main/kotlin/com/societegenerale/githubcrawler/SourceControlConfig.kt
@@ -0,0 +1,15 @@
+package com.societegenerale.githubcrawler
+
+import org.springframework.boot.context.properties.ConfigurationProperties
+
+
+@ConfigurationProperties("github-crawler.source-control")
+class SourceControlConfig(var type: SourceControlType = SourceControlType.GITHUB,
+                          var url: String="",
+                          var apiToken: String="",
+                          var organizationName: String="",
+                          var crawlUsersRepoInsteadOfOrgasRepos: Boolean=false)
+
+enum class SourceControlType {
+  GITLAB, GITHUB,AZURE_DEVOPS
+}
\ No newline at end of file


Test patch:
diff --git a/github-crawler-autoconfigure/src/test/java/com/societegenerale/githubcrawler/AzureDevopsCrawlerIT.java b/github-crawler-autoconfigure/src/test/java/com/societegenerale/githubcrawler/AzureDevopsCrawlerIT.java
index 8f7c169..cf52ee5 100644
--- a/github-crawler-autoconfigure/src/test/java/com/societegenerale/githubcrawler/AzureDevopsCrawlerIT.java
+++ b/github-crawler-autoconfigure/src/test/java/com/societegenerale/githubcrawler/AzureDevopsCrawlerIT.java
@@ -95,7 +95,7 @@ class AzureDevopsCrawlerIT {
 
     log.info("about to start crawling...");
 
-    log.info("URL config used : "+crawler.getGitHubCrawlerProperties().getGithubConfig().getApiUrl());
+    log.info("URL config used : "+crawler.getGitHubCrawlerProperties().getSourceControl().getUrl());
 
     log.info("nb misc tasks : "+crawler.getGitHubCrawlerProperties().getMiscRepositoryTasks().size());
 
diff --git a/github-crawler-autoconfigure/src/test/resources/application-azureDevopsTest.yml b/github-crawler-autoconfigure/src/test/resources/application-azureDevopsTest.yml
index ff3e321..725a2db 100644
--- a/github-crawler-autoconfigure/src/test/resources/application-azureDevopsTest.yml
+++ b/github-crawler-autoconfigure/src/test/resources/application-azureDevopsTest.yml
@@ -1,8 +1,8 @@
 github-crawler:
 
-  githubConfig:
+  source-control:
     type: "AZURE_DEVOPS"
-    apiUrl: http://localhost:9901/
+    url: http://localhost:9901/
     organizationName: "platform#platform-projects"
 
   publishExcludedRepositories: false
diff --git a/github-crawler-autoconfigure/src/test/resources/application-gitHubTest.yml b/github-crawler-autoconfigure/src/test/resources/application-gitHubTest.yml
index 7f780fc..7ac2e1e 100644
--- a/github-crawler-autoconfigure/src/test/resources/application-gitHubTest.yml
+++ b/github-crawler-autoconfigure/src/test/resources/application-gitHubTest.yml
@@ -1,8 +1,8 @@
 github-crawler:
 
-  githubConfig:
+  source-control:
     type: "GITHUB"
-    apiUrl: http://localhost:9900/api/v3
+    url: http://localhost:9900/api/v3
     organizationName: MyOrganization
 
   publishExcludedRepositories: false
diff --git a/github-crawler-autoconfigure/src/test/resources/application-gitLabTest.yml b/github-crawler-autoconfigure/src/test/resources/application-gitLabTest.yml
index a0a4415..a2612fa 100644
--- a/github-crawler-autoconfigure/src/test/resources/application-gitLabTest.yml
+++ b/github-crawler-autoconfigure/src/test/resources/application-gitLabTest.yml
@@ -1,8 +1,8 @@
 github-crawler:
 
-  githubConfig:
+  source-control:
     type: "GITLAB"
-    apiUrl: http://localhost:9900/api/v3
+    url: http://localhost:9900/api/v3
     organizationName: MyOrganization
 
   publishExcludedRepositories: false
diff --git a/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/ConfigValidatorTest.kt b/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/ConfigValidatorTest.kt
index 18619e0..944fb29 100644
--- a/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/ConfigValidatorTest.kt
+++ b/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/ConfigValidatorTest.kt
@@ -15,16 +15,16 @@ class ConfigValidatorTest {
     @Test
     fun shouldNotHaveEmptyGitHubUrl() {
 
-        val configValidator = ConfigValidator(GitHubCrawlerProperties(GithubConfig(apiUrl = "",organizationName="notEmpty")),mockRemoteGitHub)
+        val configValidator = ConfigValidator(GitHubCrawlerProperties(SourceControlConfig(url = "",organizationName="notEmpty")),mockRemoteGitHub)
 
-        assertThat(configValidator.getValidationErrors()).containsOnly("gitHub.apiUrl can't be empty");
+        assertThat(configValidator.getValidationErrors()).containsOnly("source-control.url can't be empty");
 
     }
 
     @Test
     fun shouldNotHaveEmptyOrganization() {
 
-        val configValidator = ConfigValidator(GitHubCrawlerProperties(GithubConfig(apiUrl = "notEmpty",organizationName="")),mockRemoteGitHub)
+        val configValidator = ConfigValidator(GitHubCrawlerProperties(SourceControlConfig(url = "notEmpty",organizationName="")),mockRemoteGitHub)
 
         assertThat(configValidator.getValidationErrors()).containsOnly("organization can't be empty");
 
@@ -33,7 +33,7 @@ class ConfigValidatorTest {
     @Test
     fun shouldLogProperMessageIfNotAbleToHitAPI() {
 
-        val configValidator = ConfigValidator(GitHubCrawlerProperties(GithubConfig(apiUrl = "someIncorrectURL",organizationName="someOrg")),mockRemoteGitHub)
+        val configValidator = ConfigValidator(GitHubCrawlerProperties(SourceControlConfig(url = "someIncorrectURL",organizationName="someOrg")),mockRemoteGitHub)
 
         `when`(mockRemoteGitHub.validateRemoteConfig("someOrg")).thenThrow(NoReachableRepositories("problem !",mock(Exception::class.java)))
 
diff --git a/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/GitHubCrawlerTest.kt b/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/GitHubCrawlerTest.kt
index c2f01ec..f79e67f 100644
--- a/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/GitHubCrawlerTest.kt
+++ b/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/GitHubCrawlerTest.kt
@@ -33,7 +33,7 @@ class GitHubCrawlerTest {
 
     private val repositoryEnricher = RepositoryEnricher(mockRemoteGitHub,availableParsersAndTasks)
 
-    private val gitHubCrawlerProperties = GitHubCrawlerProperties(githubConfig= GithubConfig(), indicatorsToFetchByFile = mapOf(Pair(FileToParse(fileToParse, null), listOf(indicator))))
+    private val gitHubCrawlerProperties = GitHubCrawlerProperties(sourceControl= SourceControlConfig(), indicatorsToFetchByFile = mapOf(Pair(FileToParse(fileToParse, null), listOf(indicator))))
     private val mockEnvironment = mock(Environment::class.java)
     private val organizationName = "myOrg"
     private val mockConfigValidator = mock(ConfigValidator::class.java)
diff --git a/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/RepositoryEnricherTest.kt b/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/RepositoryEnricherTest.kt
index 3422b82..54bb5b7 100644
--- a/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/RepositoryEnricherTest.kt
+++ b/github-crawler-core/src/test/java/com/societegenerale/githubcrawler/RepositoryEnricherTest.kt
@@ -34,7 +34,7 @@ class RepositoryEnricherTest {
     @Test
     fun shouldHaveEmptyIndicatorsWhenNoneIsConfigured() {
 
-        val properties = GitHubCrawlerProperties(GithubConfig())
+        val properties = GitHubCrawlerProperties(SourceControlConfig())
 
         val repoAfterProcessing=repositoryEnricher.fetchIndicatorsValues(repository,properties)