Add message to change created via cherry pick

When a new change is created as a result of cherry picking, add
a message on the change:

 "Patch Set <number>: Cherry Picked from branch <name>."

Extend the acceptance test to verify that it works as expected.

Change-Id: I7d210dfa0d04d75e24d03297c36a22fd8f83ee1d
This commit is contained in:
David Pursehouse 2015-02-04 14:44:00 +09:00
parent 7adaa2c789
commit 62ee316ede
2 changed files with 33 additions and 4 deletions

View File

@ -169,6 +169,11 @@ public class RevisionIT extends AbstractDaemonTest {
origIt.next();
assertThat(origIt.next().message).isEqualTo(expectedMessage);
assertThat((Iterable<?>)cherry.get().messages).hasSize(1);
Iterator<ChangeMessageInfo> cherryIt = cherry.get().messages.iterator();
expectedMessage = "Patch Set 1: Cherry Picked from branch master.";
assertThat(cherryIt.next().message).isEqualTo(expectedMessage);
assertThat(cherry.get().subject).contains(in.message);
assertThat(cherry.get().topic).isEqualTo("someTopic");
cherry.current().review(ReviewInput.approve());

View File

@ -193,14 +193,17 @@ public class CherryPickChange {
} else {
// Change key not found on destination branch. We can create a new
// change.
Change.Id newChange = createNewChange(git, revWalk, changeKey, project,
Change newChange = createNewChange(git, revWalk, changeKey, project,
destRef, cherryPickCommit, refControl,
identifiedUser, change.getTopic());
addMessageToSourceChange(change, patch.getId(), destinationBranch,
cherryPickCommit, identifiedUser, refControl);
return newChange;
addMessageToDestinationChange(newChange, change.getDest().getShortName(),
identifiedUser, refControl);
return newChange.getId();
}
} finally {
revWalk.release();
@ -229,7 +232,7 @@ public class CherryPickChange {
return change.getId();
}
private Change.Id createNewChange(Repository git, RevWalk revWalk,
private Change createNewChange(Repository git, RevWalk revWalk,
Change.Key changeKey, Project.NameKey project,
Ref destRef, RevCommit cherryPickCommit, RefControl refControl,
IdentifiedUser identifiedUser, String topic)
@ -269,7 +272,7 @@ public class CherryPickChange {
ins.insert();
return change.getId();
return change;
}
private void addMessageToSourceChange(Change change, PatchSet.Id patchSetId,
@ -293,4 +296,25 @@ public class CherryPickChange {
ChangeUpdate update = updateFactory.create(ctl, change.getCreatedOn());
changeMessagesUtil.addChangeMessage(db.get(), update, changeMessage);
}
private void addMessageToDestinationChange(Change change, String sourceBranch,
IdentifiedUser identifiedUser, RefControl refControl) throws OrmException {
PatchSet.Id patchSetId =
db.get().patchSets().get(change.currentPatchSetId()).getId();
ChangeMessage changeMessage = new ChangeMessage(
new ChangeMessage.Key(
patchSetId.getParentKey(), ChangeUtil.messageUUID(db.get())),
identifiedUser.getAccountId(), TimeUtil.nowTs(), patchSetId);
StringBuilder sb = new StringBuilder("Patch Set ")
.append(patchSetId.get())
.append(": Cherry Picked from branch ")
.append(sourceBranch)
.append(".");
changeMessage.setMessage(sb.toString());
ChangeControl ctl = refControl.getProjectControl().controlFor(change);
ChangeUpdate update = updateFactory.create(ctl, change.getCreatedOn());
changeMessagesUtil.addChangeMessage(db.get(), update, changeMessage);
}
}