Search in sources :

Example 1 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class CommentsIT method getChangeSortedComments.

private List<CommentInfo> getChangeSortedComments(String changeId) throws Exception {
    List<CommentInfo> comments = new ArrayList<>();
    Map<String, List<CommentInfo>> commentsMap = getPublishedComments(changeId);
    for (Entry<String, List<CommentInfo>> e : commentsMap.entrySet()) {
        for (CommentInfo c : e.getValue()) {
            // Set the comment's path field.
            c.path = e.getKey();
            comments.add(c);
        }
    }
    comments.sort(Comparator.comparing(c -> c.id));
    return comments;
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Arrays(java.util.Arrays) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Matcher(java.util.regex.Matcher) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) DraftHandling(com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling) Side(com.google.gerrit.extensions.client.Side) NoteMap(org.eclipse.jgit.notes.NoteMap) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) Function(com.google.common.base.Function) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) ImmutableMap(com.google.common.collect.ImmutableMap) Timestamp(java.sql.Timestamp) ChangeNoteUtil(com.google.gerrit.server.notedb.ChangeNoteUtil) AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) PostReview(com.google.gerrit.server.change.PostReview) Collectors(java.util.stream.Collectors) TopLevelResource(com.google.gerrit.extensions.restapi.TopLevelResource) NoHttpd(com.google.gerrit.acceptance.NoHttpd) List(java.util.List) RefNames(com.google.gerrit.reviewdb.client.RefNames) Ref(org.eclipse.jgit.lib.Ref) Entry(java.util.Map.Entry) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Iterables(com.google.common.collect.Iterables) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Change(com.google.gerrit.reviewdb.client.Change) ChangesCollection(com.google.gerrit.server.change.ChangesCollection) Message(com.google.gerrit.testutil.FakeEmailSender.Message) IdString(com.google.gerrit.extensions.restapi.IdString) Patch(com.google.gerrit.reviewdb.client.Patch) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) Comment(com.google.gerrit.extensions.client.Comment) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ChangeResource(com.google.gerrit.server.change.ChangeResource) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Before(org.junit.Before) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) FakeEmailSender(com.google.gerrit.testutil.FakeEmailSender) DeleteCommentRewriter(com.google.gerrit.server.notedb.DeleteCommentRewriter) Provider(com.google.inject.Provider) RevisionResource(com.google.gerrit.server.change.RevisionResource) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Comparator(java.util.Comparator) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Repository(org.eclipse.jgit.lib.Repository) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) IdString(com.google.gerrit.extensions.restapi.IdString)

Example 2 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class ChangeRebuilderIT method resolveCommentsInheritsValueFromParentWhenUnspecified.

@Test
public void resolveCommentsInheritsValueFromParentWhenUnspecified() throws Exception {
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getPatchSetId().getParentKey();
    putDraft(user, id, 1, "comment", true);
    putDraft(user, id, 1, "newComment", null);
    Map<String, List<CommentInfo>> comments = gApi.changes().id(id.get()).current().drafts();
    for (List<CommentInfo> cList : comments.values()) {
        for (CommentInfo ci : cList) {
            assertThat(ci.unresolved).isEqualTo(true);
        }
    }
}
Also used : List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) Change(com.google.gerrit.reviewdb.client.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class MailProcessorIT method parseAndPersistChangeMessage.

@Test
public void parseAndPersistChangeMessage() throws Exception {
    String changeId = createChangeWithReview();
    ChangeInfo changeInfo = gApi.changes().id(changeId).get();
    List<CommentInfo> comments = gApi.changes().id(changeId).current().commentsAsList();
    String ts = MailUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(comments.get(0).updated.toInstant(), ZoneId.of("UTC")));
    // Build Message
    MailMessage.Builder b = messageBuilderWithDefaultFields();
    String txt = newPlaintextBody(canonicalWebUrl.get() + "#/c/" + changeInfo._number + "/1", "Test Message", null, null, null);
    b.textContent(txt + textFooterForChange(changeId, ts));
    mailProcessor.process(b.build());
    Collection<ChangeMessageInfo> messages = gApi.changes().id(changeId).get().messages;
    assertThat(messages).hasSize(3);
    assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\n\nTest Message");
    assertThat(Iterables.getLast(messages).tag).isEqualTo("mailMessageId=some id");
}
Also used : MailMessage(com.google.gerrit.server.mail.receive.MailMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test)

