Пример #1
0
  private void writeChangelog(Issue issue, JsonWriter json) {
    json.name("changelog")
        .beginArray()
        .beginObject()
        .prop("creationDate", DateUtils.formatDateTime(issue.creationDate()))
        .prop("fCreationDate", formatDate(issue.creationDate()))
        .name("diffs")
        .beginArray()
        .value(i18n.message(UserSession.get().locale(), "created", null))
        .endArray()
        .endObject();

    IssueChangelog changelog = issueChangelogService.changelog(issue);
    for (FieldDiffs diffs : changelog.changes()) {
      String userLogin = diffs.userLogin();
      json.beginObject()
          .prop("userName", userLogin != null ? changelog.user(diffs).name() : null)
          .prop("creationDate", DateUtils.formatDateTime(diffs.creationDate()))
          .prop("fCreationDate", formatDate(diffs.creationDate()));
      json.name("diffs").beginArray();
      List<String> diffsFormatted = issueChangelogService.formatDiffs(diffs);
      for (String diff : diffsFormatted) {
        json.value(diff);
      }
      json.endArray();
      json.endObject();
    }
    json.endArray();
  }
 @Override
 public void decorate(Resource resource, DecoratorContext context) {
   Issuable issuable = perspectives.as(Issuable.class, resource);
   if (issuable != null) {
     int falsePositives = 0;
     for (Issue issue : issuable.resolvedIssues()) {
       if (Issue.RESOLUTION_FALSE_POSITIVE.equals(issue.resolution())) {
         falsePositives++;
       }
     }
     saveMeasure(context, CoreMetrics.FALSE_POSITIVE_ISSUES, falsePositives);
   }
 }
  private void treatUnresolvedIssues(DecoratorContext context, List<Issue> unresolvedIssues) {
    Map<Integer, String> authorsByLine = null;
    for (Issue issue : unresolvedIssues) {
      logger.debug(
          "Treating unresolved issue [{}]: isNew = [{}], line = [{}], assignee = [{}]",
          issue.key(),
          issue.isNew(),
          issue.line(),
          issue.assignee());

      if (!isCandidateIssue(issue)) {
        logger.debug("Issue [{}] is not a candidate for auto assignment", issue.key());
        continue;
      }

      if (authorsByLine == null) {
        // Load authors by line for the current resource. Should be done only once per resource
        authorsByLine = getAuthorsByLineFromScm(context);
      }

      User autoAssignee = getAutoAssignee(issue, authorsByLine);
      if (autoAssignee != null) {
        logger.debug("Assigning issue [{}] to user [{}]", issue.key(), autoAssignee.login());
        assignIssue(issue, autoAssignee);
      } else {
        logger.debug("Leaving the issue [{}] unassigned", issue.key());
      }
    }
  }
Пример #4
0
 @VisibleForTesting
 ListMultimap<TechnicalDebtRequirement, Issue> issuesByRequirement(List<Issue> issues) {
   ListMultimap<TechnicalDebtRequirement, Issue> issuesByRequirement = ArrayListMultimap.create();
   for (Issue issue : issues) {
     String repositoryKey = issue.ruleKey().repository();
     String key = issue.ruleKey().rule();
     TechnicalDebtRequirement requirement =
         technicalDebtModel.getRequirementByRule(repositoryKey, key);
     if (requirement == null) {
       LoggerFactory.getLogger(getClass())
           .debug("No technical debt requirement for: " + repositoryKey + "/" + key);
     } else {
       issuesByRequirement.put(requirement, issue);
     }
   }
   return issuesByRequirement;
 }
  private User getAutoAssignee(Issue issue, Map<Integer, String> authorsByLine) {
    String scmLoginName = null;
    if (issue.line() != null || authorsByLine.get(issue.line()) != null) {
      scmLoginName = authorsByLine.get(issue.line());
    }

    User autoAssignee = null;
    if (scmLoginName == null) {
      logger.debug(
          "Cannot detect automatically the login of the assignee from SCM blame for issue [{}]",
          issue.key());
      autoAssignee = getDefaultAssigneeIfAny();
      if (autoAssignee != null) {
        logger.debug(
            "Using default assignee [{}] for issue [{}]", autoAssignee.login(), issue.key());
      }
    } else {
      autoAssignee = getUserFromLoginName(scmLoginName);
    }
    return autoAssignee;
  }
  @Test
  public void shouldAcceptIssueIfFullyMatched() {
    String rule = "rule";
    String path = "org/sonar/api/Issue.java";
    String componentKey = "org.sonar.api.Issue";
    RuleKey ruleKey = mock(RuleKey.class);
    when(ruleKey.toString()).thenReturn(rule);
    when(issue.ruleKey()).thenReturn(ruleKey);
    when(issue.componentKey()).thenReturn(componentKey);

    IssuePattern matching = mock(IssuePattern.class);
    WildcardPattern rulePattern = mock(WildcardPattern.class);
    when(matching.getRulePattern()).thenReturn(rulePattern);
    when(rulePattern.match(rule)).thenReturn(true);
    WildcardPattern pathPattern = mock(WildcardPattern.class);
    when(matching.getResourcePattern()).thenReturn(pathPattern);
    when(pathPattern.match(path)).thenReturn(true);
    when(exclusionPatternInitializer.getMulticriteriaPatterns())
        .thenReturn(ImmutableList.of(matching));
    when(exclusionPatternInitializer.getPathForComponent(componentKey)).thenReturn(path);

    assertThat(ignoreFilter.accept(issue, chain)).isTrue();
    verifyZeroInteractions(chain);
  }
