Skip to content

Commit

Permalink
feat: Configurable repos.csv path
Browse files Browse the repository at this point in the history
  • Loading branch information
pstreef committed Aug 12, 2024
1 parent 5be7c4d commit ec8447f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ There is repetition in organizational hierarchy in this format. The reference im
If you have multiple organizations with the same display name, you can map id to display name in an `id-mapping.txt`. A simple reference
file is included in this repository.

You can either overwrite the existing [repos.csv](src/main/resources/repos.csv) or set the `moderne.scm.reposCsvPath` in [application.yaml](src/main/resources/application.yaml).

### Mapping repositories

Edit [application.yaml](src/main/resources/application.yaml) to list all the origins (host + context path) for the SCM providers listed in the repos.csv, and provide a type: `[GITHUB,GITLAB,BITBUCKET_CLOUD,BITBUCKET,AZURE_DEVOPS]`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -22,7 +21,7 @@
*/
@Service
public class OrganizationStructureService {
private static final String REPOS_CSV = "repos.csv";
private static final String DEFAULT_REPOS_CSV = "repos.csv";
private static final String NAME_MAPPING = "id-mapping.txt";
private static final Logger log = LoggerFactory.getLogger(OrganizationStructureService.class.getName());
private final ScmConfiguration scmConfiguration;
Expand All @@ -39,7 +38,19 @@ public Map<String, OrganizationRepositories> readOrganizationStructure() {

final Map<String, String> idToNameMapping = readIdToNameMapping();

try (BufferedReader reader = new BufferedReader(new InputStreamReader(new ClassPathResource(REPOS_CSV).getInputStream()))) {
Path reposCsvOverride = scmConfiguration.getReposCsvPath();
InputStream inputStream;
try {
if (reposCsvOverride == null) {
inputStream = new ClassPathResource(DEFAULT_REPOS_CSV).getInputStream();
} else {
inputStream = new FileInputStream(reposCsvOverride.toFile());
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}

try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
reader.readLine(); // skip header
reader.lines()
.forEach(line -> {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/moderne/organizations/ScmConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.moderne.organizations;

import jakarta.annotation.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -10,6 +12,9 @@ public class ScmConfiguration {
private List<ScmRepository> repositories;
private boolean allowMissingScmOrigins;

@Nullable
private Path reposCsvPath;

public static class ScmRepository {
String origin;
Type type;
Expand Down Expand Up @@ -54,5 +59,12 @@ public void setAllowMissingScmOrigins(boolean allowMissingScmOrigins) {
this.allowMissingScmOrigins = allowMissingScmOrigins;
}

@Nullable
public Path getReposCsvPath() {
return reposCsvPath;
}

public void setReposCsvPath(@Nullable Path reposCsvPath) {
this.reposCsvPath = reposCsvPath;
}
}

0 comments on commit ec8447f

Please sign in to comment.