ChangeNotes: add past assignees

To enable finding all users that have been assigned to a change.

Change-Id: Idc2929b198ecb5800a4d32e06d096f586b6460ad
This commit is contained in:
Sven Selberg
2016-09-21 14:37:45 +02:00
parent 076b5c8309
commit bed1f41ac9
4 changed files with 58 additions and 12 deletions

View File

@@ -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());

View File

@@ -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());
}
}
}

View File

@@ -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();