in java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigScanner.java [99:171]
public void visit(
BranchNameKey branchNameKey,
CodeOwnerConfigVisitor codeOwnerConfigVisitor,
InvalidCodeOwnerConfigCallback invalidCodeOwnerConfigCallback,
@Nullable String pathGlob) {
requireNonNull(branchNameKey, "branchNameKey");
requireNonNull(codeOwnerConfigVisitor, "codeOwnerConfigVisitor");
requireNonNull(invalidCodeOwnerConfigCallback, "invalidCodeOwnerConfigCallback");
CodeOwnerBackend codeOwnerBackend =
codeOwnersPluginConfiguration
.getProjectConfig(branchNameKey.project())
.getBackend(branchNameKey.branch());
logger.atFine().log(
"scanning code owner files in branch %s of project %s (path glob = %s)",
branchNameKey.branch(), branchNameKey.project(), pathGlob);
if (includeDefaultCodeOwnerConfig && !RefNames.REFS_CONFIG.equals(branchNameKey.branch())) {
logger.atFine().log("Scanning code owner config file in %s", RefNames.REFS_CONFIG);
Optional<CodeOwnerConfig> metaCodeOwnerConfig =
codeOwnerBackend.getCodeOwnerConfig(
CodeOwnerConfig.Key.createWithFileName(
codeOwnerBackend, branchNameKey.project(), RefNames.REFS_CONFIG, "/"),
/** revision */
null);
if (metaCodeOwnerConfig.isPresent()) {
boolean visitFurtherCodeOwnerConfigFiles =
codeOwnerConfigVisitor.visit(metaCodeOwnerConfig.get());
if (!visitFurtherCodeOwnerConfigFiles) {
// By returning false the callback told us to not visit any further code owner config
// files, hence we are done and do not need to search for further code owner config files
// in the branch.
return;
}
}
}
try (Repository repository = repoManager.openRepository(branchNameKey.project());
RevWalk rw = new RevWalk(repository);
CodeOwnerConfigTreeWalk treeWalk =
new CodeOwnerConfigTreeWalk(
codeOwnerBackend, branchNameKey, repository, rw, pathGlob)) {
while (treeWalk.next()) {
CodeOwnerConfig codeOwnerConfig;
try {
codeOwnerConfig = treeWalk.getCodeOwnerConfig();
} catch (CodeOwnersInternalServerErrorException codeOwnersInternalServerErrorException) {
Optional<InvalidCodeOwnerConfigException> invalidCodeOwnerConfigException =
getInvalidCodeOwnerConfigCause(codeOwnersInternalServerErrorException);
if (!invalidCodeOwnerConfigException.isPresent()) {
// Propagate any failure that is not related to the contents of the code owner config.
throw codeOwnersInternalServerErrorException;
}
// The code owner config is invalid and cannot be parsed.
invalidCodeOwnerConfigCallback.onInvalidCodeOwnerConfig(
treeWalk.getFilePath(), invalidCodeOwnerConfigException.get());
continue;
}
boolean visitFurtherCodeOwnerConfigFiles = codeOwnerConfigVisitor.visit(codeOwnerConfig);
if (!visitFurtherCodeOwnerConfigFiles) {
break;
}
}
} catch (IOException e) {
throw new CodeOwnersInternalServerErrorException(
String.format(
"Failed to scan for code owner configs in branch %s of project %s",
branchNameKey.branch(), branchNameKey.project()),
e);
}
}