private Set<PatchSet.Id> parsePatchSetId(final String patchIdentity) throws UnloggedFailure, OrmException { // By commit? // if (patchIdentity.matches("^([0-9a-fA-F]{4," + RevId.LEN + "})$")) { final RevId id = new RevId(patchIdentity); final ResultSet<PatchSet> patches; if (id.isComplete()) { patches = db.patchSets().byRevision(id); } else { patches = db.patchSets().byRevisionRange(id, id.max()); } final Set<PatchSet.Id> matches = new HashSet<PatchSet.Id>(); for (final PatchSet ps : patches) { final Change change = db.changes().get(ps.getId().getParentKey()); if (inProject(change)) { matches.add(ps.getId()); } } switch (matches.size()) { case 1: return matches; case 0: throw error("\"" + patchIdentity + "\" no such patch set"); default: throw error("\"" + patchIdentity + "\" matches multiple patch sets"); } } // By older style change,patchset? // if (patchIdentity.matches("^[1-9][0-9]*,[1-9][0-9]*$")) { final PatchSet.Id patchSetId; try { patchSetId = PatchSet.Id.parse(patchIdentity); } catch (IllegalArgumentException e) { throw error("\"" + patchIdentity + "\" is not a valid patch set"); } if (db.patchSets().get(patchSetId) == null) { throw error("\"" + patchIdentity + "\" no such patch set"); } if (projectControl != null) { final Change change = db.changes().get(patchSetId.getParentKey()); if (!inProject(change)) { throw error( "change " + change.getId() + " not in project " + projectControl.getProject().getName()); } } return Collections.singleton(patchSetId); } throw error("\"" + patchIdentity + "\" is not a valid patch set"); }
private void ccApprovals(final boolean includeZero) { try { // CC anyone else who has posted an approval mark on this change // for (PatchSetApproval ap : args.db.get().patchSetApprovals().byChange(change.getId())) { if (!includeZero && ap.getValue() == 0) { continue; } add(RecipientType.CC, ap.getAccountId()); } } catch (OrmException err) { } }
/** BCC any user who has starred this change. */ protected void bccStarredBy() { try { // BCC anyone who has starred this change. // for (StarredChange w : args.db.get().starredChanges().byChange(change.getId())) { add(RecipientType.BCC, w.getAccountId()); } } catch (OrmException err) { // Just don't BCC everyone. Better to send a partial message to those // we already have queued up then to fail deliver entirely to people // who have a lower interest in the change. } }
/** Format the message body by calling {@link #appendText(String)}. */ protected void format() throws EmailException { formatChange(); appendText(velocifyFile("ChangeFooter.vm")); try { HashSet<Account.Id> reviewers = new HashSet<Account.Id>(); for (PatchSetApproval p : args.db.get().patchSetApprovals().byChange(change.getId())) { reviewers.add(p.getAccountId()); } TreeSet<String> names = new TreeSet<String>(); for (Account.Id who : reviewers) { names.add(getNameEmailFor(who)); } for (String name : names) { appendText("Gerrit-Reviewer: " + name + "\n"); } } catch (OrmException e) { } }