.setFieldValue("projectName", project.getName())
.setFieldValue("projectKey", project.getPublicKey())
.setFieldValue("projectUuid", project.getUuid())
+ .setFieldValue("projectVersion", project.getReportAttributes().getVersion())
.setFieldValue("alertName", label)
.setFieldValue("alertText", rawStatus.getText())
.setFieldValue("alertLevel", rawStatus.getStatus().toString())
String projectId = notification.getFieldValue("projectId");
String projectKey = notification.getFieldValue("projectKey");
String projectName = notification.getFieldValue("projectName");
+ String projectVersion = notification.getFieldValue("projectVersion");
String branchName = notification.getFieldValue("branch");
String alertName = notification.getFieldValue("alertName");
String alertText = notification.getFieldValue("alertText");
// Generate text
String subject = generateSubject(fullProjectName, alertLevel, isNewAlert);
- String messageBody = generateMessageBody(fullProjectName, projectKey, branchName, alertName, alertText, isNewAlert);
+ String messageBody = generateMessageBody(fullProjectName, projectKey, projectVersion, branchName, alertName, alertText, isNewAlert);
// And finally return the email that will be sent
return new EmailMessage()
return subjectBuilder.toString();
}
- private String generateMessageBody(String fullProjectName, String projectKey, @Nullable String branchName, String alertName, String alertText, boolean isNewAlert) {
+ private String generateMessageBody(String fullProjectName, String projectKey,
+ @Nullable String projectVersion, @Nullable String branchName,
+ String alertName, String alertText, boolean isNewAlert) {
StringBuilder messageBody = new StringBuilder();
messageBody.append("Project: ").append(fullProjectName).append("\n");
+ if (projectVersion != null) {
+ messageBody.append("Version: ").append(projectVersion).append("\n");
+ }
messageBody.append("Quality gate status: ").append(alertName).append("\n\n");
String[] alerts = StringUtils.split(alertText, ",");
public class QualityGateEventsStepTest {
private static final ReportComponent PROJECT_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("uuid 1").setKey("key 1")
- .addChildren(ReportComponent.builder(Component.Type.MODULE, 2).build())
+ .addChildren(ReportComponent.builder(Component.Type.MODULE, 2).setVersion("V1.9").build())
.build();
private static final String INVALID_ALERT_STATUS = "trololo";
private static final String ALERT_TEXT = "alert text";
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
+ assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
assertThat(notification.getFieldValue("branch")).isNull();
assertThat(notification.getFieldValue("alertLevel")).isEqualTo(rawAlterStatus.name());
assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel);
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
+ assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
assertThat(notification.getFieldValue("branch")).isNull();
assertThat(notification.getFieldValue("alertLevel")).isEqualTo(newQualityGateStatus.getStatus().name());
assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel);
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
+ assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
assertThat(notification.getFieldValue("branch")).isEqualTo(branchName);
reset(measureRepository, eventRepository, notificationService);
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
+ assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
assertThat(notification.getFieldValue("branch")).isEqualTo(null);
reset(measureRepository, eventRepository, notificationService);
assertThat(message.getSubject(), is("Quality gate status changed on \"Foo\""));
assertThat(message.getMessage(), is("" +
"Project: Foo\n" +
+ "Version: V1-SNAP\n" +
"Quality gate status: Orange (was Red)\n" +
"\n" +
"Quality gate thresholds:\n" +
assertThat(message.getSubject(), is("Quality gate status changed on \"Foo (feature)\""));
assertThat(message.getMessage(), is("" +
"Project: Foo (feature)\n" +
+ "Version: V1-SNAP\n" +
"Quality gate status: Orange (was Red)\n" +
"\n" +
"Quality gate thresholds:\n" +
assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
assertThat(message.getMessage(), is("" +
"Project: Foo\n" +
+ "Version: V1-SNAP\n" +
"Quality gate status: Orange (was Red)\n" +
"\n" +
"New quality gate thresholds:\n" +
public void shouldFormatNewAlertWithOneMessage() {
Notification notification = createNotification("Orange (was Red)", "violations > 4", "WARN", "true");
+ EmailMessage message = template.format(notification);
+ assertThat(message.getMessageId(), is("alerts/45"));
+ assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
+ assertThat(message.getMessage(), is("" +
+ "Project: Foo\n" +
+ "Version: V1-SNAP\n" +
+ "Quality gate status: Orange (was Red)\n" +
+ "\n" +
+ "New quality gate threshold: violations > 4\n" +
+ "\n" +
+ "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo"));
+ }
+
+ @Test
+ public void shouldFormatNewAlertWithoutVersion() {
+ Notification notification = createNotification("Orange (was Red)", "violations > 4", "WARN", "true")
+ .setFieldValue("projectVersion", null);
+
EmailMessage message = template.format(notification);
assertThat(message.getMessageId(), is("alerts/45"));
assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo (feature)\""));
assertThat(message.getMessage(), is("" +
"Project: Foo (feature)\n" +
+ "Version: V1-SNAP\n" +
"Quality gate status: Orange (was Red)\n" +
"\n" +
"New quality gate threshold: violations > 4\n" +
assertThat(message.getSubject(), is("\"Foo\" is back to green"));
assertThat(message.getMessage(), is("" +
"Project: Foo\n" +
+ "Version: V1-SNAP\n" +
"Quality gate status: Green (was Red)\n" +
"\n" +
"\n" +
assertThat(message.getSubject(), is("\"Foo (feature)\" is back to green"));
assertThat(message.getMessage(), is("" +
"Project: Foo (feature)\n" +
+ "Version: V1-SNAP\n" +
"Quality gate status: Green (was Red)\n" +
"\n" +
"\n" +
.setFieldValue("projectName", "Foo")
.setFieldValue("projectKey", "org.sonar.foo:foo")
.setFieldValue("projectId", "45")
+ .setFieldValue("projectVersion", "V1-SNAP")
.setFieldValue("alertName", alertName)
.setFieldValue("alertText", alertText)
.setFieldValue("alertLevel", alertLevel)