Example 4 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class ChangeApiImpl method draftsRequest.

@Override
public DraftsRequest draftsRequest() {
    return new DraftsRequest() {

        @Override
        public Map<String, List<CommentInfo>> get() throws RestApiException {
            try {
                ListChangeDrafts listDrafts = listDraftsProvider.get();
                listDrafts.setContext(this.getContext());
                listDrafts.setContextPadding(this.getContextPadding());
                return listDrafts.apply(change).value();
            } catch (Exception e) {
                throw asRestApiException("Cannot get drafts", e);
            }
        }

        @Override
        public List<CommentInfo> getAsList() throws RestApiException {
            try {
                ListChangeDrafts listDrafts = listDraftsProvider.get();
                listDrafts.setContext(this.getContext());
                listDrafts.setContextPadding(this.getContextPadding());
                return listDrafts.getComments(change);
            } catch (Exception e) {
                throw asRestApiException("Cannot get drafts", e);
            }
        }
    };
}
Also used : List(java.util.List) IdString(com.google.gerrit.extensions.restapi.IdString) ListChangeDrafts(com.google.gerrit.server.restapi.change.ListChangeDrafts) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) IllegalLabelException(com.google.gerrit.server.StarredChangesUtil.IllegalLabelException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) StorageException(com.google.gerrit.exceptions.StorageException) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 5 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class ChangeApiImpl method commentsRequest.

@Override
public CommentsRequest commentsRequest() {
    return new CommentsRequest() {

        @Override
        public Map<String, List<CommentInfo>> get() throws RestApiException {
            try {
                ListChangeComments listComments = listCommentsProvider.get();
                listComments.setContext(this.getContext());
                listComments.setContextPadding(this.getContextPadding());
                return listComments.apply(change).value();
            } catch (Exception e) {
                throw asRestApiException("Cannot get comments", e);
            }
        }

        @Override
        public List<CommentInfo> getAsList() throws RestApiException {
            try {
                ListChangeComments listComments = listCommentsProvider.get();
                listComments.setContext(this.getContext());
                listComments.setContextPadding(this.getContextPadding());
                return listComments.getComments(change);
            } catch (Exception e) {
                throw asRestApiException("Cannot get comments", e);
            }
        }
    };
}
Also used : ListChangeComments(com.google.gerrit.server.restapi.change.ListChangeComments) List(java.util.List) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) IllegalLabelException(com.google.gerrit.server.StarredChangesUtil.IllegalLabelException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) StorageException(com.google.gerrit.exceptions.StorageException) CmdLineException(org.kohsuke.args4j.CmdLineException)

Aggregations

CommentInfo (com.google.gerrit.extensions.common.CommentInfo)186 Test (org.junit.Test)178 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)164 Change (com.google.gerrit.entities.Change)120 PatchSet (com.google.gerrit.entities.PatchSet)62 RobotCommentInfo (com.google.gerrit.extensions.common.RobotCommentInfo)56 List (java.util.List)51 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)47 ImmutableList (com.google.common.collect.ImmutableList)46 IdString (com.google.gerrit.extensions.restapi.IdString)34 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)27 ArrayList (java.util.ArrayList)26 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)25 Collectors.toList (java.util.stream.Collectors.toList)25 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)24 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)22 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)21 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)20 CommentInfoSubject.assertThatList (com.google.gerrit.extensions.common.testing.CommentInfoSubject.assertThatList)19 MailMessage (com.google.gerrit.mail.MailMessage)13