Ejemplo n.º 1
0
 public boolean setResolution(DefaultIssue issue, @Nullable String resolution, IssueChangeContext context) {
   if (!Objects.equal(resolution, issue.resolution())) {
     issue.setFieldChange(context, RESOLUTION, issue.resolution(), resolution);
     issue.setResolution(resolution);
     issue.setUpdateDate(context.date());
     issue.setChanged(true);
     issue.setSendNotifications(true);
     return true;
   }
   return false;
 }
  @Test
  public void should_keep_changes_made_by_user() throws Exception {
    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.setActionPlanKey("PLAN-1");
    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")
            .setActionPlanKey("PLAN-2")
            .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);
    assertThat(issue.actionPlanKey()).isEqualTo("PLAN-2");
  }
Ejemplo n.º 3
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")
            .setRuleId(1)
            .setRuleKey_unit_test_only("squid", "AvoidCycle")
            .setComponentKey_unit_test_only("org.sonar.sample:Sample")
            .setRootComponentKey_unit_test_only("org.sonar.sample")
            .setComponentId(1l)
            .setRootComponentId(1l)
            .setStatus(Issue.STATUS_CLOSED)
            .setResolution(Issue.RESOLUTION_FALSE_POSITIVE)
            .setEffortToFix(15.0)
            .setTechnicalDebt(101010L)
            .setLine(6)
            .setSeverity("BLOCKER")
            .setMessage("message")
            .setManualSeverity(true)
            .setReporter("arthur")
            .setAssignee("perceval")
            .setIssueAttributes("key=value")
            .setAuthorLogin("pierre")
            .setIssueCreationDate(createdAt)
            .setIssueUpdateDate(updatedAt)
            .setIssueCloseDate(closedAt);

    DefaultIssue issue = dto.toDefaultIssue();
    assertThat(issue.key()).isEqualTo("100");
    assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle");
    assertThat(issue.componentKey()).isEqualTo("org.sonar.sample:Sample");
    assertThat(issue.projectKey()).isEqualTo("org.sonar.sample");
    assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
    assertThat(issue.effortToFix()).isEqualTo(15.0);
    assertThat(issue.technicalDebt()).isEqualTo(WorkDayDuration.of(10, 10, 10));
    assertThat(issue.line()).isEqualTo(6);
    assertThat(issue.severity()).isEqualTo("BLOCKER");
    assertThat(issue.message()).isEqualTo("message");
    assertThat(issue.manualSeverity()).isTrue();
    assertThat(issue.reporter()).isEqualTo("arthur");
    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();
  }
Ejemplo n.º 4
0
 // TODO all available actions should be returned by ActionService or another service
 private List<String> actions(DefaultIssue issue) {
   List<String> actions = newArrayList();
   if (UserSession.get().isLoggedIn()) {
     actions.add("comment");
     if (issue.resolution() == null) {
       actions.add("assign");
       if (!UserSession.get().login().equals(issue.assignee())) {
         actions.add("assign_to_me");
       }
       actions.add("plan");
       if (UserSession.get().hasProjectPermission(UserRole.ISSUE_ADMIN, issue.projectKey())) {
         actions.add("set_severity");
       }
       for (Action action : actionService.listAvailableActions(issue)) {
         actions.add(action.key());
       }
     }
   }
   return actions;
 }
Ejemplo n.º 5
0
  private void writeIssue(IssueQueryResult result, DefaultIssue issue, JsonWriter json) {
    Component component = result.component(issue);
    Component project = result.project(issue);
    String actionPlanKey = issue.actionPlanKey();
    WorkDayDuration technicalDebt = issue.technicalDebt();
    Date updateDate = issue.updateDate();
    Date closeDate = issue.closeDate();

    json.prop("key", issue.key())
        .prop("component", issue.componentKey())
        .prop("componentLongName", component != null ? component.longName() : null)
        .prop("componentQualifier", component != null ? component.qualifier() : null)
        .prop("project", issue.projectKey())
        .prop("projectLongName", project != null ? project.longName() : null)
        .prop("rule", issue.ruleKey().toString())
        .prop("ruleName", result.rule(issue).getName())
        .prop("line", issue.line())
        .prop("message", issue.message())
        .prop("resolution", issue.resolution())
        .prop("status", issue.status())
        .prop("severity", issue.severity())
        .prop("author", issue.authorLogin())
        .prop("actionPlan", actionPlanKey)
        .prop(
            "debt",
            technicalDebt != null
                ? technicalDebtFormatter.format(UserSession.get().locale(), technicalDebt)
                : null)
        .prop("actionPlanName", actionPlanKey != null ? result.actionPlan(issue).name() : null)
        .prop("creationDate", DateUtils.formatDateTime(issue.creationDate()))
        .prop("fCreationDate", formatDate(issue.creationDate()))
        .prop("updateDate", updateDate != null ? DateUtils.formatDateTime(updateDate) : null)
        .prop("fUpdateDate", formatDate(updateDate))
        .prop("fUpdateAge", formatAgeDate(updateDate))
        .prop("closeDate", closeDate != null ? DateUtils.formatDateTime(closeDate) : null)
        .prop("fCloseDate", formatDate(issue.closeDate()));

    addUserWithLabel(result, issue.assignee(), "assignee", json);
    addUserWithLabel(result, issue.reporter(), "reporter", json);
  }
  @Test
  public void build_new_issue() throws Exception {
    String componentKey = "org.apache.struts:struts-core:Action.java";
    String projectKey = "org.apache.struts";
    DefaultIssue issue =
        (DefaultIssue)
            new DefaultIssueBuilder()
                .componentKey(componentKey)
                .projectKey(projectKey)
                .message("the message")
                .line(123)
                .effortToFix(10000.0)
                .ruleKey(RuleKey.of("squid", "NullDereference"))
                .severity(Severity.CRITICAL)
                .attribute("JIRA", "FOO-123")
                .attribute("YOUTRACK", "YT-123")
                .build();

    assertThat(issue).isNotNull();
    assertThat(issue.key()).isNotNull();
    assertThat(issue.effortToFix()).isEqualTo(10000.0);
    assertThat(issue.componentKey()).isEqualTo(componentKey);
    assertThat(issue.projectKey()).isEqualTo(projectKey);
    assertThat(issue.message()).isEqualTo("the message");
    assertThat(issue.line()).isEqualTo(123);
    assertThat(issue.ruleKey().repository()).isEqualTo("squid");
    assertThat(issue.ruleKey().rule()).isEqualTo("NullDereference");
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    assertThat(issue.assignee()).isNull();
    assertThat(issue.isNew()).isTrue();
    assertThat(issue.resolution()).isNull();
    assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN);
    assertThat(issue.attribute("JIRA")).isEqualTo("FOO-123");
    assertThat(issue.attribute("YOUTRACK")).isEqualTo("YT-123");
    assertThat(issue.attributes()).hasSize(2);
  }