From c4e562cb2fad74318b6a9bf733a0909263ff0271 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 7 Jul 2014 13:47:11 +0200 Subject: [PATCH] Update issue notification link --- .../IssueChangesEmailTemplate.java | 4 +++- .../IssueChangesEmailTemplateTest.java | 21 ++++++++++++++++++- ...lay_component_key_if_no_component_name.txt | 6 ++++++ .../email_with_action_plan_change.txt | 4 ++-- .../email_with_assignee_change.txt | 4 ++-- .../email_with_multiple_changes.txt | 4 ++-- 6 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/display_component_key_if_no_component_name.txt diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplate.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplate.java index e2776bbdf8d..9a342524d2f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplate.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplate.java @@ -92,7 +92,9 @@ public class IssueChangesEmailTemplate extends EmailTemplate { private void appendFooter(StringBuilder sb, Notification notification) { String issueKey = notification.getFieldValue("key"); - sb.append("See it in SonarQube: ").append(settings.getServerBaseURL()).append("/issue/show/").append(issueKey).append(NEW_LINE); + String componentKey = notification.getFieldValue("componentKey"); + sb.append("See it in SonarQube: ").append(settings.getServerBaseURL()).append("/component/index#component=").append(componentKey) + .append("¤tIssue=").append(issueKey).append(NEW_LINE); } private void appendLine(StringBuilder sb, @Nullable String line) { diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java index 02e00bacb0a..77a5f382533 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java @@ -99,6 +99,24 @@ public class IssueChangesEmailTemplateTest { assertThat(email.getFrom()).isNull(); } + @Test + public void display_component_key_if_no_component_name() throws Exception { + Notification notification = generateNotification() + .setFieldValue("componentName", null); + + EmailMessage email = template.format(notification); + assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE"); + assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE"); + + String message = email.getMessage(); + String expected = Resources.toString(Resources.getResource( + "org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/display_component_key_if_no_component_name.txt"), + Charsets.UTF_8 + ); + expected = StringUtils.remove(expected, '\r'); + assertThat(message).isEqualTo(expected); + } + @Test public void test_email_with_multiple_changes() throws Exception { Notification notification = generateNotification() @@ -139,7 +157,8 @@ public class IssueChangesEmailTemplateTest { Notification notification = new Notification("issue-changes") .setFieldValue("projectName", "Struts") .setFieldValue("projectKey", "org.apache:struts") - .setFieldValue("componentName", "org.apache.struts.Action") + .setFieldValue("componentName", "Action") + .setFieldValue("componentKey", "org.apache.struts.Action") .setFieldValue("key", "ABCDE") .setFieldValue("ruleName", "Avoid Cycles") .setFieldValue("message", "Has 3 cycles"); diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/display_component_key_if_no_component_name.txt b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/display_component_key_if_no_component_name.txt new file mode 100644 index 00000000000..74e3c716b78 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/display_component_key_if_no_component_name.txt @@ -0,0 +1,6 @@ +org.apache.struts.Action +Rule: Avoid Cycles +Message: Has 3 cycles + + +See it in SonarQube: http://nemo.sonarsource.org/component/index#component=org.apache.struts.Action¤tIssue=ABCDE diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt index d1230a17d45..1fc46b2e8f7 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt @@ -1,7 +1,7 @@ -org.apache.struts.Action +Action Rule: Avoid Cycles Message: Has 3 cycles Action Plan changed to ABC 1.0 -See it in SonarQube: http://nemo.sonarsource.org/issue/show/ABCDE +See it in SonarQube: http://nemo.sonarsource.org/component/index#component=org.apache.struts.Action¤tIssue=ABCDE diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt index 8cc9ab6d1fe..aec09dd4b52 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt @@ -1,7 +1,7 @@ -org.apache.struts.Action +Action Rule: Avoid Cycles Message: Has 3 cycles Assignee changed to louis -See it in SonarQube: http://nemo.sonarsource.org/issue/show/ABCDE +See it in SonarQube: http://nemo.sonarsource.org/component/index#component=org.apache.struts.Action¤tIssue=ABCDE diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt index 995de7018e5..6bee33751fd 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt @@ -1,4 +1,4 @@ -org.apache.struts.Action +Action Rule: Avoid Cycles Message: Has 3 cycles @@ -7,4 +7,4 @@ Assignee changed to louis Resolution: FALSE-POSITIVE Status: RESOLVED -See it in SonarQube: http://nemo.sonarsource.org/issue/show/ABCDE +See it in SonarQube: http://nemo.sonarsource.org/component/index#component=org.apache.struts.Action¤tIssue=ABCDE -- 2.39.5