Add convenience methods for constructing approvals and messages

This saves a lot of boilerplate, nested key construction, ChangeUtil
usage, etc. Particularly in the case of ChangeMessage, we can usually
infer pretty much everything directly from the ChangeContext.

Change-Id: I93eb1e5f5c766b4f661bf21084760141b4d1db02
This commit is contained in:
Dave Borowitz
2016-10-05 17:23:32 -04:00
parent 76a0028397
commit 2e8857a18b
21 changed files with 106 additions and 199 deletions

View File

@@ -26,7 +26,6 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.change.PutTopic.Input;
import com.google.gerrit.server.extensions.events.TopicEdited;
import com.google.gerrit.server.git.BatchUpdate;
@@ -115,13 +114,7 @@ public class PutTopic implements RestModifyView<ChangeResource, Input>,
change.setTopic(Strings.emptyToNull(newTopicName));
update.setTopic(change.getTopic());
ChangeMessage cmsg = new ChangeMessage(
new ChangeMessage.Key(
change.getId(),
ChangeUtil.messageUUID(ctx.getDb())),
ctx.getAccountId(), ctx.getWhen(),
change.currentPatchSetId());
cmsg.setMessage(summary);
ChangeMessage cmsg = ChangeMessagesUtil.newMessage(ctx, summary);
cmUtil.addChangeMessage(ctx.getDb(), update, cmsg);
return true;
}