Search in sources :

Example 1 with InvalidAuthorException

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change) RepoException(com.google.copybara.exception.RepoException) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) InvalidAuthorException(com.google.copybara.authoring.InvalidAuthorException)

Example 2 with InvalidAuthorException

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);
}
Also used : Author(com.google.copybara.authoring.Author) ImmutableMap(com.google.common.collect.ImmutableMap) InvalidAuthorException(com.google.copybara.authoring.InvalidAuthorException)

Example 3 with InvalidAuthorException

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;
}
Also used : Author(com.google.copybara.authoring.Author) InvalidAuthorException(com.google.copybara.authoring.InvalidAuthorException)

Aggregations

Author (com.google.copybara.authoring.Author)3 InvalidAuthorException (com.google.copybara.authoring.InvalidAuthorException)3 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Change (com.google.copybara.Change)1 RepoException (com.google.copybara.exception.RepoException)1 HgLogEntry (com.google.copybara.hg.HgRepository.HgLogEntry)1