Search in sources :

Example 6 with Comment

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

the class ChangeData method draftRefs.

public Map<Account.Id, Ref> draftRefs() throws OrmException {
    if (draftsByUser == null) {
        if (!lazyLoad) {
            return Collections.emptyMap();
        }
        Change c = change();
        if (c == null) {
            return Collections.emptyMap();
        }
        draftsByUser = new HashMap<>();
        if (notesMigration.readChanges()) {
            for (Ref ref : commentsUtil.getDraftRefs(notes.getChangeId())) {
                Account.Id account = Account.Id.fromRefSuffix(ref.getName());
                if (account != null && // this point.
                !notes().getDraftComments(account, ref).isEmpty()) {
                    draftsByUser.put(account, ref);
                }
            }
        } else {
            for (Comment sc : commentsUtil.draftByChange(db, notes())) {
                draftsByUser.put(sc.author.getId(), null);
            }
        }
    }
    return draftsByUser;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) Comment(com.google.gerrit.reviewdb.client.Comment) RobotComment(com.google.gerrit.reviewdb.client.RobotComment) StarRef(com.google.gerrit.server.StarredChangesUtil.StarRef) Ref(org.eclipse.jgit.lib.Ref) Change(com.google.gerrit.reviewdb.client.Change)

Example 7 with Comment

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

the class CommentDetail method addChildren.

/** Add the comments to {@code outResult}, depth first */
private static void addChildren(Map<String, List<Comment>> parentMap, List<Comment> children, List<Comment> outResult) {
    if (children != null) {
        for (Comment c : children) {
            outResult.add(c);
            addChildren(parentMap, parentMap.get(c.key.uuid), outResult);
        }
    }
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment)

Example 8 with Comment

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

the class ChangeRebuilderImpl method buildUpdates.

@Override
public void buildUpdates(NoteDbUpdateManager manager, ChangeBundle bundle) throws IOException, OrmException {
    manager.setCheckExpectedState(false).setRefLogMessage("Rebuilding change");
    Change change = new Change(bundle.getChange());
    if (bundle.getPatchSets().isEmpty()) {
        throw new NoPatchSetsException(change.getId());
    }
    // We will rebuild all events, except for draft comments, in buckets based
    // on author and timestamp.
    List<Event> events = new ArrayList<>();
    ListMultimap<Account.Id, DraftCommentEvent> draftCommentEvents = MultimapBuilder.hashKeys().arrayListValues().build();
    events.addAll(getHashtagsEvents(change, manager));
    // Delete ref only after hashtags have been read
    deleteChangeMetaRef(change, manager.getChangeRepo().cmds);
    deleteDraftRefs(change, manager.getAllUsersRepo());
    Integer minPsNum = getMinPatchSetNum(bundle);
    TreeMap<PatchSet.Id, PatchSetEvent> patchSetEvents = new TreeMap<>(ReviewDbUtil.intKeyOrdering());
    for (PatchSet ps : bundle.getPatchSets()) {
        PatchSetEvent pse = new PatchSetEvent(change, ps, manager.getChangeRepo().rw);
        patchSetEvents.put(ps.getId(), pse);
        events.add(pse);
        for (Comment c : getComments(bundle, serverId, Status.PUBLISHED, ps)) {
            CommentEvent e = new CommentEvent(c, change, ps, patchListCache);
            events.add(e.addDep(pse));
        }
        for (Comment c : getComments(bundle, serverId, Status.DRAFT, ps)) {
            DraftCommentEvent e = new DraftCommentEvent(c, change, ps, patchListCache);
            draftCommentEvents.put(c.author.getId(), e);
        }
    }
    ensurePatchSetOrder(patchSetEvents);
    for (PatchSetApproval psa : bundle.getPatchSetApprovals()) {
        PatchSetEvent pse = patchSetEvents.get(psa.getPatchSetId());
        if (pse != null) {
            events.add(new ApprovalEvent(psa, change.getCreatedOn()).addDep(pse));
        }
    }
    for (Table.Cell<ReviewerStateInternal, Account.Id, Timestamp> r : bundle.getReviewers().asTable().cellSet()) {
        events.add(new ReviewerEvent(r, change.getCreatedOn()));
    }
    Change noteDbChange = new Change(null, null, null, null, null);
    for (ChangeMessage msg : bundle.getChangeMessages()) {
        Event msgEvent = new ChangeMessageEvent(change, noteDbChange, msg, change.getCreatedOn());
        if (msg.getPatchSetId() != null) {
            PatchSetEvent pse = patchSetEvents.get(msg.getPatchSetId());
            if (pse == null) {
                // Ignore events for missing patch sets.
                continue;
            }
            msgEvent.addDep(pse);
        }
        events.add(msgEvent);
    }
    sortAndFillEvents(change, noteDbChange, bundle.getPatchSets(), events, minPsNum);
    EventList<Event> el = new EventList<>();
    for (Event e : events) {
        if (!el.canAdd(e)) {
            flushEventsToUpdate(manager, el, change);
            checkState(el.canAdd(e));
        }
        el.add(e);
    }
    flushEventsToUpdate(manager, el, change);
    EventList<DraftCommentEvent> plcel = new EventList<>();
    for (Account.Id author : draftCommentEvents.keys()) {
        for (DraftCommentEvent e : Ordering.natural().sortedCopy(draftCommentEvents.get(author))) {
            if (!plcel.canAdd(e)) {
                flushEventsToDraftUpdate(manager, plcel, change);
                checkState(plcel.canAdd(e));
            }
            plcel.add(e);
        }
        flushEventsToDraftUpdate(manager, plcel, change);
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ArrayList(java.util.ArrayList) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Timestamp(java.sql.Timestamp) PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) Comment(com.google.gerrit.reviewdb.client.Comment) Table(com.google.common.collect.Table) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) TreeMap(java.util.TreeMap) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) GerritServerId(com.google.gerrit.server.config.GerritServerId) ObjectId(org.eclipse.jgit.lib.ObjectId)

