if (baseStatus.getStatus() != rawStatus.getStatus()) {
// The QualityGate status has changed
- String label = String.format("%s (was %s)", rawStatus.getStatus().getColorName(), baseStatus.getStatus().getColorName());
- createEvent(project, label, rawStatus.getText());
+ createEvent(project, rawStatus.getStatus().getLabel(), rawStatus.getText());
boolean isNewKo = rawStatus.getStatus() == Measure.Level.OK;
- notifyUsers(project, label, rawStatus, isNewKo);
+ notifyUsers(project, rawStatus, isNewKo);
}
}
private void checkNewQualityGate(Component project, QualityGateStatus rawStatus) {
if (rawStatus.getStatus() != Measure.Level.OK) {
// There were no defined alerts before, so this one is a new one
- createEvent(project, rawStatus.getStatus().getColorName(), rawStatus.getText());
- notifyUsers(project, rawStatus.getStatus().getColorName(), rawStatus, true);
+ createEvent(project, rawStatus.getStatus().getLabel(), rawStatus.getText());
+ notifyUsers(project, rawStatus, true);
}
}
/**
- * @param label "Red (was Green)"
* @param rawStatus OK or ERROR + optional text
*/
- private void notifyUsers(Component project, String label, QualityGateStatus rawStatus, boolean isNewAlert) {
+ private void notifyUsers(Component project, QualityGateStatus rawStatus, boolean isNewAlert) {
QGChangeNotification notification = new QGChangeNotification();
notification
- .setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label))
+ .setDefaultMessage(String.format("Alert on %s: %s", project.getName(), rawStatus.getStatus().getLabel()))
.setFieldValue("projectName", project.getName())
.setFieldValue("projectKey", project.getKey())
.setFieldValue("projectVersion", project.getProjectAttributes().getProjectVersion())
- .setFieldValue("alertName", label)
+ .setFieldValue("alertName", rawStatus.getStatus().getLabel())
.setFieldValue("alertText", rawStatus.getText())
.setFieldValue("alertLevel", rawStatus.getStatus().toString())
.setFieldValue("isNewAlert", Boolean.toString(isNewAlert));
@Test
public void event_created_if_base_ALERT_STATUS_has_no_alertStatus_and_raw_is_ERROR() {
- verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Red");
+ verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Failed");
}
@Test
public void event_created_if_base_ALERT_STATUS_has_invalid_alertStatus_and_raw_is_ERROR() {
- verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Red");
+ verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Failed");
}
private void verify_event_created_if_no_base_ALERT_STATUS_measure(Measure.Level rawAlterStatus, String expectedLabel) {
@Test
public void event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed() {
- verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(OK, ERROR_QUALITY_GATE_STATUS, "Red (was Green)");
- verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(ERROR, OK_QUALITY_GATE_STATUS, "Green (was Red)");
+ verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(OK, ERROR_QUALITY_GATE_STATUS, "Failed");
+ verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(ERROR, OK_QUALITY_GATE_STATUS, "Passed");
}
private void verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(Measure.Level previousAlertStatus,
@Test
public void shouldFormatAlertWithSeveralMessages() {
- Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "false");
+ Notification notification = createNotification("Failed", "violations > 4, coverage < 75%", "ERROR", "false");
EmailMessage message = template.format(notification);
assertThat(message.getMessageId(), is("alerts/45"));
assertThat(message.getMessage(), is("" +
"Project: Foo\n" +
"Version: V1-SNAP\n" +
- "Quality gate status: Red (was Green)\n" +
+ "Quality gate status: Failed\n" +
"\n" +
"Quality gate thresholds:\n" +
" - violations > 4\n" +
@Test
public void shouldFormatAlertWithSeveralMessagesOnBranch() {
- Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "false")
+ Notification notification = createNotification("Failed", "violations > 4, coverage < 75%", "ERROR", "false")
.setFieldValue("branch", "feature");
EmailMessage message = template.format(notification);
"Project: Foo\n" +
"Branch: feature\n" +
"Version: V1-SNAP\n" +
- "Quality gate status: Red (was Green)\n" +
+ "Quality gate status: Failed\n" +
"\n" +
"Quality gate thresholds:\n" +
" - violations > 4\n" +
@Test
public void shouldFormatNewAlertWithSeveralMessages() {
- Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "true");
+ Notification notification = createNotification("Failed", "violations > 4, coverage < 75%", "ERROR", "true");
EmailMessage message = template.format(notification);
assertThat(message.getMessageId(), is("alerts/45"));
assertThat(message.getMessage(), is("" +
"Project: Foo\n" +
"Version: V1-SNAP\n" +
- "Quality gate status: Red (was Green)\n" +
+ "Quality gate status: Failed\n" +
"\n" +
"New quality gate thresholds:\n" +
" - violations > 4\n" +
@Test
public void shouldFormatNewAlertWithOneMessage() {
- Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true");
+ Notification notification = createNotification("Failed", "violations > 4", "ERROR", "true");
EmailMessage message = template.format(notification);
assertThat(message.getMessageId(), is("alerts/45"));
assertThat(message.getMessage(), is("" +
"Project: Foo\n" +
"Version: V1-SNAP\n" +
- "Quality gate status: Red (was Green)\n" +
+ "Quality gate status: Failed\n" +
"\n" +
"New quality gate threshold: violations > 4\n" +
"\n" +
@Test
public void shouldFormatNewAlertWithoutVersion() {
- Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true")
+ Notification notification = createNotification("Failed", "violations > 4", "ERROR", "true")
.setFieldValue("projectVersion", null);
EmailMessage message = template.format(notification);
assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
assertThat(message.getMessage(), is("" +
"Project: Foo\n" +
- "Quality gate status: Red (was Green)\n" +
+ "Quality gate status: Failed\n" +
"\n" +
"New quality gate threshold: violations > 4\n" +
"\n" +
@Test
public void shouldFormatNewAlertWithOneMessageOnBranch() {
- Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true")
+ Notification notification = createNotification("Failed", "violations > 4", "ERROR", "true")
.setFieldValue("branch", "feature");
EmailMessage message = template.format(notification);
"Project: Foo\n" +
"Branch: feature\n" +
"Version: V1-SNAP\n" +
- "Quality gate status: Red (was Green)\n" +
+ "Quality gate status: Failed\n" +
"\n" +
"New quality gate threshold: violations > 4\n" +
"\n" +
@Test
public void shouldFormatBackToGreenMessage() {
- Notification notification = createNotification("Green (was Red)", "", "OK", "false");
+ Notification notification = createNotification("Passed", "", "OK", "false");
EmailMessage message = template.format(notification);
assertThat(message.getMessageId(), is("alerts/45"));
assertThat(message.getMessage(), is("" +
"Project: Foo\n" +
"Version: V1-SNAP\n" +
- "Quality gate status: Green (was Red)\n" +
+ "Quality gate status: Passed\n" +
"\n" +
"\n" +
"More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo"));
@Test
public void shouldFormatBackToGreenMessageOnBranch() {
- Notification notification = createNotification("Green (was Red)", "", "OK", "false")
+ Notification notification = createNotification("Passed", "", "OK", "false")
.setFieldValue("branch", "feature");
EmailMessage message = template.format(notification);
"Project: Foo\n" +
"Branch: feature\n" +
"Version: V1-SNAP\n" +
- "Quality gate status: Green (was Red)\n" +
+ "Quality gate status: Passed\n" +
"\n" +
"\n" +
"More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo&branch=feature"));