PatchSetInfoFactory: Use PatchSetUtil

Some public methods now need to take ChangeNotes. A significant
affected caller was ChangeHookRunner, which now needs to construct
notes on many event types. This might be able to be avoided if we
changed the ChangeHooks interface, but that is saved for later
cleanup.

Change-Id: Ia2f0b9b07bc9e32b8c010191d3a6c3bbf848a5d1
This commit is contained in:
Dave Borowitz
2016-01-19 12:55:50 -05:00
parent 0dfabcc1ac
commit 3a6dea327c
9 changed files with 87 additions and 54 deletions

View File

@@ -382,17 +382,17 @@ public class EventFactory {
public void addPatchSets(ReviewDb db, RevWalk revWalk, ChangeAttribute ca,
Collection<PatchSet> ps,
Map<PatchSet.Id, Collection<PatchSetApproval>> approvals,
boolean includeFiles, Change change, LabelTypes labelTypes) {
boolean includeFiles, ChangeNotes notes, LabelTypes labelTypes) {
if (!ps.isEmpty()) {
ca.patchSets = new ArrayList<>(ps.size());
for (PatchSet p : ps) {
PatchSetAttribute psa = asPatchSetAttribute(db, revWalk, p);
PatchSetAttribute psa = asPatchSetAttribute(db, revWalk, notes, p);
if (approvals != null) {
addApprovals(psa, p.getId(), approvals, labelTypes);
}
ca.patchSets.add(psa);
if (includeFiles && change != null) {
addPatchSetFileNames(psa, change, p);
if (includeFiles && notes != null) {
addPatchSetFileNames(psa, notes.getChange(), p);
}
}
}
@@ -452,9 +452,9 @@ public class EventFactory {
* @return object suitable for serialization to JSON
*/
public PatchSetAttribute asPatchSetAttribute(RevWalk revWalk,
PatchSet patchSet) {
ChangeNotes notes, PatchSet patchSet) {
try (ReviewDb db = schema.open()) {
return asPatchSetAttribute(db, revWalk, patchSet);
return asPatchSetAttribute(db, revWalk, notes, patchSet);
} catch (OrmException e) {
log.error("Cannot open database connection", e);
return new PatchSetAttribute();
@@ -470,7 +470,7 @@ public class EventFactory {
* @return object suitable for serialization to JSON
*/
public PatchSetAttribute asPatchSetAttribute(ReviewDb db, RevWalk revWalk,
PatchSet patchSet) {
ChangeNotes notes, PatchSet patchSet) {
PatchSetAttribute p = new PatchSetAttribute();
p.revision = patchSet.getRevision().get();
p.number = Integer.toString(patchSet.getPatchSetId());
@@ -486,7 +486,7 @@ public class EventFactory {
p.parents.add(parent.name());
}
UserIdentity author = psInfoFactory.get(db, pId).getAuthor();
UserIdentity author = psInfoFactory.get(db, notes, pId).getAuthor();
if (author.getAccount() == null) {
p.author = new AccountAttribute();
p.author.email = author.getEmail();