You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MyNewIssuesEmailTemplate.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.issue.notification;
  21. import java.util.Date;
  22. import org.sonar.api.config.EmailSettings;
  23. import org.sonar.api.i18n.I18n;
  24. import org.sonar.api.notifications.Notification;
  25. import org.sonar.api.utils.DateUtils;
  26. import org.sonar.server.issue.notification.NewIssuesStatistics.Metric;
  27. /**
  28. * Creates email message for notification "my-new-issues".
  29. */
  30. public class MyNewIssuesEmailTemplate extends AbstractNewIssuesEmailTemplate {
  31. public MyNewIssuesEmailTemplate(EmailSettings settings, I18n i18n) {
  32. super(settings, i18n);
  33. }
  34. @Override
  35. protected boolean shouldNotFormat(Notification notification) {
  36. return !MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE.equals(notification.getType());
  37. }
  38. @Override
  39. protected void appendAssignees(StringBuilder message, Notification notification) {
  40. // do nothing as we don't want to print assignees, it's a personalized email for one person
  41. }
  42. @Override
  43. protected String subject(Notification notification, String fullProjectName) {
  44. int issueCount = Integer.parseInt(notification.getFieldValue(Metric.RULE_TYPE + COUNT));
  45. return String.format("You have %s new issue%s on project %s",
  46. issueCount,
  47. issueCount > 1 ? "s" : "",
  48. fullProjectName);
  49. }
  50. @Override
  51. protected void appendFooter(StringBuilder message, Notification notification) {
  52. String projectKey = notification.getFieldValue(FIELD_PROJECT_KEY);
  53. String dateString = notification.getFieldValue(FIELD_PROJECT_DATE);
  54. String assignee = notification.getFieldValue(FIELD_ASSIGNEE);
  55. if (projectKey != null && dateString != null && assignee != null) {
  56. Date date = DateUtils.parseDateTime(dateString);
  57. String url = String.format("%s/project/issues?id=%s&assignees=%s",
  58. settings.getServerBaseURL(),
  59. encode(projectKey),
  60. encode(assignee));
  61. String branchName = notification.getFieldValue(FIELD_BRANCH);
  62. if (branchName != null) {
  63. url += "&branch=" + encode(branchName);
  64. }
  65. String pullRequest = notification.getFieldValue(FIELD_PULL_REQUEST);
  66. if (pullRequest != null) {
  67. url += "&pullRequest=" + encode(pullRequest);
  68. }
  69. url += "&createdAt=" + encode(DateUtils.formatDateTime(date));
  70. message
  71. .append("More details at: ")
  72. .append(url)
  73. .append(NEW_LINE);
  74. }
  75. }
  76. }