Example 9 with Comment

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

the class PatchScriptFactory method loadDrafts.

private void loadDrafts(Map<Patch.Key, Patch> byKey, Account.Id me, String file) throws OrmException {
    for (Comment c : commentsUtil.draftByChangeFileAuthor(db, control.getNotes(), file, me)) {
        comments.include(change.getId(), c);
        PatchSet.Id psId = new PatchSet.Id(change.getId(), c.key.patchSetId);
        Patch.Key pKey = new Patch.Key(psId, c.key.filename);
        Patch p = byKey.get(pKey);
        if (p != null) {
            p.setDraftCount(p.getDraftCount() + 1);
        }
    }
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ObjectId(org.eclipse.jgit.lib.ObjectId) Patch(com.google.gerrit.reviewdb.client.Patch)

Example 10 with Comment

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

the class RevisionNoteBuilder method buildNoteJson.

private void buildNoteJson(ChangeNoteUtil noteUtil, OutputStream out) throws IOException {
    ListMultimap<Integer, Comment> comments = buildCommentMap();
    if (comments.isEmpty() && pushCert == null) {
        return;
    }
    RevisionNoteData data = new RevisionNoteData();
    data.comments = COMMENT_ORDER.sortedCopy(comments.values());
    data.pushCert = pushCert;
    try (OutputStreamWriter osw = new OutputStreamWriter(out, UTF_8)) {
        noteUtil.getGson().toJson(data, osw);
    }
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

Comment (com.google.gerrit.reviewdb.client.Comment)73 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)38 Change (com.google.gerrit.reviewdb.client.Change)35 Test (org.junit.Test)34 CommentRange (com.google.gerrit.reviewdb.client.CommentRange)29 Timestamp (java.sql.Timestamp)29 RevId (com.google.gerrit.reviewdb.client.RevId)27 ObjectId (org.eclipse.jgit.lib.ObjectId)14 ArrayList (java.util.ArrayList)12 RobotComment (com.google.gerrit.reviewdb.client.RobotComment)11 Account (com.google.gerrit.reviewdb.client.Account)9 PatchLineComment (com.google.gerrit.reviewdb.client.PatchLineComment)8 ChangeNotesRevWalk (com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk)7 Map (java.util.Map)6 Note (org.eclipse.jgit.notes.Note)6 NoteMap (org.eclipse.jgit.notes.NoteMap)6 RevWalk (org.eclipse.jgit.revwalk.RevWalk)6 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)4 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)4