Search in sources :

Example 11 with NoteMap

use of org.eclipse.jgit.notes.NoteMap in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentsDeleteAllDraftsForOneRevision.

@Test
public void patchLineCommentsDeleteAllDraftsForOneRevision() throws Exception {
    Change c = newChange();
    String uuid = "uuid";
    ObjectId commitId1 = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
    ObjectId commitId2 = ObjectId.fromString("abcd4567abcd4567abcd4567abcd4567abcd4567");
    CommentRange range = new CommentRange(1, 1, 2, 1);
    PatchSet.Id ps1 = c.currentPatchSetId();
    String filename = "filename1";
    short side = (short) 1;
    ChangeUpdate update = newUpdate(c, otherUser);
    Instant now = TimeUtil.now();
    HumanComment comment1 = newComment(ps1, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps1", side, commitId1, false);
    update.setPatchSetId(ps1);
    update.putComment(HumanComment.Status.DRAFT, comment1);
    update.commit();
    incrementPatchSet(c);
    PatchSet.Id ps2 = c.currentPatchSetId();
    update = newUpdate(c, otherUser);
    now = TimeUtil.now();
    HumanComment comment2 = newComment(ps2, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps2", side, commitId2, false);
    update.setPatchSetId(ps2);
    update.putComment(HumanComment.Status.DRAFT, comment2);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).hasSize(2);
    update = newUpdate(c, otherUser);
    update.setPatchSetId(ps2);
    update.deleteComment(comment2);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).hasSize(1);
    NoteMap noteMap = notes.getDraftCommentNotes().getNoteMap();
    assertThat(noteMap.contains(commitId1)).isTrue();
    assertThat(noteMap.contains(commitId2)).isFalse();
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) Instant(java.time.Instant) CommentRange(com.google.gerrit.entities.CommentRange) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) NoteMap(org.eclipse.jgit.notes.NoteMap) HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Example 12 with NoteMap

use of org.eclipse.jgit.notes.NoteMap in project gerrit by GerritCodeReview.

the class ExternalIdIT method insertExternalIdWithInvalidConfig.

private String insertExternalIdWithInvalidConfig(Repository repo, RevWalk rw, String externalId) throws IOException {
    ObjectId rev = ExternalIdReader.readRevision(repo);
    NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);
    try (ObjectInserter ins = repo.newObjectInserter()) {
        ObjectId noteId = ExternalId.Key.parse(externalId).sha1();
        byte[] raw = "bad-config".getBytes(UTF_8);
        ObjectId dataBlob = ins.insert(OBJ_BLOB, raw);
        noteMap.set(noteId, dataBlob);
        ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, "Add external ID", admin.getIdent(), admin.getIdent());
        return noteId.getName();
    }
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ObjectId(org.eclipse.jgit.lib.ObjectId) NoteMap(org.eclipse.jgit.notes.NoteMap)

Example 13 with NoteMap

use of org.eclipse.jgit.notes.NoteMap in project gerrit by GerritCodeReview.

the class ExternalIdIT method insertExternalIdWithKeyThatDoesntMatchNoteId.

private String insertExternalIdWithKeyThatDoesntMatchNoteId(Repository repo, RevWalk rw, String externalId) throws IOException {
    ObjectId rev = ExternalIdReader.readRevision(repo);
    NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);
    ExternalId extId = ExternalId.create(ExternalId.Key.parse(externalId), admin.id);
    try (ObjectInserter ins = repo.newObjectInserter()) {
        ObjectId noteId = ExternalId.Key.parse(externalId + "x").sha1();
        Config c = new Config();
        extId.writeToConfig(c);
        byte[] raw = c.toText().getBytes(UTF_8);
        ObjectId dataBlob = ins.insert(OBJ_BLOB, raw);
        noteMap.set(noteId, dataBlob);
        ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, "Add external ID", admin.getIdent(), admin.getIdent());
        return noteId.getName();
    }
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ObjectId(org.eclipse.jgit.lib.ObjectId) Config(org.eclipse.jgit.lib.Config) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) NoteMap(org.eclipse.jgit.notes.NoteMap)

Example 14 with NoteMap

use of org.eclipse.jgit.notes.NoteMap in project gerrit by GerritCodeReview.

the class ExternalIdIT method insertExternalIdWithoutAccountId.

private String insertExternalIdWithoutAccountId(Repository repo, RevWalk rw, String externalId) throws IOException {
    ObjectId rev = ExternalIdReader.readRevision(repo);
    NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);
    ExternalId extId = ExternalId.create(ExternalId.Key.parse(externalId), admin.id);
    try (ObjectInserter ins = repo.newObjectInserter()) {
        ObjectId noteId = extId.key().sha1();
        Config c = new Config();
        extId.writeToConfig(c);
        c.unset("externalId", extId.key().get(), "accountId");
        byte[] raw = c.toText().getBytes(UTF_8);
        ObjectId dataBlob = ins.insert(OBJ_BLOB, raw);
        noteMap.set(noteId, dataBlob);
        ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, "Add external ID", admin.getIdent(), admin.getIdent());
        return noteId.getName();
    }
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ObjectId(org.eclipse.jgit.lib.ObjectId) Config(org.eclipse.jgit.lib.Config) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) NoteMap(org.eclipse.jgit.notes.NoteMap)

Example 15 with NoteMap

use of org.eclipse.jgit.notes.NoteMap in project gerrit by GerritCodeReview.

the class ExternalIdIT method insertExternalIdWithEmptyNote.

private String insertExternalIdWithEmptyNote(Repository repo, RevWalk rw, String externalId) throws IOException {
    ObjectId rev = ExternalIdReader.readRevision(repo);
    NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);
    try (ObjectInserter ins = repo.newObjectInserter()) {
        ObjectId noteId = ExternalId.Key.parse(externalId).sha1();
        byte[] raw = "".getBytes(UTF_8);
        ObjectId dataBlob = ins.insert(OBJ_BLOB, raw);
        noteMap.set(noteId, dataBlob);
        ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, "Add external ID", admin.getIdent(), admin.getIdent());
        return noteId.getName();
    }
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ObjectId(org.eclipse.jgit.lib.ObjectId) NoteMap(org.eclipse.jgit.notes.NoteMap)

Aggregations

NoteMap (org.eclipse.jgit.notes.NoteMap)29 ObjectId (org.eclipse.jgit.lib.ObjectId)23 RevWalk (org.eclipse.jgit.revwalk.RevWalk)15 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)11 Repository (org.eclipse.jgit.lib.Repository)9 Note (org.eclipse.jgit.notes.Note)9 IOException (java.io.IOException)8 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)7 ObjectReader (org.eclipse.jgit.lib.ObjectReader)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 Ref (org.eclipse.jgit.lib.Ref)5 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)4 ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)3 AllUsersName (com.google.gerrit.server.config.AllUsersName)3 Inject (com.google.inject.Inject)3 Singleton (com.google.inject.Singleton)3 ListMultimap (com.google.common.collect.ListMultimap)2 MultimapBuilder (com.google.common.collect.MultimapBuilder)2 AccountGroup (com.google.gerrit.entities.AccountGroup)2 GroupReference (com.google.gerrit.entities.GroupReference)2