Merge branch 'stable-2.11'
* stable-2.11: Release notes for Gerrit 2.11.4 Fix link in 2.10.7 release notes Set version to 2.11.4 Do not double decode the login URL token ReceiveCommits: Fire add comment hook when approvals provided ReceiveCommits: Include approvals from magic branch in change message Update no-new-change error message documentation Release notes for Gerrit 2.10.7 Fix: User could get around ref-update hook through gerrit-created commits Set version to 2.10.7 PatchListLoader: Synchronize MyersDiff and HistogramDiff invocations Change-Id: Id28f13876f16bb5194f7b078860b95004dba369d
This commit is contained in:
@@ -71,6 +71,7 @@ import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetInfo;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
@@ -1761,6 +1762,8 @@ public class ReceiveCommits {
|
||||
}
|
||||
recipients.add(getRecipientsFromFooters(accountResolver, ps, footerLines));
|
||||
recipients.remove(me);
|
||||
StringBuilder msgs = renderMessageWithApprovals(ps.getPatchSetId(),
|
||||
approvals, Collections.<String, PatchSetApproval>emptyMap());
|
||||
try (ObjectInserter oi = repo.newObjectInserter();
|
||||
BatchUpdate bu = batchUpdateFactory.create(
|
||||
db, change.getProject(), currentUser, change.getCreatedOn())) {
|
||||
@@ -1769,7 +1772,7 @@ public class ReceiveCommits {
|
||||
.setReviewers(recipients.getReviewers())
|
||||
.setExtraCC(recipients.getCcOnly())
|
||||
.setApprovals(approvals)
|
||||
.setMessage("Uploaded patch set " + ps.getPatchSetId() + ".")
|
||||
.setMessage(msgs.toString() + ".")
|
||||
.setRequestScopePropagator(requestScopePropagator)
|
||||
.setSendMail(true)
|
||||
.setUpdateRef(false));
|
||||
@@ -1881,6 +1884,27 @@ public class ReceiveCommits {
|
||||
}
|
||||
}
|
||||
|
||||
private StringBuilder renderMessageWithApprovals(int patchSetId,
|
||||
Map<String, Short> n, Map<String, PatchSetApproval> c) {
|
||||
StringBuilder msgs = new StringBuilder("Uploaded patch set " + patchSetId);
|
||||
if (!n.isEmpty()) {
|
||||
boolean first = true;
|
||||
for (Map.Entry<String, Short> e : n.entrySet()) {
|
||||
if (c.containsKey(e.getKey())
|
||||
&& c.get(e.getKey()).getValue() == e.getValue()) {
|
||||
continue;
|
||||
}
|
||||
if (first) {
|
||||
msgs.append(":");
|
||||
first = false;
|
||||
}
|
||||
msgs.append(" ")
|
||||
.append(LabelVote.create(e.getKey(), e.getValue()).format());
|
||||
}
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
|
||||
private class ReplaceRequest {
|
||||
final Change.Id ontoChange;
|
||||
final RevCommit newCommit;
|
||||
@@ -2118,29 +2142,52 @@ public class ReceiveCommits {
|
||||
return Futures.makeChecked(future, INSERT_EXCEPTION);
|
||||
}
|
||||
|
||||
private ChangeMessage newChangeMessage(ReviewDb db, ChangeKind changeKind)
|
||||
private ChangeMessage newChangeMessage(ReviewDb db, ChangeKind changeKind,
|
||||
Map<String, Short> approvals)
|
||||
throws OrmException {
|
||||
msg =
|
||||
new ChangeMessage(new ChangeMessage.Key(change.getId(), ChangeUtil
|
||||
.messageUUID(db)), currentUser.getAccountId(), newPatchSet.getCreatedOn(),
|
||||
newPatchSet.getId());
|
||||
String message = "Uploaded patch set " + newPatchSet.getPatchSetId();
|
||||
StringBuilder msgs = renderMessageWithApprovals(
|
||||
newPatchSet.getPatchSetId(), approvals, scanLabels(db, approvals));
|
||||
switch (changeKind) {
|
||||
case TRIVIAL_REBASE:
|
||||
case NO_CHANGE:
|
||||
message += ": Patch Set " + priorPatchSet.get() + " was rebased";
|
||||
msgs.append(": Patch Set " + priorPatchSet.get() + " was rebased");
|
||||
break;
|
||||
case NO_CODE_CHANGE:
|
||||
message += ": Commit message was updated";
|
||||
msgs.append(": Commit message was updated");
|
||||
break;
|
||||
case REWORK:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
msg.setMessage(message + ".");
|
||||
msg.setMessage(msgs.toString() + ".");
|
||||
return msg;
|
||||
}
|
||||
|
||||
private Map<String, PatchSetApproval> scanLabels(ReviewDb db,
|
||||
Map<String, Short> approvals)
|
||||
throws OrmException {
|
||||
Map<String, PatchSetApproval> current = new HashMap<>();
|
||||
// We optimize here and only retrieve current when approvals provided
|
||||
if (!approvals.isEmpty()) {
|
||||
for (PatchSetApproval a : approvalsUtil.byPatchSetUser(
|
||||
db, changeCtl, priorPatchSet, currentUser.getAccountId())) {
|
||||
if (a.isSubmit()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LabelType lt = labelTypes.byLabel(a.getLabelId());
|
||||
if (lt != null) {
|
||||
current.put(lt.getName(), a);
|
||||
}
|
||||
}
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
PatchSet.Id upsertEdit() {
|
||||
if (cmd.getResult() == NOT_ATTEMPTED) {
|
||||
cmd.execute(rp);
|
||||
@@ -2205,7 +2252,8 @@ public class ReceiveCommits {
|
||||
changeKind = changeKindCache.getChangeKind(
|
||||
projectControl.getProjectState(), repo, priorCommit, newCommit);
|
||||
|
||||
cmUtil.addChangeMessage(db, update, newChangeMessage(db, changeKind));
|
||||
cmUtil.addChangeMessage(db, update, newChangeMessage(db, changeKind,
|
||||
approvals));
|
||||
|
||||
if (mergedIntoRef == null) {
|
||||
// Change should be new, so it can go through review again.
|
||||
@@ -2304,6 +2352,11 @@ public class ReceiveCommits {
|
||||
change, currentUser.getAccount(), newPatchSet, db, newCommit.getName());
|
||||
}
|
||||
|
||||
if (!approvals.isEmpty()) {
|
||||
hooks.doCommentAddedHook(change, currentUser.getAccount(), newPatchSet,
|
||||
null, approvals, db);
|
||||
}
|
||||
|
||||
if (magicBranch != null && magicBranch.submit) {
|
||||
submit(changeCtl, newPatchSet);
|
||||
}
|
||||
|
Reference in New Issue
Block a user