Search in sources :

Example 1 with ChangeResource

use of com.google.gerrit.server.change.ChangeResource in project gerrit by GerritCodeReview.

the class StarredChanges method parse.

@Override
public AccountResource.StarredChange parse(AccountResource parent, IdString id) throws ResourceNotFoundException, OrmException {
    IdentifiedUser user = parent.getUser();
    ChangeResource change = changes.parse(TopLevelResource.INSTANCE, id);
    if (starredChangesUtil.getLabels(user.getAccountId(), change.getId()).contains(StarredChangesUtil.DEFAULT_LABEL)) {
        return new AccountResource.StarredChange(user, change);
    }
    throw new ResourceNotFoundException(id);
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 2 with ChangeResource

use of com.google.gerrit.server.change.ChangeResource in project gerrit by GerritCodeReview.

the class Stars method parse.

@Override
public Star parse(AccountResource parent, IdString id) throws ResourceNotFoundException, OrmException {
    IdentifiedUser user = parent.getUser();
    ChangeResource change = changes.parse(TopLevelResource.INSTANCE, id);
    Set<String> labels = starredChangesUtil.getLabels(user.getAccountId(), change.getId());
    return new AccountResource.Star(user, change, labels);
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource) Star(com.google.gerrit.server.account.AccountResource.Star) IdString(com.google.gerrit.extensions.restapi.IdString) IdentifiedUser(com.google.gerrit.server.IdentifiedUser)

Example 3 with ChangeResource

use of com.google.gerrit.server.change.ChangeResource in project gerrit by GerritCodeReview.

the class ChangeIT method addSelfAsReviewer.

@Test
public void addSelfAsReviewer() throws Exception {
    TestTimeUtil.resetWithClockStep(1, SECONDS);
    PushOneCommit.Result r = createChange();
    ChangeResource rsrc = parseResource(r);
    String oldETag = rsrc.getETag();
    Timestamp oldTs = rsrc.getChange().getLastUpdatedOn();
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    setApiUser(user);
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    // There should be no email notification when adding self
    assertThat(sender.getMessages()).isEmpty();
    // When NoteDb is enabled adding a reviewer records that user as reviewer
    // in NoteDb. When NoteDb is disabled adding a reviewer results in a dummy 0
    // approval on the change which is treated as CC when the ChangeInfo is
    // created.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.getId().get());
    // Ensure ETag and lastUpdatedOn are updated.
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
    assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with ChangeResource

use of com.google.gerrit.server.change.ChangeResource in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method parseCurrentRevisionResource.

protected RevisionResource parseCurrentRevisionResource(String changeId) throws Exception {
    ChangeResource cr = parseChangeResource(changeId);
    int psId = cr.getChange().currentPatchSetId().get();
    return revisions.parse(cr, IdString.fromDecoded(Integer.toString(psId)));
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource)

Example 5 with ChangeResource

use of com.google.gerrit.server.change.ChangeResource in project gerrit by GerritCodeReview.

the class ChangeIT method addReviewer.

@Test
public void addReviewer() throws Exception {
    TestTimeUtil.resetWithClockStep(1, SECONDS);
    PushOneCommit.Result r = createChange();
    ChangeResource rsrc = parseResource(r);
    String oldETag = rsrc.getETag();
    Timestamp oldTs = rsrc.getChange().getLastUpdatedOn();
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.emailAddress);
    assertThat(m.body()).contains("Hello " + user.fullName + ",\n");
    assertThat(m.body()).contains("I'd like you to do a code review.");
    assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
    assertMailReplyTo(m, admin.email);
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    // When NoteDb is enabled adding a reviewer records that user as reviewer
    // in NoteDb. When NoteDb is disabled adding a reviewer results in a dummy 0
    // approval on the change which is treated as CC when the ChangeInfo is
    // created.
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.getId().get());
    // Ensure ETag and lastUpdatedOn are updated.
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
    assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource) Message(com.google.gerrit.testutil.FakeEmailSender.Message) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ChangeResource (com.google.gerrit.server.change.ChangeResource)9 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)3 Timestamp (java.sql.Timestamp)3 Test (org.junit.Test)3 AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)2 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)2 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)2 IdString (com.google.gerrit.extensions.restapi.IdString)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)2 StarredChanges (com.google.gerrit.server.account.StarredChanges)2 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)2 ImmutableList (com.google.common.collect.ImmutableList)1 PermissionDeniedException (com.google.gerrit.common.errors.PermissionDeniedException)1 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)1 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)1 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)1 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)1