issue.setManualSeverity(true);
issue.setSeverity(ref.getSeverity());
} else {
- // Emulate change of severity in the current scan.
- String severity = issue.severity();
- issue.setSeverity(ref.getSeverity());
- updater.setSeverity(issue, severity, changeContext);
+ updater.setPastSeverity(issue, ref.getSeverity(), changeContext);
}
- Integer line = issue.line();
- issue.setLine(ref.getLine());
- updater.setLine(issue, line);
+ updater.setPastLine(issue, ref.getLine());
+ updater.setPastMessage(issue, ref.getMessage(), changeContext);
+ updater.setPastEffortToFix(issue, ref.getEffortToFix(), changeContext);
}
}
return false;
}
+ public boolean setPastSeverity(DefaultIssue issue, @Nullable String previousSeverity, IssueChangeContext context) {
+ String currentSeverity = issue.severity();
+ issue.setSeverity(previousSeverity);
+ return setSeverity(issue, currentSeverity, context);
+ }
+
public boolean setManualSeverity(DefaultIssue issue, String severity, IssueChangeContext context) {
if (!issue.manualSeverity() || !Objects.equal(severity, issue.severity())) {
issue.setFieldDiff(context, "severity", issue.severity(), severity);
return false;
}
+ public boolean setPastLine(DefaultIssue issue, @Nullable Integer previousLine) {
+ Integer currentLine = issue.line();
+ issue.setLine(previousLine);
+ return setLine(issue, currentLine);
+ }
+
public boolean setResolution(DefaultIssue issue, @Nullable String resolution, IssueChangeContext context) {
if (!Objects.equal(resolution, issue.resolution())) {
issue.setFieldDiff(context, "resolution", issue.resolution(), resolution);
return false;
}
- public void setAuthorLogin(DefaultIssue issue, @Nullable String authorLogin, IssueChangeContext context) {
+ public boolean setAuthorLogin(DefaultIssue issue, @Nullable String authorLogin, IssueChangeContext context) {
if (!Objects.equal(authorLogin, issue.authorLogin())) {
issue.setFieldDiff(context, "author", issue.authorLogin(), authorLogin);
issue.setAuthorLogin(authorLogin);
issue.setUpdateDate(context.date());
issue.setChanged(true);
+ return true;
}
+ return false;
}
- public void setMessage(DefaultIssue issue, @Nullable String s, IssueChangeContext context) {
+ public boolean setMessage(DefaultIssue issue, @Nullable String s, IssueChangeContext context) {
if (!Objects.equal(s, issue.message())) {
- issue.setFieldDiff(context, "message", issue.message(), s);
issue.setMessage(s);
issue.setUpdateDate(context.date());
issue.setChanged(true);
+ return true;
}
+ return false;
+ }
+
+ public boolean setPastMessage(DefaultIssue issue, @Nullable String previousMessage, IssueChangeContext context) {
+ String currentMessage = issue.message();
+ issue.setMessage(previousMessage);
+ return setMessage(issue, currentMessage, context);
}
public void addComment(DefaultIssue issue, String text, IssueChangeContext context) {
return false;
}
+ public boolean setPastEffortToFix(DefaultIssue issue, @Nullable Double previousEffort, IssueChangeContext context) {
+ Double currentEffort = issue.effortToFix();
+ issue.setEffortToFix(previousEffort);
+ return setEffortToFix(issue, currentEffort, context);
+ }
+
public boolean setAttribute(DefaultIssue issue, String key, @Nullable String value, IssueChangeContext context) {
String oldValue = issue.attribute(key);
if (!Objects.equal(oldValue, value)) {
assertThat(diff.newValue()).isEqualTo("BLOCKER");
}
+ @Test
+ public void should_set_past_severity() throws Exception {
+ issue.setSeverity("BLOCKER");
+ boolean updated = updater.setPastSeverity(issue, "INFO", context);
+ assertThat(updated).isTrue();
+ assertThat(issue.severity()).isEqualTo("BLOCKER");
+
+ FieldDiffs.Diff diff = issue.diffs().get("severity");
+ assertThat(diff.oldValue()).isEqualTo("INFO");
+ assertThat(diff.newValue()).isEqualTo("BLOCKER");
+ }
+
@Test
public void should_update_severity() throws Exception {
issue.setSeverity("BLOCKER");
assertThat(issue.diffs()).isNull();
}
+ @Test
+ public void should_set_past_line() throws Exception {
+ issue.setLine(42);
+ boolean updated = updater.setPastLine(issue, 123);
+ assertThat(updated).isTrue();
+ assertThat(issue.line()).isEqualTo(42);
+
+ // do not save change
+ assertThat(issue.diffs()).isNull();
+ }
+
@Test
public void should_not_change_line() throws Exception {
issue.setLine(123);
assertThat(issue.isChanged()).isFalse();
assertThat(issue.effortToFix()).isEqualTo(3.14);
}
+
+ @Test
+ public void should_set_past_effort() throws Exception {
+ issue.setEffortToFix(3.14);
+ boolean updated = updater.setPastEffortToFix(issue, 1.0, context);
+ assertThat(updated).isTrue();
+ assertThat(issue.effortToFix()).isEqualTo(3.14);
+
+ // do not save change
+ assertThat(issue.diffs()).isNull();
+ }
+
+ @Test
+ public void should_set_message() throws Exception {
+ boolean updated = updater.setMessage(issue, "the message", context);
+ assertThat(updated).isTrue();
+ assertThat(issue.isChanged()).isTrue();
+ assertThat(issue.message()).isEqualTo("the message");
+ }
+
+ @Test
+ public void should_set_past_message() throws Exception {
+ issue.setMessage("new message");
+ boolean updated = updater.setPastMessage(issue, "past message", context);
+ assertThat(updated).isTrue();
+ assertThat(issue.message()).isEqualTo("new message");
+
+ // do not save change
+ assertThat(issue.diffs()).isNull();
+ }
+
+ @Test
+ public void should_set_author() throws Exception {
+ boolean updated = updater.setAuthorLogin(issue, "eric", context);
+ assertThat(updated).isTrue();
+ assertThat(issue.authorLogin()).isEqualTo("eric");
+
+ FieldDiffs.Diff diff = issue.diffs().get("author");
+ assertThat(diff.oldValue()).isNull();
+ assertThat(diff.newValue()).isEqualTo("eric");
+ }
}