ChangeApi: Implement get/put topic

Change-Id: I8e76f05d52f486b85cb905f7a4bff95966faae79
This commit is contained in:
Dave Borowitz
2014-08-11 16:08:28 -07:00
parent 3e377a1a40
commit d112bcf08f
5 changed files with 61 additions and 4 deletions

View File

@@ -278,4 +278,24 @@ public class ChangeIT extends AbstractDaemonTest {
revision(r).review(ReviewInput.recommend());
assertTrue(get(r.getChangeId()).reviewed);
}
@Test
public void topic() throws Exception {
PushOneCommit.Result r = createChange();
assertEquals("", gApi.changes()
.id(r.getChangeId())
.topic());
gApi.changes()
.id(r.getChangeId())
.topic("mytopic");
assertEquals("mytopic", gApi.changes()
.id(r.getChangeId())
.topic());
gApi.changes()
.id(r.getChangeId())
.topic("");
assertEquals("", gApi.changes()
.id(r.getChangeId())
.topic());
}
}

View File

@@ -37,6 +37,9 @@ public interface ChangeApi {
ChangeApi revert() throws RestApiException;
ChangeApi revert(RevertInput in) throws RestApiException;
String topic() throws RestApiException;
void topic(String topic) throws RestApiException;
void addReviewer(AddReviewerInput in) throws RestApiException;
void addReviewer(String in) throws RestApiException;
@@ -102,6 +105,16 @@ public interface ChangeApi {
throw new NotImplementedException();
}
@Override
public String topic() throws RestApiException {
throw new NotImplementedException();
}
@Override
public void topic(String topic) throws RestApiException {
throw new NotImplementedException();
}
@Override
public void addReviewer(AddReviewerInput in) throws RestApiException {
throw new NotImplementedException();

View File

@@ -29,7 +29,9 @@ import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.Abandon;
import com.google.gerrit.server.change.ChangeJson;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.GetTopic;
import com.google.gerrit.server.change.PostReviewers;
import com.google.gerrit.server.change.PutTopic;
import com.google.gerrit.server.change.Restore;
import com.google.gerrit.server.change.Revert;
import com.google.gerrit.server.change.Revisions;
@@ -53,6 +55,8 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
private final Abandon abandon;
private final Revert revert;
private final Restore restore;
private final GetTopic getTopic;
private final PutTopic putTopic;
private final Provider<PostReviewers> postReviewers;
private final Provider<ChangeJson> changeJson;
@@ -63,6 +67,8 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
Abandon abandon,
Revert revert,
Restore restore,
GetTopic getTopic,
PutTopic putTopic,
Provider<PostReviewers> postReviewers,
Provider<ChangeJson> changeJson,
@Assisted ChangeResource change) {
@@ -72,6 +78,8 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
this.revisionApi = revisionApi;
this.abandon = abandon;
this.restore = restore;
this.getTopic = getTopic;
this.putTopic = putTopic;
this.postReviewers = postReviewers;
this.changeJson = changeJson;
this.change = change;
@@ -144,6 +152,22 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
}
}
@Override
public String topic() throws RestApiException {
return getTopic.apply(change);
}
@Override
public void topic(String topic) throws RestApiException {
PutTopic.Input in = new PutTopic.Input();
in.topic = topic;
try {
putTopic.apply(change, in);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot set topic", e);
}
}
@Override
public void addReviewer(String reviewer) throws RestApiException {
AddReviewerInput in = new AddReviewerInput();

View File

@@ -19,7 +19,7 @@ import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.inject.Singleton;
@Singleton
class GetTopic implements RestReadView<ChangeResource> {
public class GetTopic implements RestReadView<ChangeResource> {
@Override
public String apply(ChangeResource rsrc) {
return Strings.nullToEmpty(rsrc.getChange().getTopic());

View File

@@ -42,7 +42,7 @@ import com.google.inject.Singleton;
import java.io.IOException;
@Singleton
class PutTopic implements RestModifyView<ChangeResource, Input>,
public class PutTopic implements RestModifyView<ChangeResource, Input>,
UiAction<ChangeResource> {
private final Provider<ReviewDb> dbProvider;
private final ChangeIndexer indexer;
@@ -50,9 +50,9 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
private final ChangeUpdate.Factory updateFactory;
private final ChangeMessagesUtil cmUtil;
static class Input {
public static class Input {
@DefaultInput
String topic;
public String topic;
}
@Inject