Store topic of a change in Notedb

This adds a 'Topic' footer to  the commit messages of the
refs/changes/XX/YYYY/meta notes branch when the topic changes.

Similar as for hashtags we cannot rebuild the history for topic
changes since the database only stores the current topic.

Change-Id: I5ca2c1ed6326ba03dfbee21f1a7d2328b73ad322
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2015-10-21 18:16:14 +02:00
parent 232c18da1b
commit aa0a3f93a0
9 changed files with 105 additions and 2 deletions

View File

@@ -102,6 +102,7 @@ import com.google.gerrit.server.edit.ChangeEdit;
import com.google.gerrit.server.edit.ChangeEditUtil;
import com.google.gerrit.server.events.CommitReceivedEvent;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
import com.google.gerrit.server.git.MultiProgressMonitor.Task;
import com.google.gerrit.server.git.validators.CommitValidationException;
import com.google.gerrit.server.git.validators.CommitValidationMessage;
@@ -1796,6 +1797,16 @@ public class ReceiveCommits {
ins.getChange().getId(),
hashtagsFactory.create(new HashtagsInput(magicBranch.hashtags))
.setRunHooks(false));
if (!Strings.isNullOrEmpty(magicBranch.topic)) {
bu.addOp(
ins.getChange().getId(),
new BatchUpdate.Op() {
@Override
public void updateChange(ChangeContext ctx) throws Exception {
ctx.getChangeUpdate().setTopic(magicBranch.topic);
}
});
}
}
bu.execute();
}
@@ -2242,11 +2253,15 @@ public class ReceiveCommits {
recipients.add(magicBranch.getMailRecipients());
approvals = magicBranch.labels;
Set<String> hashtags = magicBranch.hashtags;
ChangeNotes notes = changeCtl.getNotes().load();
if (!hashtags.isEmpty()) {
ChangeNotes notes = changeCtl.getNotes().load();
hashtags.addAll(notes.getHashtags());
update.setHashtags(hashtags);
}
if (magicBranch.topic != null
&& !magicBranch.topic.equals(notes.getChange().getTopic())) {
update.setTopic(magicBranch.topic);
}
}
recipients.add(getRecipientsFromFooters(accountResolver, newPatchSet, footerLines));
recipients.remove(me);