コード例 #1
0
  protected void appendSeverity(StringBuilder message, Notification notification) {
    message
        .append(
            String.format(
                "%s new issues (new debt: %s)",
                notification.getFieldValue(Metric.SEVERITY + COUNT),
                notification.getFieldValue(Metric.DEBT + COUNT)))
        .append(NEW_LINE)
        .append(NEW_LINE)
        .append(TAB)
        .append("Severity")
        .append(NEW_LINE)
        .append(TAB)
        .append(TAB);

    for (Iterator<String> severityIterator = Lists.reverse(Severity.ALL).iterator();
        severityIterator.hasNext(); ) {
      String severity = severityIterator.next();
      String severityLabel = i18n.message(getLocale(), "severity." + severity, severity);
      message
          .append(severityLabel)
          .append(": ")
          .append(notification.getFieldValue(Metric.SEVERITY + DOT + severity + COUNT));
      if (severityIterator.hasNext()) {
        message.append(TAB);
      }
    }

    message.append(NEW_LINE).append(NEW_LINE);
  }
コード例 #2
0
 protected String subject(Notification notification, String projectName) {
   return String.format(
       "%s: %s new issues (new debt: %s)",
       projectName,
       notification.getFieldValue(Metric.SEVERITY + COUNT),
       notification.getFieldValue(Metric.DEBT + COUNT));
 }
コード例 #3
0
  @Override
  public EmailMessage format(Notification notif) {
    if (!"issue-changes".equals(notif.getType())) {
      return null;
    }

    StringBuilder sb = new StringBuilder();
    appendHeader(notif, sb);
    sb.append(NEW_LINE);
    appendChanges(notif, sb);
    sb.append(NEW_LINE);
    appendFooter(sb, notif);

    String projectName = notif.getFieldValue("projectName");
    String issueKey = notif.getFieldValue("key");
    String author = notif.getFieldValue("changeAuthor");

    EmailMessage message =
        new EmailMessage()
            .setMessageId("issue-changes/" + issueKey)
            .setSubject(projectName + ", change on issue #" + issueKey)
            .setMessage(sb.toString());
    if (author != null) {
      message.setFrom(getUserFullName(author));
    }
    return message;
  }
コード例 #4
0
 private void appendHeader(Notification notif, StringBuilder sb) {
   appendLine(
       sb,
       StringUtils.defaultString(
           notif.getFieldValue("componentName"), notif.getFieldValue("componentKey")));
   appendField(sb, "Rule", null, notif.getFieldValue("ruleName"));
   appendField(sb, "Message", null, notif.getFieldValue("message"));
 }
  @Test
  public void testProjectWithParentManagedProfileUsedByAnotherProject() {
    // make current test profile child of managed one
    testProjectModel.getRulesProfile().setParentName(rulesProfiles[0].getName());

    // create another test project entity
    Integer project2Id = new Integer(5678);
    ResourceModel testProjectModel2 = new ResourceModel();
    testProjectModel2.setId(project2Id);
    testProjectModel2.setKey("test.project2.key");
    testProjectModel2.setEnabled(Boolean.TRUE);
    testProjectModel2.setRootId(project2Id);
    testProjectModel2.setLanguageKey(Java.KEY);
    testProjectModel2.setRulesProfile(testProjectModel.getRulesProfile());

    // add projects to db objects
    MockDatabaseSession.EntityKey projectKey =
        databaseSession.new EntityKey(ResourceModel.class, project2Id);
    entities.put(projectKey, testProjectModel2);
    databaseSession.addMockQueryResults(
        ResourceModel.class, Arrays.asList(testProjectModel, testProjectModel2));

    // test quality profile changes
    String parentProfileBefore = testProjectModel.getRulesProfile().getParentName();
    runAnalysis();
    String parentProfileAfter = testProjectModel.getRulesProfile().getParentName();

    testOutcome(
        "Project profile's parent has been changed despite being used by another project.",
        parentProfileBefore,
        parentProfileAfter,
        true);

    ArgumentCaptor<Notification> argument = ArgumentCaptor.forClass(Notification.class);
    verify(notificationManager).scheduleForSending(argument.capture());
    Notification notification = argument.getValue();

    // check notification has project info
    assertThat(
        "Notification doesn't contain project name",
        notification.getFieldValue(ProfileProgressionPlugin.NOTIFICATION_PROJECT_NAME_KEY),
        equalTo(testProjectModel.getName()));
    assertThat(
        "Notification doesn't contain project id",
        notification.getFieldValue(ProfileProgressionPlugin.NOTIFICATION_PROJECT_ID_KEY),
        equalTo(String.valueOf(testProjectModel.getId())));
    assertThat(
        "Notification doesn't contain project key",
        notification.getFieldValue(ProfileProgressionPlugin.NOTIFICATION_PROJECT_KEY_KEY),
        equalTo(testProjectModel.getKey()));

    // check that message mentioned other project
    assertThat(
        "Notification message doesn't contain key of project blocking progression",
        notification.getFieldValue(ProfileProgressionPlugin.NOTIFICATION_MESSAGE_KEY),
        containsString(testProjectModel2.getKey()));
  }
