in src/main/java/com/googlesource/gerrit/plugins/verifystatus/PostVerification.java [78:157]
private boolean updateLabels(
RevisionResource resource, CiDb db, Map<String, VerificationInfo> jobs)
throws OrmException, BadRequestException {
Preconditions.checkNotNull(jobs);
List<PatchSetVerification> ups = Lists.newArrayList();
Map<String, PatchSetVerification> current = scanLabels(resource, db);
Timestamp ts = TimeUtil.nowTs();
for (Map.Entry<String, VerificationInfo> ent : jobs.entrySet()) {
String name = ent.getKey();
if (name == null) {
throw new BadRequestException("Missing name field");
}
PatchSetVerification c = current.remove(name);
Short value = ent.getValue().value;
if (value == null) {
throw new BadRequestException("Missing value field");
}
if (c != null) {
// update a result
c.setGranted(ts);
c.setValue(value);
if (Boolean.TRUE.equals(ent.getValue().abstain)) {
c.setAbstain(true);
}
if (Boolean.TRUE.equals(ent.getValue().rerun)) {
c.setRerun(true);
}
String url = ent.getValue().url;
if (url != null) {
c.setUrl(url);
}
String job_name = c.getName();
if (job_name != null) {
c.setName(job_name);
}
String reporter = ent.getValue().reporter;
if (reporter != null) {
c.setReporter(reporter);
}
String comment = ent.getValue().comment;
if (comment != null) {
c.setComment(comment);
}
String category = ent.getValue().category;
if (category != null) {
c.setCategory(category);
}
String duration = ent.getValue().duration;
if (duration != null) {
c.setDuration(duration);
}
log.info("Updating job " + c.getJob() + " for change " + c.getPatchSetId());
ups.add(c);
} else {
// add new result
String job_id = UUID.randomUUID().toString();
DbPatchSetId patchSetId =
new DbPatchSetId(
new DbChangeId(resource.getPatchSet().id().changeId().get()),
resource.getPatchSet().id().get());
DbLabelId labelId = new DbLabelId(job_id);
c = new PatchSetVerification(new PatchSetVerification.Key(patchSetId, labelId), value, ts);
c.setAbstain(ent.getValue().abstain);
c.setRerun(ent.getValue().rerun);
c.setUrl(ent.getValue().url);
c.setName(name);
c.setReporter(ent.getValue().reporter);
c.setComment(ent.getValue().comment);
c.setCategory(ent.getValue().category);
c.setDuration(ent.getValue().duration);
log.info("Adding job " + c.getJob() + " for change " + c.getPatchSetId());
ups.add(c);
}
}
db.patchSetVerifications().upsert(ups);
return !ups.isEmpty();
}