ChangeApi: Implement get/put topic
Change-Id: I8e76f05d52f486b85cb905f7a4bff95966faae79
This commit is contained in:
@@ -278,4 +278,24 @@ public class ChangeIT extends AbstractDaemonTest {
|
|||||||
revision(r).review(ReviewInput.recommend());
|
revision(r).review(ReviewInput.recommend());
|
||||||
assertTrue(get(r.getChangeId()).reviewed);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,9 @@ public interface ChangeApi {
|
|||||||
ChangeApi revert() throws RestApiException;
|
ChangeApi revert() throws RestApiException;
|
||||||
ChangeApi revert(RevertInput in) 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(AddReviewerInput in) throws RestApiException;
|
||||||
void addReviewer(String in) throws RestApiException;
|
void addReviewer(String in) throws RestApiException;
|
||||||
|
|
||||||
@@ -102,6 +105,16 @@ public interface ChangeApi {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String topic() throws RestApiException {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void topic(String topic) throws RestApiException {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addReviewer(AddReviewerInput in) throws RestApiException {
|
public void addReviewer(AddReviewerInput in) throws RestApiException {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@@ -29,7 +29,9 @@ import com.google.gerrit.extensions.restapi.RestApiException;
|
|||||||
import com.google.gerrit.server.change.Abandon;
|
import com.google.gerrit.server.change.Abandon;
|
||||||
import com.google.gerrit.server.change.ChangeJson;
|
import com.google.gerrit.server.change.ChangeJson;
|
||||||
import com.google.gerrit.server.change.ChangeResource;
|
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.PostReviewers;
|
||||||
|
import com.google.gerrit.server.change.PutTopic;
|
||||||
import com.google.gerrit.server.change.Restore;
|
import com.google.gerrit.server.change.Restore;
|
||||||
import com.google.gerrit.server.change.Revert;
|
import com.google.gerrit.server.change.Revert;
|
||||||
import com.google.gerrit.server.change.Revisions;
|
import com.google.gerrit.server.change.Revisions;
|
||||||
@@ -53,6 +55,8 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
|
|||||||
private final Abandon abandon;
|
private final Abandon abandon;
|
||||||
private final Revert revert;
|
private final Revert revert;
|
||||||
private final Restore restore;
|
private final Restore restore;
|
||||||
|
private final GetTopic getTopic;
|
||||||
|
private final PutTopic putTopic;
|
||||||
private final Provider<PostReviewers> postReviewers;
|
private final Provider<PostReviewers> postReviewers;
|
||||||
private final Provider<ChangeJson> changeJson;
|
private final Provider<ChangeJson> changeJson;
|
||||||
|
|
||||||
@@ -63,6 +67,8 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
|
|||||||
Abandon abandon,
|
Abandon abandon,
|
||||||
Revert revert,
|
Revert revert,
|
||||||
Restore restore,
|
Restore restore,
|
||||||
|
GetTopic getTopic,
|
||||||
|
PutTopic putTopic,
|
||||||
Provider<PostReviewers> postReviewers,
|
Provider<PostReviewers> postReviewers,
|
||||||
Provider<ChangeJson> changeJson,
|
Provider<ChangeJson> changeJson,
|
||||||
@Assisted ChangeResource change) {
|
@Assisted ChangeResource change) {
|
||||||
@@ -72,6 +78,8 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
|
|||||||
this.revisionApi = revisionApi;
|
this.revisionApi = revisionApi;
|
||||||
this.abandon = abandon;
|
this.abandon = abandon;
|
||||||
this.restore = restore;
|
this.restore = restore;
|
||||||
|
this.getTopic = getTopic;
|
||||||
|
this.putTopic = putTopic;
|
||||||
this.postReviewers = postReviewers;
|
this.postReviewers = postReviewers;
|
||||||
this.changeJson = changeJson;
|
this.changeJson = changeJson;
|
||||||
this.change = change;
|
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
|
@Override
|
||||||
public void addReviewer(String reviewer) throws RestApiException {
|
public void addReviewer(String reviewer) throws RestApiException {
|
||||||
AddReviewerInput in = new AddReviewerInput();
|
AddReviewerInput in = new AddReviewerInput();
|
||||||
|
@@ -19,7 +19,7 @@ import com.google.gerrit.extensions.restapi.RestReadView;
|
|||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class GetTopic implements RestReadView<ChangeResource> {
|
public class GetTopic implements RestReadView<ChangeResource> {
|
||||||
@Override
|
@Override
|
||||||
public String apply(ChangeResource rsrc) {
|
public String apply(ChangeResource rsrc) {
|
||||||
return Strings.nullToEmpty(rsrc.getChange().getTopic());
|
return Strings.nullToEmpty(rsrc.getChange().getTopic());
|
||||||
|
@@ -42,7 +42,7 @@ import com.google.inject.Singleton;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class PutTopic implements RestModifyView<ChangeResource, Input>,
|
public class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||||
UiAction<ChangeResource> {
|
UiAction<ChangeResource> {
|
||||||
private final Provider<ReviewDb> dbProvider;
|
private final Provider<ReviewDb> dbProvider;
|
||||||
private final ChangeIndexer indexer;
|
private final ChangeIndexer indexer;
|
||||||
@@ -50,9 +50,9 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
|
|||||||
private final ChangeUpdate.Factory updateFactory;
|
private final ChangeUpdate.Factory updateFactory;
|
||||||
private final ChangeMessagesUtil cmUtil;
|
private final ChangeMessagesUtil cmUtil;
|
||||||
|
|
||||||
static class Input {
|
public static class Input {
|
||||||
@DefaultInput
|
@DefaultInput
|
||||||
String topic;
|
public String topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
Reference in New Issue
Block a user