ReviewerApi: Add method to remove the reviewer
Change-Id: I7ad74f64a3b17d5f5209bedf7c8afb4b907146ba
This commit is contained in:
@@ -520,6 +520,7 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void addReviewer() throws Exception {
|
||||
TestTimeUtil.resetWithClockStep(1, SECONDS);
|
||||
sender.clear();
|
||||
PushOneCommit.Result r = createChange();
|
||||
ChangeResource rsrc = parseResource(r);
|
||||
String oldETag = rsrc.getETag();
|
||||
@@ -646,6 +647,49 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
assertThat(m).containsEntry("Code-Review", Short.valueOf((short)-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeReviewer() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
String changeId = r.getChangeId();
|
||||
gApi.changes()
|
||||
.id(changeId)
|
||||
.revision(r.getCommit().name())
|
||||
.review(ReviewInput.approve());
|
||||
|
||||
setApiUser(user);
|
||||
gApi.changes()
|
||||
.id(changeId)
|
||||
.revision(r.getCommit().name())
|
||||
.review(ReviewInput.recommend());
|
||||
|
||||
Collection<AccountInfo> reviewers = gApi.changes()
|
||||
.id(changeId)
|
||||
.get()
|
||||
.reviewers.get(REVIEWER);
|
||||
|
||||
assertThat(reviewers).hasSize(2);
|
||||
Iterator<AccountInfo> reviewerIt = reviewers.iterator();
|
||||
assertThat(reviewerIt.next()._accountId)
|
||||
.isEqualTo(admin.getId().get());
|
||||
assertThat(reviewerIt.next()._accountId)
|
||||
.isEqualTo(user.getId().get());
|
||||
|
||||
setApiUser(admin);
|
||||
gApi.changes()
|
||||
.id(changeId)
|
||||
.reviewer(user.getId().toString())
|
||||
.remove();
|
||||
|
||||
reviewers = gApi.changes()
|
||||
.id(changeId)
|
||||
.get()
|
||||
.reviewers.get(REVIEWER);
|
||||
assertThat(reviewers).hasSize(1);
|
||||
reviewerIt = reviewers.iterator();
|
||||
assertThat(reviewerIt.next()._accountId)
|
||||
.isEqualTo(admin.getId().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteVote() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
|
||||
@@ -23,6 +23,7 @@ public interface ReviewerApi {
|
||||
|
||||
Map<String, Short> votes() throws RestApiException;
|
||||
void deleteVote(String label) throws RestApiException;
|
||||
void remove() throws RestApiException;
|
||||
|
||||
/**
|
||||
* A default implementation which allows source compatibility
|
||||
@@ -38,5 +39,10 @@ public interface ReviewerApi {
|
||||
public void deleteVote(String label) throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.google.gerrit.server.api.changes;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.ReviewerApi;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.DeleteReviewer;
|
||||
import com.google.gerrit.server.change.DeleteVote;
|
||||
import com.google.gerrit.server.change.ReviewerResource;
|
||||
import com.google.gerrit.server.change.VoteResource;
|
||||
@@ -35,13 +36,16 @@ public class ReviewerApiImpl implements ReviewerApi {
|
||||
private final ReviewerResource reviewer;
|
||||
private final Votes.List listVotes;
|
||||
private final DeleteVote deleteVote;
|
||||
private final DeleteReviewer deleteReviewer;
|
||||
|
||||
@Inject
|
||||
ReviewerApiImpl(Votes.List listVotes,
|
||||
DeleteVote deleteVote,
|
||||
DeleteReviewer deleteReviewer,
|
||||
@Assisted ReviewerResource reviewer) {
|
||||
this.listVotes = listVotes;
|
||||
this.deleteVote = deleteVote;
|
||||
this.deleteReviewer = deleteReviewer;
|
||||
this.reviewer = reviewer;
|
||||
}
|
||||
|
||||
@@ -62,4 +66,13 @@ public class ReviewerApiImpl implements ReviewerApi {
|
||||
throw new RestApiException("Cannot delete vote", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() throws RestApiException {
|
||||
try {
|
||||
deleteReviewer.apply(reviewer, null);
|
||||
} catch (UpdateException e) {
|
||||
throw new RestApiException("Cannot remove reviewer", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user