Пример #7
0
 /**
  * Never return null, but an empty list if the issue does not exist. No security check is done
  * since it should already have been done to get the issue
  */
 public List<Transition> listTransitions(@Nullable Issue issue) {
   if (issue == null) {
     return Collections.emptyList();
   }
   List<Transition> outTransitions = workflow.outTransitions(issue);
   List<Transition> allowedTransitions = new ArrayList<>();
   for (Transition transition : outTransitions) {
     String projectUuid = issue.projectUuid();
     if (userSession.isLoggedIn() && StringUtils.isBlank(transition.requiredProjectPermission())
         || (projectUuid != null
             && userSession.hasComponentUuidPermission(
                 transition.requiredProjectPermission(), projectUuid))) {
       allowedTransitions.add(transition);
     }
   }
   return allowedTransitions;
 }
  @Test
  public void shouldPassToChainIfRuleDoesNotMatch() {
    String rule = "rule";
    RuleKey ruleKey = mock(RuleKey.class);
    when(ruleKey.toString()).thenReturn(rule);
    when(issue.ruleKey()).thenReturn(ruleKey);

    IssuePattern matching = mock(IssuePattern.class);
    WildcardPattern rulePattern = mock(WildcardPattern.class);
    when(matching.getRulePattern()).thenReturn(rulePattern);
    when(rulePattern.match(rule)).thenReturn(false);
    when(exclusionPatternInitializer.getMulticriteriaPatterns())
        .thenReturn(ImmutableList.of(matching));

    assertThat(ignoreFilter.accept(issue, chain)).isTrue();
    verify(chain).accept(issue);
  }
Пример #9
0
 private void writeComments(IssueQueryResult queryResult, Issue issue, JsonWriter json) {
   json.name("comments").beginArray();
   for (IssueComment comment : issue.comments()) {
     String userLogin = comment.userLogin();
     json.beginObject()
         .prop("key", comment.key())
         .prop("userName", userLogin != null ? queryResult.user(userLogin).name() : null)
         .prop("raw", comment.markdownText())
         .prop("html", Markdown.convertToHtml(comment.markdownText()))
         .prop("createdAt", DateUtils.formatDateTime(comment.createdAt()))
         .prop("fCreatedAge", formatAgeDate(comment.createdAt()))
         .prop(
             "updatable",
             UserSession.get().isLoggedIn()
                 && UserSession.get().login().equals(comment.userLogin()))
         .endObject();
   }
   json.endArray();
 }
  @Override
  public void executeOn(Project project, SensorContext context) {
    System.out.println("ListAllIssuesPostJob");

    // all open issues
    for (Issue issue : projectIssues.issues()) {
      String ruleKey = issue.ruleKey().toString();
      Integer issueLine = issue.line();
      String severity = issue.severity();
      boolean isNew = issue.isNew();

      // just to illustrate, we dump some fields of the 'issue' in sysout (bad, very bad)
      System.out.println(ruleKey + " : " + issue.componentKey() + "(" + issueLine + ")");
      System.out.println("isNew: " + isNew + " | severity: " + severity);
    }

    // all resolved issues
    for (Issue issue : projectIssues.resolvedIssues()) {
      String ruleKey = issue.ruleKey().toString();
      Integer issueLine = issue.line();
      boolean isNew = issue.isNew();

      System.out.println(ruleKey + " : " + issue.componentKey() + "(" + issueLine + ")");
      System.out.println("isNew: " + isNew + " | resolution: " + issue.resolution());
    }
  }
Пример #11
0
 @Override
 public boolean matches(Issue issue) {
   return issue.resolution() == null;
 }
 private boolean isCandidateIssue(Issue issue) {
   return issue.assignee() == null
       && (issue.isNew() || !settings.getBoolean(IssueAutoAssignPlugin.PROPERTY_NEW_ISSUES_ONLY));
 }
Пример #13
0
 @Override
 public boolean matches(Issue issue) {
   return issue.resolution() != null && resolutions.contains(issue.resolution());
 }
Пример #14
0
 IssueDto getByKeyForUpdate(DbSession session, String key) {
   // Load from index to check permission : if the user has no permission to see the issue an
   // exception will be generated
   Issue authorizedIssueIndex = getByKey(key);
   return dbClient.issueDao().selectOrFailByKey(session, authorizedIssueIndex.key());
 }
Пример #15
0
 @Override
 public boolean matches(Issue issue) {
   return manual == (issue.reporter() != null);
 }
Пример #16
0
  /** Create issue report according to issue list generated during SonarQube analysis. */
  public static SonarQubeIssuesReport extractIssueReport(
      ProjectIssues projectIssues, InputFileCache inputFileCache, File projectBaseDir) {
    SonarQubeIssuesReport result = new SonarQubeIssuesReport();

    for (Issue issue : projectIssues.issues()) {
      if (!issue.isNew()) {
        LOGGER.debug("Issue {} is not a new issue and so, not added to the report", issue.key());
      } else {
        String key = issue.key();
        String severity = issue.severity();
        String rule = issue.ruleKey().toString();
        String message = issue.message();

        int line = 0;
        if (issue.line() != null) {
          line = issue.line();
        }

        InputFile inputFile = inputFileCache.getInputFile(issue.componentKey());
        if (inputFile == null) {
          LOGGER.debug("Issue {} is not linked to a file, not added to the report", issue.key());
        } else {
          String path = new PathResolver().relativePath(projectBaseDir, inputFile.file());

          // Create the issue and Add to report
          SonarQubeIssue stashIssue = new SonarQubeIssue(key, severity, message, rule, path, line);
          result.add(stashIssue);
        }
      }
    }

    return result;
  }