@Override public EmailMessage format(Notification notification) { if (shouldNotFormat(notification)) { return null; appendRuleType(message, notification); appendAssignees(message, notification); appendRules(message, notification); appendTags(message, notification); appendComponents(message, notification); appendFooter(message, notification); .setSubject(subject(notification, computeFullProjectName(projectName, branchName))) .setMessage(message.toString());
protected void appendAssignees(StringBuilder message, Notification notification) { genericAppendOfMetric(Metric.ASSIGNEE, "Assignees", message, notification); }
protected void appendFooter(StringBuilder message, Notification notification) { String projectKey = notification.getFieldValue(FIELD_PROJECT_KEY); String dateString = notification.getFieldValue(FIELD_PROJECT_DATE); if (projectKey != null && dateString != null) { Date date = DateUtils.parseDateTime(dateString); String url = String.format("%s/project/issues?id=%s", settings.getServerBaseURL(), encode(projectKey)); String branchName = notification.getFieldValue(FIELD_BRANCH); if (branchName != null) { url += "&branch=" + encode(branchName); } String pullRequest = notification.getFieldValue(FIELD_PULL_REQUEST); if (pullRequest != null) { url += "&pullRequest=" + encode(pullRequest); } url += "&createdAt=" + encode(DateUtils.formatDateTime(date)); message .append("More details at: ") .append(url) .append(NEW_LINE); } }
private static void genericAppendOfMetric(Metric metric, String label, StringBuilder message, Notification notification) { if (doNotHaveValue(notification, metric)) { return; } message .append(TAB) .append(label) .append(NEW_LINE); int i = 1; while (notification.getFieldValue(metric + DOT + i + LABEL) != null && i <= 5) { String name = notification.getFieldValue(metric + DOT + i + LABEL); message .append(TAB).append(TAB) .append(name) .append(": ") .append(notification.getFieldValue(metric + DOT + i + COUNT)) .append(NEW_LINE); i += 1; } message.append(NEW_LINE); }
protected void appendFooter(StringBuilder message, Notification notification) { String projectKey = notification.getFieldValue(FIELD_PROJECT_KEY); String dateString = notification.getFieldValue(FIELD_PROJECT_DATE); if (projectKey != null && dateString != null) { Date date = DateUtils.parseDateTime(dateString); String url = String.format("%s/project/issues?id=%s", settings.getServerBaseURL(), encode(projectKey)); String branchName = notification.getFieldValue(FIELD_BRANCH); if (branchName != null) { url += "&branch=" + encode(branchName); } String pullRequest = notification.getFieldValue(FIELD_PULL_REQUEST); if (pullRequest != null) { url += "&pullRequest=" + encode(pullRequest); } url += "&createdAt=" + encode(DateUtils.formatDateTime(date)); message .append("More details at: ") .append(url) .append(NEW_LINE); } }
private static void genericAppendOfMetric(Metric metric, String label, StringBuilder message, Notification notification) { if (doNotHaveValue(notification, metric)) { return; } message .append(TAB) .append(label) .append(NEW_LINE); int i = 1; while (notification.getFieldValue(metric + DOT + i + LABEL) != null && i <= 5) { String name = notification.getFieldValue(metric + DOT + i + LABEL); message .append(TAB).append(TAB) .append(name) .append(": ") .append(notification.getFieldValue(metric + DOT + i + COUNT)) .append(NEW_LINE); i += 1; } message.append(NEW_LINE); }
@Override public EmailMessage format(Notification notification) { if (shouldNotFormat(notification)) { return null; appendRuleType(message, notification); appendAssignees(message, notification); appendRules(message, notification); appendTags(message, notification); appendComponents(message, notification); appendFooter(message, notification); .setSubject(subject(notification, computeFullProjectName(projectName, branchName))) .setMessage(message.toString());
protected void appendComponents(StringBuilder message, Notification notification) { genericAppendOfMetric(Metric.COMPONENT, "Most impacted files", message, notification); }
protected void appendTags(StringBuilder message, Notification notification) { genericAppendOfMetric(Metric.TAG, "Tags", message, notification); }
protected void appendRules(StringBuilder message, Notification notification) { genericAppendOfMetric(Metric.RULE, "Rules", message, notification); }
protected void appendComponents(StringBuilder message, Notification notification) { genericAppendOfMetric(Metric.COMPONENT, "Most impacted files", message, notification); }
protected void appendAssignees(StringBuilder message, Notification notification) { genericAppendOfMetric(Metric.ASSIGNEE, "Assignees", message, notification); }
protected void appendRules(StringBuilder message, Notification notification) { genericAppendOfMetric(Metric.RULE, "Rules", message, notification); }
protected void appendTags(StringBuilder message, Notification notification) { genericAppendOfMetric(Metric.TAG, "Tags", message, notification); }