示例#1
0
  /** Setup the message headers and envelope (TO, CC, BCC). */
  protected void init() throws EmailException {
    if (args.projectCache != null) {
      projectState = args.projectCache.get(change.getProject());
    } else {
      projectState = null;
    }

    if (patchSet == null) {
      try {
        patchSet = args.db.get().patchSets().get(change.currentPatchSetId());
      } catch (OrmException err) {
        patchSet = null;
      }
    }

    if (patchSet != null && patchSetInfo == null) {
      try {
        patchSetInfo = args.patchSetInfoFactory.get(patchSet.getId());
      } catch (PatchSetInfoNotAvailableException err) {
        patchSetInfo = null;
      }
    }
    authors = getAuthors();

    super.init();

    if (changeMessage != null && changeMessage.getWrittenOn() != null) {
      setHeader("Date", new Date(changeMessage.getWrittenOn().getTime()));
    }
    setChangeSubjectHeader();
    setHeader("X-Gerrit-Change-Id", "" + change.getKey().get());
    setListIdHeader();
    setChangeUrlHeader();
    setCommitIdHeader();
  }
示例#2
0
  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");
  }
示例#3
0
 @Override
 protected void setupVelocityContext() {
   super.setupVelocityContext();
   velocityContext.put("change", change);
   velocityContext.put("changeId", change.getKey());
   velocityContext.put("coverLetter", getCoverLetter());
   velocityContext.put("branch", change.getDest());
   velocityContext.put("fromName", getNameFor(fromId));
   velocityContext.put(
       "projectName", //
       projectState != null ? projectState.getProject().getName() : null);
   velocityContext.put("patchSet", patchSet);
   velocityContext.put("patchSetInfo", patchSetInfo);
 }
示例#4
0
  /** Create the change message and the affected file list. */
  public String getChangeDetail() {
    StringBuilder detail = new StringBuilder();

    if (patchSetInfo != null) {
      detail.append(patchSetInfo.getMessage().trim() + "\n");
    } else {
      detail.append(change.getSubject().trim() + "\n");
    }

    if (patchSet != null) {
      detail.append("---\n");
      PatchList patchList = getPatchList();
      for (PatchListEntry p : patchList.getPatches()) {
        if (Patch.COMMIT_MSG.equals(p.getNewName())) {
          continue;
        }
        detail.append(p.getChangeType().getCode() + " " + p.getNewName() + "\n");
      }
      detail.append(
          MessageFormat.format(
              "" //
                  + "{0,choice,0#0 files|1#1 file|1<{0} files} changed, " //
                  + "{1,choice,0#0 insertions|1#1 insertion|1<{1} insertions}(+), " //
                  + "{2,choice,0#0 deletions|1#1 deletion|1<{2} deletions}(-)" //
                  + "\n",
              patchList.getPatches().size() - 1, //
              patchList.getInsertions(), //
              patchList.getDeletions()));
      detail.append("\n");
    }
    return detail.toString();
  }
示例#5
0
 private boolean inProject(final Change change) {
   if (projectControl == null) {
     // No --project option, so they want every project.
     return true;
   }
   return projectControl.getProject().getNameKey().equals(change.getProject());
 }
示例#6
0
 /** Get a link to the change; null if the server doesn't know its own address. */
 public String getChangeUrl() {
   if (change != null && getGerritUrl() != null) {
     final StringBuilder r = new StringBuilder();
     r.append(getGerritUrl());
     r.append(change.getChangeId());
     return r.toString();
   }
   return null;
 }
示例#7
0
  /** Find all users who are authors of any part of this change. */
  protected Set<Account.Id> getAuthors() {
    Set<Account.Id> authors = new HashSet<Account.Id>();

    authors.add(change.getOwner());
    if (patchSet != null) {
      authors.add(patchSet.getUploader());
    }
    if (patchSetInfo != null) {
      authors.add(patchSetInfo.getAuthor().getAccount());
      authors.add(patchSetInfo.getCommitter().getAccount());
    }
    return authors;
  }
示例#8
0
 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) {
   }
 }
示例#9
0
 /** 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.
   }
 }
示例#10
0
  /** 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) {
    }
  }
示例#11
0
  /** Returns all watches that are relevant */
  protected final List<AccountProjectWatch> getWatches() throws OrmException {
    if (changeData == null) {
      return Collections.emptyList();
    }

    List<AccountProjectWatch> matching = new ArrayList<AccountProjectWatch>();
    Set<Account.Id> projectWatchers = new HashSet<Account.Id>();

    for (AccountProjectWatch w :
        args.db.get().accountProjectWatches().byProject(change.getProject())) {
      projectWatchers.add(w.getAccountId());
      add(matching, w);
    }

    for (AccountProjectWatch w :
        args.db.get().accountProjectWatches().byProject(args.allProjectsName)) {
      if (!projectWatchers.contains(w.getAccountId())) {
        add(matching, w);
      }
    }

    return Collections.unmodifiableList(matching);
  }
示例#12
0
  /** Get the groups which own the project. */
  protected Set<AccountGroup.UUID> getProjectOwners() {
    final ProjectState r;

    r = args.projectCache.get(change.getProject());
    return r != null ? r.getOwners() : Collections.<AccountGroup.UUID>emptySet();
  }