private void appendFooter(StringBuilder sb, Notification notification) {
String projectKey = notification.getFieldValue("projectKey");
String dateString = notification.getFieldValue("projectDate");
- Date date = DateUtils.parseDateTime(dateString);
- String url = String.format("%s/issues/search?componentRoots=%s&createdAfter=%s",
- settings.getServerBaseURL(), URLEncoder.encode(projectKey), DateUtils.formatDate(date));
- sb.append("\n").append("See it in SonarQube: ").append(url).append("\n");
+ if (projectKey != null && dateString != null) {
+ Date date = DateUtils.parseDateTime(dateString);
+ String url = String.format("%s/issues/search?componentRoots=%s&createdAfter=%s",
+ settings.getServerBaseURL(), URLEncoder.encode(projectKey), DateUtils.formatDate(date));
+ sb.append("\n").append("See it in SonarQube: ").append(url).append("\n");
+ }
}
}
"\n" +
"See it in SonarQube: http://nemo.sonarsource.org/issues/search?componentRoots=org.apache%3Astruts&createdAfter=2010-05-18\n");
}
+
+ @Test
+ public void shouldNotAddFooterIfMissingProperties() {
+ Notification notification = new Notification("new-issues")
+ .setFieldValue("count", "32")
+ .setFieldValue("projectName", "Struts");
+
+ EmailMessage message = template.format(notification);
+ assertThat(message.getMessage()).doesNotContain("See it");
+ }
}
}
public boolean overDue(){
- return isOpen() && deadLine() != null && new Date().after(deadLine());
+ Date deadline = deadLine();
+ return isOpen() && deadline != null && new Date().after(deadline);
}
}
}
@Override
- public Issuable.IssueBuilder severity(String severity) {
+ public Issuable.IssueBuilder severity(@Nullable String severity) {
this.severity = severity;
return this;
}
}
@Override
- public Issuable.IssueBuilder attribute(String key, String value) {
+ public Issuable.IssueBuilder attribute(String key, @Nullable String value) {
if (attributes == null) {
attributes = Maps.newLinkedHashMap();
}
}
}
+ // TODO remove this duplication from IssueService
public IssueQueryResult loadIssue(String issueKey) {
IssueQuery query = IssueQuery.builder().issueKeys(Arrays.asList(issueKey)).requiredRole(UserRole.USER).build();
- return finder.find(query);
+ IssueQueryResult result = finder.find(query);
+ if (result.issues().size()!=1) {
+ throw new IllegalStateException("Issue not found: " + issueKey);
+ }
+ return result;
}
}