in github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GitHubDestinations.java [91:137]
private List<Destination> getDestinations(Path cfgPath)
throws ConfigInvalidException, IOException {
if (!Files.exists(cfgPath) || Files.size(cfgPath) == 0) {
return Collections.emptyList();
}
FileBasedConfig cfg = new FileBasedConfig(cfgPath.toFile(), FS.DETECTED);
try {
cfg.load();
} catch (ConfigInvalidException e) {
throw new ConfigInvalidException(
String.format("Config file %s is invalid: %s", cfg.getFile(), e.getMessage()), e);
} catch (IOException e) {
throw new IOException(String.format("Cannot read %s: %s", cfg.getFile(), e.getMessage()), e);
}
ImmutableList.Builder<Destination> dest = ImmutableList.builder();
for (RemoteConfig c : allRemotes(cfg)) {
if (c.getURIs().isEmpty()) {
continue;
}
for (URIish u : c.getURIs()) {
if (u.getPath() == null || !u.getPath().contains("${name}")) {
throw new ConfigInvalidException(
String.format(
"remote.%s.url \"%s\" lacks ${name} placeholder in %s",
c.getName(), u, cfg.getFile()));
}
}
// If destination for push is not set assume equal to source.
for (RefSpec ref : c.getPushRefSpecs()) {
if (ref.getDestination() == null) {
ref.setDestination(ref.getSource());
}
}
if (c.getPushRefSpecs().isEmpty()) {
c.addPushRefSpec(
new RefSpec().setSourceDestination("refs/*", "refs/*").setForceUpdate(true));
}
dest.add(new Destination(c, cfg, replicationUserFactory, pluginUser, groupBackend));
}
return dest.build();
}