use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.
the class ListRevisionReviewers method apply.
@Override
public List<ReviewerInfo> apply(RevisionResource rsrc) throws OrmException, MethodNotAllowedException, PermissionBackendException {
if (!rsrc.isCurrent()) {
throw new MethodNotAllowedException("Cannot list reviewers on non-current patch set");
}
Map<String, ReviewerResource> reviewers = new LinkedHashMap<>();
ReviewDb db = dbProvider.get();
for (Account.Id accountId : approvalsUtil.getReviewers(db, rsrc.getNotes()).all()) {
if (!reviewers.containsKey(accountId.toString())) {
reviewers.put(accountId.toString(), resourceFactory.create(rsrc, accountId));
}
}
for (Address address : rsrc.getNotes().getReviewersByEmail().all()) {
if (!reviewers.containsKey(address.toString())) {
reviewers.put(address.toString(), new ReviewerResource(rsrc, address));
}
}
return json.format(reviewers.values());
}
use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.
the class ProjectWatchIT method noNotificationForDraftChangesForWatchersInNotifyConfig.
@Test
public void noNotificationForDraftChangesForWatchersInNotifyConfig() throws Exception {
Address addr = new Address("Watcher", "watcher@example.com");
NotifyConfig nc = new NotifyConfig();
nc.addEmail(addr);
nc.setName("team");
nc.setHeader(NotifyConfig.Header.TO);
nc.setTypes(EnumSet.of(NotifyType.NEW_CHANGES, NotifyType.ALL_COMMENTS));
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
cfg.putNotifyConfig("team", nc);
saveProjectConfig(project, cfg);
PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), testRepo, "draft change", "a", "a1").to("refs/for/master%draft");
r.assertOkStatus();
assertThat(sender.getMessages()).isEmpty();
setApiUser(admin);
ReviewInput in = new ReviewInput();
in.message = "comment";
gApi.changes().id(r.getChangeId()).current().review(in);
assertThat(sender.getMessages()).isEmpty();
}
use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.
the class MetadataParserTest method parseMetadataFromText.
@Test
public void parseMetadataFromText() {
// This tests if the metadata parser is able to parse metadata from the
// the text body of the message.
MailMessage.Builder b = MailMessage.builder();
b.id("");
b.dateReceived(new DateTime());
b.subject("");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(toFooterWithDelimiter(MetadataName.CHANGE_ID) + "cid\r\n");
stringBuilder.append("> " + toFooterWithDelimiter(MetadataName.PATCH_SET) + "1\n");
stringBuilder.append(toFooterWithDelimiter(MetadataName.MESSAGE_TYPE) + "comment\n");
stringBuilder.append(toFooterWithDelimiter(MetadataName.TIMESTAMP) + "Tue, 25 Oct 2016 02:11:35 -0700\r\n");
b.textContent(stringBuilder.toString());
Address author = new Address("Diffy", "test@gerritcodereview.com");
b.from(author);
MailMetadata meta = MetadataParser.parse(b.build());
assertThat(meta.author).isEqualTo(author.getEmail());
assertThat(meta.changeId).isEqualTo("cid");
assertThat(meta.patchSet).isEqualTo(1);
assertThat(meta.messageType).isEqualTo("comment");
assertThat(meta.timestamp.getTime()).isEqualTo(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC).getMillis());
}
use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.
the class MetadataParserTest method parseMetadataFromHTML.
@Test
public void parseMetadataFromHTML() {
// This tests if the metadata parser is able to parse metadata from the
// the HTML body of the message.
MailMessage.Builder b = MailMessage.builder();
b.id("");
b.dateReceived(new DateTime());
b.subject("");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<div id\"someid\">" + toFooterWithDelimiter(MetadataName.CHANGE_ID) + "cid</div>");
stringBuilder.append("<div>" + toFooterWithDelimiter(MetadataName.PATCH_SET) + "1</div>");
stringBuilder.append("<div>" + toFooterWithDelimiter(MetadataName.MESSAGE_TYPE) + "comment</div>");
stringBuilder.append("<div>" + toFooterWithDelimiter(MetadataName.TIMESTAMP) + "Tue, 25 Oct 2016 02:11:35 -0700" + "</div>");
b.htmlContent(stringBuilder.toString());
Address author = new Address("Diffy", "test@gerritcodereview.com");
b.from(author);
MailMetadata meta = MetadataParser.parse(b.build());
assertThat(meta.author).isEqualTo(author.getEmail());
assertThat(meta.changeId).isEqualTo("cid");
assertThat(meta.patchSet).isEqualTo(1);
assertThat(meta.messageType).isEqualTo("comment");
assertThat(meta.timestamp.getTime()).isEqualTo(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC).getMillis());
}
use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.
the class HtmlMimeMessage method expectedMailMessage.
@Override
public MailMessage expectedMailMessage() {
MailMessage.Builder expect = MailMessage.builder();
expect.id("<001a114cd8be55b4ab053face5cd@google.com>").from(new Address("ekempin (Gerrit)", "noreply-gerritcodereview-qUgXfQecoDLHwp0MldAzig@google.com")).addCc(new Address("ekempin", "ekempin@google.com")).addTo(new Address("Patrick Hiesel", "hiesel@google.com")).textContent(textContent).htmlContent(unencodedHtmlContent).subject("Change in gerrit[master]: Implement receiver class structure and bindings").addAdditionalHeader("MIME-Version: 1.0").dateReceived(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
return expect.build();
}
Aggregations