in src/main/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreator.java [189:242]
public void onCommentAdded(CommentAddedListener.Event event) {
try (ManualRequestContext ctx = oneOffRequestContext.openAs(config.getContextUserId())) {
RevisionInfo eventRevision = event.getRevision();
if (!eventRevision.isCurrent) {
log.info(
"Not updating downstream votes since revision {} is not current.",
eventRevision._number);
return;
}
ChangeInfo change = event.getChange();
String revision = gApi.changes().id(event.getChange()._number).current().commit(false).commit;
Set<String> downstreamBranches;
downstreamBranches = config.getDownstreamBranches(change.branch, change.project);
if (downstreamBranches.isEmpty()) {
log.debug("Downstream branches of {} on {} are empty", change.branch, change.project);
return;
}
Map<String, LabelInfo> labels =
gApi.changes()
.id(change._number)
.get(EnumSet.of(ListChangesOption.DETAILED_LABELS))
.labels;
for (String downstreamBranch : downstreamBranches) {
try {
List<Integer> existingDownstream =
getExistingMergesOnBranch(revision, change.topic, downstreamBranch);
for (Integer changeNumber : existingDownstream) {
ChangeInfo downstreamChange =
gApi.changes().id(changeNumber).get(EnumSet.of(ListChangesOption.CURRENT_REVISION));
for (Map.Entry<String, LabelInfo> labelEntry : labels.entrySet()) {
if (labelEntry.getValue().all != null && labelEntry.getValue().all.size() > 0) {
OptionalInt maxVote =
labelEntry.getValue().all.stream()
.filter(o -> o.value != null)
.mapToInt(i -> i.value)
.max();
if (maxVote.isPresent()) {
updateVote(downstreamChange, labelEntry.getKey(), (short) maxVote.getAsInt());
}
}
}
}
} catch (RestApiException | InvalidQueryParameterException e) {
log.error("Exception when updating downstream votes of {}", change.id, e);
}
}
} catch (StorageException | ConfigInvalidException | RestApiException | IOException e) {
log.error("Automerger plugin failed onCommentAdded for {}", event.getChange().id, e);
}
}