ChangeNotes: add past assignees
To enable finding all users that have been assigned to a change. Change-Id: Idc2929b198ecb5800a4d32e06d096f586b6460ad
This commit is contained in:
@@ -395,8 +395,16 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a ImmutableSet of all hashtags for this change sorted in alphabetical order.
|
||||
* @return an ImmutableSet of Account.Ids of all users that have been assigned
|
||||
* to this change.
|
||||
*/
|
||||
public ImmutableSet<Account.Id> getPastAssignees() {
|
||||
return state.pastAssignees();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a ImmutableSet of all hashtags for this change sorted in
|
||||
* alphabetical order.
|
||||
*/
|
||||
public ImmutableSet<String> getHashtags() {
|
||||
return ImmutableSortedSet.copyOf(state.hashtags());
|
||||
|
||||
@@ -138,6 +138,7 @@ class ChangeNotesParser {
|
||||
private Change.Status status;
|
||||
private String topic;
|
||||
private Optional<Account.Id> assignee;
|
||||
private List<Account.Id> pastAssignees;
|
||||
private Set<String> hashtags;
|
||||
private Timestamp createdOn;
|
||||
private Timestamp lastUpdatedOn;
|
||||
@@ -186,6 +187,7 @@ class ChangeNotesParser {
|
||||
parseNotes();
|
||||
allPastReviewers.addAll(reviewers.rowKeySet());
|
||||
pruneReviewers();
|
||||
|
||||
updatePatchSetStates();
|
||||
checkMandatoryFooters();
|
||||
}
|
||||
@@ -213,6 +215,7 @@ class ChangeNotesParser {
|
||||
status,
|
||||
|
||||
assignee != null ? assignee.orNull() : null,
|
||||
Sets.newLinkedHashSet(Lists.reverse(pastAssignees)),
|
||||
hashtags,
|
||||
patchSets,
|
||||
buildApprovals(),
|
||||
@@ -480,18 +483,25 @@ class ChangeNotesParser {
|
||||
|
||||
private void parseAssignee(ChangeNotesCommit commit)
|
||||
throws ConfigInvalidException {
|
||||
if (assignee != null) {
|
||||
return;
|
||||
if (pastAssignees == null) {
|
||||
pastAssignees = Lists.newArrayList();
|
||||
}
|
||||
String assigneeValue = parseOneFooter(commit, FOOTER_ASSIGNEE);
|
||||
if (assigneeValue == null){
|
||||
//footer not found
|
||||
} else if (assigneeValue.equals("")) {
|
||||
// empty footer found, assignee deleted
|
||||
assignee = Optional.absent();
|
||||
} else {
|
||||
PersonIdent ident = RawParseUtils.parsePersonIdent(assigneeValue);
|
||||
assignee = Optional.fromNullable(noteUtil.parseIdent(ident, id));
|
||||
if (assigneeValue != null) {
|
||||
Optional<Account.Id> parsedAssignee;
|
||||
if (assigneeValue.equals("")) {
|
||||
// Empty footer found, assignee deleted
|
||||
parsedAssignee = Optional.absent();
|
||||
} else {
|
||||
PersonIdent ident = RawParseUtils.parsePersonIdent(assigneeValue);
|
||||
parsedAssignee = Optional.fromNullable(noteUtil.parseIdent(ident, id));
|
||||
}
|
||||
if (assignee == null) {
|
||||
assignee = parsedAssignee;
|
||||
}
|
||||
if (parsedAssignee.isPresent()) {
|
||||
pastAssignees.add(parsedAssignee.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ public abstract class ChangeNotesState {
|
||||
change.getId(),
|
||||
null,
|
||||
null,
|
||||
ImmutableSet.<Account.Id>of(),
|
||||
ImmutableSet.<String>of(),
|
||||
ImmutableSortedMap.<PatchSet.Id, PatchSet>of(),
|
||||
ImmutableListMultimap.<PatchSet.Id, PatchSetApproval>of(),
|
||||
@@ -86,6 +87,7 @@ public abstract class ChangeNotesState {
|
||||
@Nullable String submissionId,
|
||||
@Nullable Change.Status status,
|
||||
@Nullable Account.Id assignee,
|
||||
@Nullable Set<Account.Id> pastAssignees,
|
||||
@Nullable Set<String> hashtags,
|
||||
Map<PatchSet.Id, PatchSet> patchSets,
|
||||
Multimap<PatchSet.Id, PatchSetApproval> approvals,
|
||||
@@ -114,6 +116,7 @@ public abstract class ChangeNotesState {
|
||||
submissionId,
|
||||
status),
|
||||
assignee,
|
||||
ImmutableSet.copyOf(pastAssignees),
|
||||
ImmutableSet.copyOf(hashtags),
|
||||
ImmutableSortedMap.copyOf(patchSets, comparing(PatchSet.Id::get)),
|
||||
ImmutableListMultimap.copyOf(approvals),
|
||||
@@ -157,6 +160,7 @@ public abstract class ChangeNotesState {
|
||||
|
||||
// Other related to this Change.
|
||||
@Nullable abstract Account.Id assignee();
|
||||
abstract ImmutableSet<Account.Id> pastAssignees();
|
||||
abstract ImmutableSet<String> hashtags();
|
||||
abstract ImmutableSortedMap<PatchSet.Id, PatchSet> patchSets();
|
||||
abstract ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals();
|
||||
|
||||
@@ -600,7 +600,31 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
|
||||
notes = newNotes(c);
|
||||
assertThat(notes.getAssignee().get()).isEqualTo(changeOwner.getAccountId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pastAssigneesChangeNotes() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.setAssignee(Optional.fromNullable(otherUserId));
|
||||
update.commit();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.setAssignee(Optional.fromNullable(changeOwner.getAccountId()));
|
||||
update.commit();
|
||||
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.setAssignee(Optional.fromNullable(otherUserId));
|
||||
update.commit();
|
||||
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.setAssignee(Optional.absent());
|
||||
update.commit();
|
||||
|
||||
notes = newNotes(c);
|
||||
assertThat(notes.getPastAssignees()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user