Search in sources :

Example 1 with UserIdentity

use of com.google.gerrit.reviewdb.client.UserIdentity in project gerrit by GerritCodeReview.

the class EventFactory method toUserIdentity.

// TODO: The same method exists in PatchSetInfoFactory, find a common place
// for it
private UserIdentity toUserIdentity(PersonIdent who) {
    UserIdentity u = new UserIdentity();
    u.setName(who.getName());
    u.setEmail(who.getEmailAddress());
    u.setDate(new Timestamp(who.getWhen().getTime()));
    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 = byEmailCache.get(u.getEmail());
    if (a.size() == 1) {
        u.setAccount(a.iterator().next());
    }
    return u;
}
Also used : UserIdentity(com.google.gerrit.reviewdb.client.UserIdentity) ObjectId(org.eclipse.jgit.lib.ObjectId) Timestamp(java.sql.Timestamp)

Example 2 with UserIdentity

use of com.google.gerrit.reviewdb.client.UserIdentity in project gerrit by GerritCodeReview.

the class PatchSetInfoFactory method toUserIdentity.

// TODO: The same method exists in EventFactory, find a common place for it
private UserIdentity toUserIdentity(final PersonIdent who) {
    final UserIdentity u = new UserIdentity();
    u.setName(who.getName());
    u.setEmail(who.getEmailAddress());
    u.setDate(new Timestamp(who.getWhen().getTime()));
    u.setTimeZone(who.getTimeZoneOffset());
    // If only one account has access to this email address, select it
    // as the identity of the user.
    //
    final Set<Account.Id> a = byEmailCache.get(u.getEmail());
    if (a.size() == 1) {
        u.setAccount(a.iterator().next());
    }
    return u;
}
Also used : UserIdentity(com.google.gerrit.reviewdb.client.UserIdentity) ObjectId(org.eclipse.jgit.lib.ObjectId) RevId(com.google.gerrit.reviewdb.client.RevId) Timestamp(java.sql.Timestamp)

Example 3 with UserIdentity

use of com.google.gerrit.reviewdb.client.UserIdentity in project gerrit by GerritCodeReview.

the class EventFactory method asPatchSetAttribute.

/**
   * Create a PatchSetAttribute for the given patchset suitable for serialization to JSON.
   *
   * @param db Review database
   * @param patchSet
   * @return object suitable for serialization to JSON
   */
public PatchSetAttribute asPatchSetAttribute(ReviewDb db, RevWalk revWalk, Change change, PatchSet patchSet) {
    PatchSetAttribute p = new PatchSetAttribute();
    p.revision = patchSet.getRevision().get();
    p.number = patchSet.getPatchSetId();
    p.ref = patchSet.getRefName();
    p.uploader = asAccountAttribute(patchSet.getUploader());
    p.createdOn = patchSet.getCreatedOn().getTime() / 1000L;
    p.isDraft = patchSet.isDraft();
    PatchSet.Id pId = patchSet.getId();
    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 = 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());
        }
        List<Patch> list = patchListCache.get(change, patchSet).toPatchList(pId);
        for (Patch pe : list) {
            if (!Patch.isMagic(pe.getFileName())) {
                p.sizeDeletions -= pe.getDeletions();
                p.sizeInsertions += pe.getInsertions();
            }
        }
        p.kind = changeKindCache.getChangeKind(db, change, patchSet);
    } catch (IOException e) {
        log.error("Cannot load patch set data for " + patchSet.getId(), e);
    } catch (PatchListNotAvailableException e) {
        log.error(String.format("Cannot get size information for %s.", pId), e);
    }
    return p;
}
Also used : AccountAttribute(com.google.gerrit.server.data.AccountAttribute) UserIdentity(com.google.gerrit.reviewdb.client.UserIdentity) PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) PatchSetAttribute(com.google.gerrit.server.data.PatchSetAttribute) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) IOException(java.io.IOException) Patch(com.google.gerrit.reviewdb.client.Patch) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 4 with UserIdentity

use of com.google.gerrit.reviewdb.client.UserIdentity in project gerrit by GerritCodeReview.

the class PRED_commit_author_3 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    PatchSetInfo psInfo = StoredValues.PATCH_SET_INFO.get(engine);
    UserIdentity author = psInfo.getAuthor();
    return exec(engine, author);
}
Also used : UserIdentity(com.google.gerrit.reviewdb.client.UserIdentity) PatchSetInfo(com.google.gerrit.reviewdb.client.PatchSetInfo)

Example 5 with UserIdentity

use of com.google.gerrit.reviewdb.client.UserIdentity in project gerrit by GerritCodeReview.

the class PRED_commit_committer_3 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    PatchSetInfo psInfo = StoredValues.PATCH_SET_INFO.get(engine);
    UserIdentity committer = psInfo.getCommitter();
    return exec(engine, committer);
}
Also used : UserIdentity(com.google.gerrit.reviewdb.client.UserIdentity) PatchSetInfo(com.google.gerrit.reviewdb.client.PatchSetInfo)

Aggregations

UserIdentity (com.google.gerrit.reviewdb.client.UserIdentity)5 PatchSetInfo (com.google.gerrit.reviewdb.client.PatchSetInfo)2 Timestamp (java.sql.Timestamp)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 Patch (com.google.gerrit.reviewdb.client.Patch)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 RevId (com.google.gerrit.reviewdb.client.RevId)1 AccountAttribute (com.google.gerrit.server.data.AccountAttribute)1 PatchSetAttribute (com.google.gerrit.server.data.PatchSetAttribute)1 PatchListNotAvailableException (com.google.gerrit.server.patch.PatchListNotAvailableException)1 IOException (java.io.IOException)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1