Search in sources :

Example 1 with UserIdentity

use of com.google.gerrit.entities.UserIdentity in project gerrit by GerritCodeReview.

the class Emails method toUserIdentity.

// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
public UserIdentity toUserIdentity(PersonIdent who) throws IOException {
    UserIdentity u = new UserIdentity();
    u.setName(who.getName());
    u.setEmail(who.getEmailAddress());
    u.setDate(who.getWhen().toInstant());
    u.setTimeZone(who.getTimeZoneOffset());
    // If only one account has access to this email address, select it
    // as the identity of the user.
    // 
    Set<Account.Id> a = getAccountFor(u.getEmail());
    if (a.size() == 1) {
        u.setAccount(a.iterator().next());
    }
    return u;
}
Also used : UserIdentity(com.google.gerrit.entities.UserIdentity) ExternalId(com.google.gerrit.server.account.externalids.ExternalId)

Example 2 with UserIdentity

use of com.google.gerrit.entities.UserIdentity in project gerrit by GerritCodeReview.

the class EventFactory method asPatchSetAttribute.

/**
 * Create a PatchSetAttribute for the given patchset suitable for serialization to JSON.
 */
public PatchSetAttribute asPatchSetAttribute(RevWalk revWalk, Change change, PatchSet patchSet) {
    PatchSetAttribute p = new PatchSetAttribute();
    p.revision = patchSet.commitId().name();
    p.number = patchSet.number();
    p.ref = patchSet.refName();
    p.uploader = asAccountAttribute(patchSet.uploader());
    p.createdOn = patchSet.createdOn().getEpochSecond();
    PatchSet.Id pId = patchSet.id();
    try {
        p.parents = new ArrayList<>();
        RevCommit c = revWalk.parseCommit(ObjectId.fromString(p.revision));
        for (RevCommit parent : c.getParents()) {
            p.parents.add(parent.name());
        }
        UserIdentity author = emails.toUserIdentity(c.getAuthorIdent());
        if (author.getAccount() == null) {
            p.author = new AccountAttribute();
            p.author.email = author.getEmail();
            p.author.name = author.getName();
            p.author.username = "";
        } else {
            p.author = asAccountAttribute(author.getAccount());
        }
        Map<String, FileDiffOutput> modifiedFiles = diffOperations.listModifiedFilesAgainstParent(change.getProject(), patchSet.commitId(), /* parentNum= */
        0, DiffOptions.DEFAULTS);
        for (FileDiffOutput fileDiff : modifiedFiles.values()) {
            p.sizeDeletions += fileDiff.deletions();
            p.sizeInsertions += fileDiff.insertions();
        }
        p.kind = changeKindCache.getChangeKind(change, patchSet);
    } catch (IOException | StorageException e) {
        logger.atSevere().withCause(e).log("Cannot load patch set data for %s", patchSet.id());
    } catch (DiffNotAvailableException e) {
        logger.atSevere().withCause(e).log("Cannot get size information for %s.", pId);
    }
    return p;
}
Also used : AccountAttribute(com.google.gerrit.server.data.AccountAttribute) UserIdentity(com.google.gerrit.entities.UserIdentity) PatchSet(com.google.gerrit.entities.PatchSet) IOException(java.io.IOException) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) PatchSetAttribute(com.google.gerrit.server.data.PatchSetAttribute) StorageException(com.google.gerrit.exceptions.StorageException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

UserIdentity (com.google.gerrit.entities.UserIdentity)2 PatchSet (com.google.gerrit.entities.PatchSet)1 StorageException (com.google.gerrit.exceptions.StorageException)1 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)1 AccountAttribute (com.google.gerrit.server.data.AccountAttribute)1 PatchSetAttribute (com.google.gerrit.server.data.PatchSetAttribute)1 DiffNotAvailableException (com.google.gerrit.server.patch.DiffNotAvailableException)1 FileDiffOutput (com.google.gerrit.server.patch.filediff.FileDiffOutput)1 IOException (java.io.IOException)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1