public void resolve(DefaultIssue issue, IssueMapper mapper) {
    LOG.debug("Resolve conflict on issue {}", issue.key());

    IssueDto dbIssue = mapper.selectByKey(issue.key());
    if (dbIssue != null) {
      mergeFields(dbIssue, issue);
      mapper.update(IssueDto.toDtoForUpdate(issue, System.currentTimeMillis()));
    }
  }
 private void assertInitializedIssue(DefaultIssue issue) {
   assertThat(issue.componentKey()).isEqualTo(FILE.getKey());
   assertThat(issue.componentUuid()).isEqualTo(FILE.getUuid());
   assertThat(issue.resolution()).isNull();
   assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN);
   assertThat(issue.key()).isNull();
   assertThat(issue.authorLogin()).isNull();
   assertThat(issue.debt()).isNull();
 }
  @Test
  public void should_keep_changes_made_by_user() {
    DefaultIssue issue =
        new DefaultIssue()
            .setKey("ABCDE")
            .setRuleKey(RuleKey.of("squid", "AvoidCycles"))
            .setComponentKey("struts:org.apache.struts.Action")
            .setNew(false);

    // Before starting scan
    issue.setAssignee(null);
    issue.setCreationDate(DateUtils.parseDate("2012-01-01"));
    issue.setUpdateDate(DateUtils.parseDate("2012-02-02"));

    // Changed by scan
    issue.setLine(200);
    issue.setSeverity(Severity.BLOCKER);
    issue.setManualSeverity(false);
    issue.setAuthorLogin("simon");
    issue.setChecksum("CHECKSUM-ABCDE");
    issue.setResolution(null);
    issue.setStatus(Issue.STATUS_REOPENED);

    // Issue as seen and changed by end-user
    IssueDto dbIssue =
        new IssueDto()
            .setKee("ABCDE")
            .setRuleId(10)
            .setRuleKey("squid", "AvoidCycles")
            .setComponentUuid("100")
            .setComponentKey("struts:org.apache.struts.Action")
            .setLine(10)
            .setResolution(Issue.RESOLUTION_FALSE_POSITIVE)
            .setStatus(Issue.STATUS_RESOLVED)
            .setAssignee("arthur")
            .setSeverity(Severity.MAJOR)
            .setManualSeverity(false);

    new UpdateConflictResolver().mergeFields(dbIssue, issue);

    assertThat(issue.key()).isEqualTo("ABCDE");
    assertThat(issue.componentKey()).isEqualTo("struts:org.apache.struts.Action");

    // Scan wins on :
    assertThat(issue.line()).isEqualTo(200);
    assertThat(issue.severity()).isEqualTo(Severity.BLOCKER);
    assertThat(issue.manualSeverity()).isFalse();

    // User wins on :
    assertThat(issue.assignee()).isEqualTo("arthur");
    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
    assertThat(issue.status()).isEqualTo(Issue.STATUS_RESOLVED);
  }
Example #4
0
 void saveIssue(
     DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment) {
   String projectKey = issue.projectKey();
   if (projectKey == null) {
     throw new IllegalStateException(String.format("Issue '%s' has no project key", issue.key()));
   }
   issueStorage.save(session, issue);
   Rule rule = getNullableRuleByKey(issue.ruleKey());
   ComponentDto project = dbClient.componentDao().selectOrFailByKey(session, projectKey);
   notificationService.scheduleForSending(
       new IssueChangeNotification()
           .setIssue(issue)
           .setChangeAuthorLogin(context.login())
           .setRuleName(rule != null ? rule.getName() : null)
           .setProject(project.getKey(), project.name())
           .setComponent(dbClient.componentDao().selectOrFailByKey(session, issue.componentKey()))
           .setComment(comment));
 }
Example #5
0
 public void addComment(DefaultIssue issue, String text, IssueChangeContext context) {
   issue.addComment(DefaultIssueComment.create(issue.key(), context.login(), text));
   issue.setUpdateDate(context.date());
   issue.setChanged(true);
 }
Example #6
0
  @Test
  public void set_issue_fields() {
    Date createdAt = DateUtils.addDays(new Date(), -5);
    Date updatedAt = DateUtils.addDays(new Date(), -3);
    Date closedAt = DateUtils.addDays(new Date(), -1);

    IssueDto dto =
        new IssueDto()
            .setKee("100")
            .setType(RuleType.VULNERABILITY)
            .setRuleId(1)
            .setRuleKey("squid", "AvoidCycle")
            .setLanguage("xoo")
            .setComponentKey("org.sonar.sample:Sample")
            .setComponentUuid("CDEF")
            .setProjectUuid("GHIJ")
            .setModuleUuid("BCDE")
            .setModuleUuidPath("ABCD.BCDE.")
            .setProjectKey("org.sonar.sample")
            .setStatus(Issue.STATUS_CLOSED)
            .setResolution(Issue.RESOLUTION_FALSE_POSITIVE)
            .setGap(15.0)
            .setEffort(10L)
            .setLine(6)
            .setSeverity("BLOCKER")
            .setMessage("message")
            .setManualSeverity(true)
            .setAssignee("perceval")
            .setIssueAttributes("key=value")
            .setAuthorLogin("pierre")
            .setIssueCreationDate(createdAt)
            .setIssueUpdateDate(updatedAt)
            .setIssueCloseDate(closedAt);

    DefaultIssue issue = dto.toDefaultIssue();
    assertThat(issue.key()).isEqualTo("100");
    assertThat(issue.type()).isEqualTo(RuleType.VULNERABILITY);
    assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle");
    assertThat(issue.language()).isEqualTo("xoo");
    assertThat(issue.componentUuid()).isEqualTo("CDEF");
    assertThat(issue.projectUuid()).isEqualTo("GHIJ");
    assertThat(issue.componentKey()).isEqualTo("org.sonar.sample:Sample");
    assertThat(issue.moduleUuid()).isEqualTo("BCDE");
    assertThat(issue.moduleUuidPath()).isEqualTo("ABCD.BCDE.");
    assertThat(issue.projectKey()).isEqualTo("org.sonar.sample");
    assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
    assertThat(issue.gap()).isEqualTo(15.0);
    assertThat(issue.effort()).isEqualTo(Duration.create(10L));
    assertThat(issue.line()).isEqualTo(6);
    assertThat(issue.severity()).isEqualTo("BLOCKER");
    assertThat(issue.message()).isEqualTo("message");
    assertThat(issue.manualSeverity()).isTrue();
    assertThat(issue.assignee()).isEqualTo("perceval");
    assertThat(issue.attribute("key")).isEqualTo("value");
    assertThat(issue.authorLogin()).isEqualTo("pierre");
    assertThat(issue.creationDate()).isEqualTo(DateUtils.truncate(createdAt, Calendar.SECOND));
    assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(updatedAt, Calendar.SECOND));
    assertThat(issue.closeDate()).isEqualTo(DateUtils.truncate(closedAt, Calendar.SECOND));
    assertThat(issue.isNew()).isFalse();
  }