use of com.google.copybara.authoring.InvalidAuthorException in project copybara by google.
the class ChangeReader method parseChanges.
private ImmutableList<Change<HgRevision>> parseChanges(ImmutableList<HgLogEntry> logEntries) throws RepoException {
ImmutableList.Builder<Change<HgRevision>> result = ImmutableList.builder();
for (HgLogEntry entry : logEntries) {
HgRevision rev = new HgRevision(entry.getGlobalId());
if (NULL_GLOBAL_ID.equals(rev.getGlobalId())) {
continue;
}
Author user;
try {
user = AuthorParser.parse(entry.getUser());
} catch (InvalidAuthorException e) {
console.warn(String.format("Cannot parse commit user and email: %s", e.getMessage()));
user = authoring.orElseThrow(() -> new RepoException("No default author provided.")).getDefaultAuthor();
}
ImmutableList<HgRevision> parents = entry.getParents().stream().map(HgRevision::new).collect(ImmutableList.toImmutableList());
result.add(new Change<>(rev, user, entry.getDescription(), entry.getZonedDate(), ChangeMessage.parseAllAsLabels(entry.getDescription()).labelsAsMultimap(), ImmutableSet.copyOf(entry.getFiles()), parents.size() > 1, parents));
}
return result.build();
}
use of com.google.copybara.authoring.InvalidAuthorException in project copybara by google.
the class MapAuthor method create.
public static MapAuthor create(Location location, Map<String, String> authorMap, boolean reversible, boolean noopReverse, boolean failIfNotFound, boolean failIfNotFoundInReverse, boolean mapAll) throws EvalException {
ImmutableMap.Builder<String, String> authorToAuthor = ImmutableMap.builder();
ImmutableMap.Builder<String, Author> mailToAuthor = ImmutableMap.builder();
ImmutableMap.Builder<String, Author> nameToAuthor = ImmutableMap.builder();
for (Entry<String, String> e : authorMap.entrySet()) {
Author to = Author.parse(e.getValue());
try {
authorToAuthor.put(AuthorParser.parse(e.getKey()).toString(), to.toString());
} catch (InvalidAuthorException ex) {
if (e.getKey().contains("@")) {
mailToAuthor.put(e.getKey(), to);
} else {
nameToAuthor.put(e.getKey(), to);
}
}
}
return new MapAuthor(location, authorToAuthor.buildOrThrow(), mailToAuthor.buildOrThrow(), nameToAuthor.buildOrThrow(), reversible, noopReverse, failIfNotFound, failIfNotFoundInReverse, mapAll);
}
use of com.google.copybara.authoring.InvalidAuthorException in project copybara by google.
the class MapAuthor method getMappedAuthor.
private Author getMappedAuthor(Author originalAuthor) throws ValidationException {
String newAuthor = authorToAuthor.get(originalAuthor.toString());
if (newAuthor != null) {
try {
return AuthorParser.parse(newAuthor);
} catch (InvalidAuthorException e) {
throw new IllegalStateException("Shouldn't happen. We validate before", e);
}
}
Author byMail = mailToAuthor.get(originalAuthor.getEmail());
if (byMail != null) {
return byMail;
}
Author byName = nameToAuthor.get(originalAuthor.getName());
if (byName != null) {
return byName;
}
checkCondition(!failIfNotFound, "Cannot find a mapping for author '%s'", originalAuthor);
return originalAuthor;
}
Aggregations