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());
      }
    }
  }
Пример #2
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;
  }
  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;
  }
Пример #4
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());
 }