PostReview: update and insert comments/approvals in a single step
Conflicts: gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java Change-Id: Ieab4ac0628e397495bfd8a278c879f79817ba443
This commit is contained in:
parent
f67d09d96d
commit
3a20cefc4b
@ -348,16 +348,14 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<PatchLineComment> del = Lists.newArrayList();
|
List<PatchLineComment> del = Lists.newArrayList();
|
||||||
List<PatchLineComment> ins = Lists.newArrayList();
|
List<PatchLineComment> ups = Lists.newArrayList();
|
||||||
List<PatchLineComment> upd = Lists.newArrayList();
|
|
||||||
|
|
||||||
for (Map.Entry<String, List<Comment>> ent : in.entrySet()) {
|
for (Map.Entry<String, List<Comment>> ent : in.entrySet()) {
|
||||||
String path = ent.getKey();
|
String path = ent.getKey();
|
||||||
for (Comment c : ent.getValue()) {
|
for (Comment c : ent.getValue()) {
|
||||||
String parent = Url.decode(c.inReplyTo);
|
String parent = Url.decode(c.inReplyTo);
|
||||||
PatchLineComment e = drafts.remove(Url.decode(c.id));
|
PatchLineComment e = drafts.remove(Url.decode(c.id));
|
||||||
boolean create = e == null;
|
if (e == null) {
|
||||||
if (create) {
|
|
||||||
e = new PatchLineComment(
|
e = new PatchLineComment(
|
||||||
new PatchLineComment.Key(
|
new PatchLineComment.Key(
|
||||||
new Patch.Key(rsrc.getPatchSet().getId(), path),
|
new Patch.Key(rsrc.getPatchSet().getId(), path),
|
||||||
@ -373,7 +371,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
|||||||
e.setSide(c.side == Side.PARENT ? (short) 0 : (short) 1);
|
e.setSide(c.side == Side.PARENT ? (short) 0 : (short) 1);
|
||||||
e.setMessage(c.message);
|
e.setMessage(c.message);
|
||||||
e.setRange(c.range);
|
e.setRange(c.range);
|
||||||
(create ? ins : upd).add(e);
|
ups.add(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,16 +386,14 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
|||||||
for (PatchLineComment e : drafts.values()) {
|
for (PatchLineComment e : drafts.values()) {
|
||||||
e.setStatus(PatchLineComment.Status.PUBLISHED);
|
e.setStatus(PatchLineComment.Status.PUBLISHED);
|
||||||
e.setWrittenOn(timestamp);
|
e.setWrittenOn(timestamp);
|
||||||
upd.add(e);
|
ups.add(e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
db.get().patchComments().delete(del);
|
db.get().patchComments().delete(del);
|
||||||
db.get().patchComments().insert(ins);
|
db.get().patchComments().upsert(ups);
|
||||||
db.get().patchComments().update(upd);
|
comments.addAll(ups);
|
||||||
comments.addAll(ins);
|
return !del.isEmpty() || !ups.isEmpty();
|
||||||
comments.addAll(upd);
|
|
||||||
return !del.isEmpty() || !ins.isEmpty() || !upd.isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, PatchLineComment> scanDraftComments(
|
private Map<String, PatchLineComment> scanDraftComments(
|
||||||
@ -418,8 +414,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<PatchSetApproval> del = Lists.newArrayList();
|
List<PatchSetApproval> del = Lists.newArrayList();
|
||||||
List<PatchSetApproval> ins = Lists.newArrayList();
|
List<PatchSetApproval> ups = Lists.newArrayList();
|
||||||
List<PatchSetApproval> upd = Lists.newArrayList();
|
|
||||||
Map<String, PatchSetApproval> current = scanLabels(rsrc, del);
|
Map<String, PatchSetApproval> current = scanLabels(rsrc, del);
|
||||||
|
|
||||||
LabelTypes labelTypes = rsrc.getControl().getLabelTypes();
|
LabelTypes labelTypes = rsrc.getControl().getLabelTypes();
|
||||||
@ -445,7 +440,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
|||||||
c.setValue(ent.getValue());
|
c.setValue(ent.getValue());
|
||||||
c.setGranted(timestamp);
|
c.setGranted(timestamp);
|
||||||
c.cache(change);
|
c.cache(change);
|
||||||
upd.add(c);
|
ups.add(c);
|
||||||
labelDelta.add(format(normName, c.getValue()));
|
labelDelta.add(format(normName, c.getValue()));
|
||||||
categories.put(normName, c.getValue());
|
categories.put(normName, c.getValue());
|
||||||
} else if (c != null && c.getValue() == ent.getValue()) {
|
} else if (c != null && c.getValue() == ent.getValue()) {
|
||||||
@ -458,23 +453,22 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
|||||||
ent.getValue(), TimeUtil.nowTs());
|
ent.getValue(), TimeUtil.nowTs());
|
||||||
c.setGranted(timestamp);
|
c.setGranted(timestamp);
|
||||||
c.cache(change);
|
c.cache(change);
|
||||||
ins.add(c);
|
ups.add(c);
|
||||||
labelDelta.add(format(normName, c.getValue()));
|
labelDelta.add(format(normName, c.getValue()));
|
||||||
categories.put(normName, c.getValue());
|
categories.put(normName, c.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forceCallerAsReviewer(rsrc, current, ins, upd, del);
|
forceCallerAsReviewer(rsrc, current, ups, del);
|
||||||
db.get().patchSetApprovals().delete(del);
|
db.get().patchSetApprovals().delete(del);
|
||||||
db.get().patchSetApprovals().insert(ins);
|
db.get().patchSetApprovals().upsert(ups);
|
||||||
db.get().patchSetApprovals().update(upd);
|
return !del.isEmpty() || !ups.isEmpty();
|
||||||
return !del.isEmpty() || !ins.isEmpty() || !upd.isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forceCallerAsReviewer(RevisionResource rsrc,
|
private void forceCallerAsReviewer(RevisionResource rsrc,
|
||||||
Map<String, PatchSetApproval> current, List<PatchSetApproval> ins,
|
Map<String, PatchSetApproval> current, List<PatchSetApproval> ups,
|
||||||
List<PatchSetApproval> upd, List<PatchSetApproval> del) {
|
List<PatchSetApproval> del) {
|
||||||
if (current.isEmpty() && ins.isEmpty() && upd.isEmpty()) {
|
if (current.isEmpty() && ups.isEmpty()) {
|
||||||
// TODO Find another way to link reviewers to changes.
|
// TODO Find another way to link reviewers to changes.
|
||||||
if (del.isEmpty()) {
|
if (del.isEmpty()) {
|
||||||
// If no existing label is being set to 0, hack in the caller
|
// If no existing label is being set to 0, hack in the caller
|
||||||
@ -487,7 +481,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
|||||||
(short) 0, TimeUtil.nowTs());
|
(short) 0, TimeUtil.nowTs());
|
||||||
c.setGranted(timestamp);
|
c.setGranted(timestamp);
|
||||||
c.cache(change);
|
c.cache(change);
|
||||||
ins.add(c);
|
ups.add(c);
|
||||||
} else {
|
} else {
|
||||||
// Pick a random label that is about to be deleted and keep it.
|
// Pick a random label that is about to be deleted and keep it.
|
||||||
Iterator<PatchSetApproval> i = del.iterator();
|
Iterator<PatchSetApproval> i = del.iterator();
|
||||||
@ -496,7 +490,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
|||||||
c.setGranted(timestamp);
|
c.setGranted(timestamp);
|
||||||
c.cache(change);
|
c.cache(change);
|
||||||
i.remove();
|
i.remove();
|
||||||
upd.add(c);
|
ups.add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user