コード例 #6
0
 protected void appendFooter(StringBuilder message, Notification notification) {
   String projectKey = notification.getFieldValue(FIELD_PROJECT_KEY);
   String dateString = notification.getFieldValue(FIELD_PROJECT_DATE);
   if (projectKey != null && dateString != null) {
     Date date = DateUtils.parseDateTime(dateString);
     String url =
         String.format(
             "%s/component_issues?id=%s#createdAt=%s",
             settings.getServerBaseURL(),
             encode(projectKey),
             encode(DateUtils.formatDateTime(date)));
     message.append("See it in SonarQube: ").append(url).append(NEW_LINE);
   }
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 private void appendFooter(StringBuilder sb, Notification notification) {
   String reviewId = notification.getFieldValue("reviewId");
   sb.append("\n")
       .append("See it in Sonar: ")
       .append(configuration.getServerBaseURL())
       .append("/reviews/view/")
       .append(reviewId)
       .append('\n');
 }
コード例 #9
0
  @Override
  public EmailMessage format(Notification notification) {
    if (shouldNotFormat(notification)) {
      return null;
    }
    String projectName = checkNotNull(notification.getFieldValue(FIELD_PROJECT_NAME));

    StringBuilder message = new StringBuilder();
    message.append("Project: ").append(projectName).append(NEW_LINE).append(NEW_LINE);
    appendSeverity(message, notification);
    appendAssignees(message, notification);
    appendRules(message, notification);
    appendTags(message, notification);
    appendComponents(message, notification);
    appendFooter(message, notification);

    return new EmailMessage()
        .setMessageId(notification.getType() + "/" + notification.getFieldValue(FIELD_PROJECT_KEY))
        .setSubject(subject(notification, projectName))
        .setMessage(message.toString());
  }
コード例 #10
0
  private static void genericAppendOfMetric(
      Metric metric, String label, StringBuilder message, Notification notification) {
    if (doNotHaveValue(notification, metric)) {
      return;
    }

    message.append(TAB).append(label).append(NEW_LINE);
    int i = 1;
    while (notification.getFieldValue(metric + DOT + i + LABEL) != null && i <= 5) {
      String name = notification.getFieldValue(metric + DOT + i + LABEL);
      message
          .append(TAB)
          .append(TAB)
          .append(name)
          .append(": ")
          .append(notification.getFieldValue(metric + DOT + i + COUNT))
          .append(NEW_LINE);
      i += 1;
    }

    message.append(NEW_LINE);
  }
コード例 #11
0
  private void appendComment(StringBuilder sb, Notification notification) {
    String newComment = notification.getFieldValue("new.comment");
    String oldComment = notification.getFieldValue("old.comment");

    if (newComment != null) { // comment was added or modified
      sb.append("Comment:\n  ").append(newComment).append('\n');
      if (oldComment != null) { // comment was modified
        sb.append("Was:\n  ").append(oldComment).append('\n');
      }
    } else if (oldComment != null) { // comment was deleted
      sb.append("Comment deleted, was:\n  ").append(oldComment).append('\n');
    }
  }
コード例 #12
0
  @Override
  public void dispatch(Notification notification, Context context) {
    // "null" is passed as a 2nd argument because this dispatcher is not a per-project dispatcher
    Multimap<String, NotificationChannel> subscribedRecipients =
        notificationManager.findSubscribedRecipientsForDispatcher(this, null);

    List<String> userLogins =
        propertiesDao.findUserIdsForFavouriteResource(
            Long.parseLong(notification.getFieldValue("projectId")));
    for (String userLogin : userLogins) {
      Collection<NotificationChannel> channels = subscribedRecipients.get(userLogin);
      for (NotificationChannel channel : channels) {
        context.addUser(userLogin, channel);
      }
    }
  }
コード例 #13
0
  @Override
  public EmailMessage format(Notification notification) {
    if (!"review-changed".equals(notification.getType())) {
      return null;
    }
    String reviewId = notification.getFieldValue("reviewId");
    String author = notification.getFieldValue("author");
    StringBuilder sb = new StringBuilder();

    append(sb, "Project", null, notification.getFieldValue("project"));
    append(sb, "Resource", null, notification.getFieldValue("resource"));
    sb.append('\n');
    append(sb, null, null, notification.getFieldValue("title"));
    sb.append('\n');
    append(
        sb,
        "Status",
        notification.getFieldValue("old.status"),
        notification.getFieldValue("new.status"));
    append(
        sb,
        "Resolution",
        notification.getFieldValue("old.resolution"),
        notification.getFieldValue("new.resolution"));
    append(
        sb,
        "Assignee",
        getUserFullName(notification.getFieldValue("old.assignee")),
        getUserFullName(notification.getFieldValue("new.assignee")));
    appendComment(sb, notification);
    appendFooter(sb, notification);

    EmailMessage message =
        new EmailMessage()
            .setMessageId("review/" + reviewId)
            .setSubject("Review #" + reviewId)
            .setMessage(sb.toString());
    if (author != null) {
      message.setFrom(getUserFullName(author));
    }
    return message;
  }
コード例 #14
0
 private static boolean doNotHaveValue(Notification notification, Metric metric) {
   return notification.getFieldValue(metric + DOT + "1" + LABEL) == null;
 }
コード例 #15
0
 private void appendChanges(Notification notif, StringBuilder sb) {
   appendField(sb, "Comment", null, notif.getFieldValue("comment"));
   appendFieldWithoutHistory(
       sb, "Assignee", notif.getFieldValue("old.assignee"), notif.getFieldValue("new.assignee"));
   appendField(
       sb, "Severity", notif.getFieldValue("old.severity"), notif.getFieldValue("new.severity"));
   appendField(
       sb,
       "Resolution",
       notif.getFieldValue("old.resolution"),
       notif.getFieldValue("new.resolution"));
   appendField(sb, "Status", notif.getFieldValue("old.status"), notif.getFieldValue("new.status"));
   appendField(
       sb, "Message", notif.getFieldValue("old.message"), notif.getFieldValue("new.message"));
   appendField(sb, "Author", notif.getFieldValue("old.author"), notif.getFieldValue("new.author"));
   appendFieldWithoutHistory(
       sb,
       "Action Plan",
       notif.getFieldValue("old.actionPlan"),
       notif.getFieldValue("new.actionPlan"));
 }