public boolean setEffortToFix(DefaultIssue issue, @Nullable Double d, IssueChangeContext context) { if (!Objects.equal(d, issue.effortToFix())) { issue.setEffortToFix(d); issue.setUpdateDate(context.date()); issue.setChanged(true); // Do not send notifications to prevent spam when installing the SQALE plugin, // and do not complete the changelog (for the moment) return true; } return false; }
@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(); }
private void updateIssue(DefaultIssue issue, Rule rule, ActiveRule activeRule) { if (Strings.isNullOrEmpty(issue.message())) { issue.setMessage(rule.name()); } issue.setCreationDate(project.getAnalysisDate()); issue.setUpdateDate(project.getAnalysisDate()); if (issue.severity() == null) { issue.setSeverity(activeRule.severity()); } DebtRemediationFunction function = rule.debtRemediationFunction(); if (rule.debtSubCharacteristic() != null && function != null) { issue.setDebt(calculateDebt(function, issue.effortToFix(), rule.key())); } }
@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); }
public boolean setPastEffortToFix( DefaultIssue issue, @Nullable Double previousEffort, IssueChangeContext context) { Double currentEffort = issue.effortToFix(); issue.setEffortToFix(previousEffort); return setEffortToFix(issue, currentEffort, context); }