use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class ProtobufIssueDiskCache method toProto.
private static IssueCache.Issue toProto(IssueCache.Issue.Builder builder, DefaultIssue defaultIssue) {
builder.clear();
builder.setKey(defaultIssue.key());
builder.setRuleType(defaultIssue.type().getDbConstant());
ofNullable(defaultIssue.componentUuid()).ifPresent(builder::setComponentUuid);
builder.setComponentKey(defaultIssue.componentKey());
ofNullable(defaultIssue.moduleUuid()).ifPresent(builder::setModuleUuid);
ofNullable(defaultIssue.moduleUuidPath()).ifPresent(builder::setModuleUuidPath);
builder.setProjectUuid(defaultIssue.projectUuid());
builder.setProjectKey(defaultIssue.projectKey());
builder.setRuleKey(defaultIssue.ruleKey().toString());
ofNullable(defaultIssue.language()).ifPresent(builder::setLanguage);
ofNullable(defaultIssue.severity()).ifPresent(builder::setSeverity);
builder.setManualSeverity(defaultIssue.manualSeverity());
ofNullable(defaultIssue.message()).ifPresent(builder::setMessage);
ofNullable(defaultIssue.line()).ifPresent(builder::setLine);
ofNullable(defaultIssue.gap()).ifPresent(builder::setGap);
ofNullable(defaultIssue.effort()).map(Duration::toMinutes).ifPresent(builder::setEffort);
builder.setStatus(defaultIssue.status());
ofNullable(defaultIssue.resolution()).ifPresent(builder::setResolution);
ofNullable(defaultIssue.assignee()).ifPresent(builder::setAssigneeUuid);
ofNullable(defaultIssue.checksum()).ifPresent(builder::setChecksum);
ofNullable(defaultIssue.authorLogin()).ifPresent(builder::setAuthorLogin);
defaultIssue.defaultIssueComments().forEach(c -> builder.addComments(toProtoComment(c)));
ofNullable(defaultIssue.tags()).ifPresent(t -> builder.setTags(String.join(TAGS_SEPARATOR, t)));
ofNullable(defaultIssue.getLocations()).ifPresent(l -> builder.setLocations((DbIssues.Locations) l));
builder.setIsFromExternalRuleEngine(defaultIssue.isFromExternalRuleEngine());
builder.setCreationDate(defaultIssue.creationDate().getTime());
ofNullable(defaultIssue.updateDate()).map(Date::getTime).ifPresent(builder::setUpdateDate);
ofNullable(defaultIssue.closeDate()).map(Date::getTime).ifPresent(builder::setCloseDate);
ofNullable(defaultIssue.currentChange()).ifPresent(c -> builder.setCurrentChanges(toProtoIssueChanges(c)));
builder.setIsNew(defaultIssue.isNew());
builder.setIsOnReferencedBranch(defaultIssue.isOnReferencedBranch());
builder.setIsOnChangedLine(defaultIssue.isOnChangedLine());
builder.setIsCopied(defaultIssue.isCopied());
builder.setBeingClosed(defaultIssue.isBeingClosed());
builder.setOnDisabledRule(defaultIssue.isOnDisabledRule());
builder.setIsChanged(defaultIssue.isChanged());
builder.setSendNotifications(defaultIssue.mustSendNotifications());
ofNullable(defaultIssue.selectedAt()).ifPresent(builder::setSelectedAt);
builder.setQuickFixAvailable(defaultIssue.isQuickFixAvailable());
builder.setIsNoLongerNewCodeReferenceIssue(defaultIssue.isNoLongerNewCodeReferenceIssue());
for (FieldDiffs fieldDiffs : defaultIssue.changes()) {
builder.addChanges(toProtoIssueChanges(fieldDiffs));
}
return builder.build();
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class ProtobufIssueDiskCache method toProtoIssueChanges.
private static IssueCache.FieldDiffs toProtoIssueChanges(FieldDiffs fieldDiffs) {
IssueCache.FieldDiffs.Builder builder = IssueCache.FieldDiffs.newBuilder().setCreationDate(fieldDiffs.creationDate().getTime());
if (fieldDiffs.issueKey() != null) {
builder.setIssueKey(fieldDiffs.issueKey());
}
String userUuid = fieldDiffs.userUuid();
if (userUuid != null) {
builder.setUserUuid(userUuid);
}
for (Map.Entry<String, FieldDiffs.Diff> e : fieldDiffs.diffs().entrySet()) {
IssueCache.Diff.Builder diffBuilder = IssueCache.Diff.newBuilder();
Serializable oldValue = e.getValue().oldValue();
if (oldValue != null) {
diffBuilder.setOldValue(oldValue.toString());
}
Serializable newValue = e.getValue().newValue();
if (newValue != null) {
diffBuilder.setNewValue(newValue.toString());
}
builder.putDiffs(e.getKey(), diffBuilder.build());
}
return builder.build();
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class PreviousStatusWas method matches.
@Override
public boolean matches(Issue issue) {
DefaultIssue defaultIssue = (DefaultIssue) issue;
Optional<String> lastPreviousStatus = defaultIssue.changes().stream().filter(change -> change != defaultIssue.currentChange()).filter(change -> change.creationDate() != null).sorted(Comparator.comparing(FieldDiffs::creationDate).reversed()).map(change -> change.get("status")).filter(Objects::nonNull).findFirst().map(t -> (String) t.oldValue());
return lastPreviousStatus.filter(this.expectedPreviousStatus::equals).isPresent();
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueLifecycleTest method mergeIssueFromPRIntoBranch.
@Test
public void mergeIssueFromPRIntoBranch() {
DefaultIssue raw = new DefaultIssue().setKey("raw");
DefaultIssue fromShort = new DefaultIssue().setKey("short").setIsNewCodeReferenceIssue(true);
fromShort.setResolution("resolution");
fromShort.setStatus("status");
Date commentDate = new Date();
fromShort.addComment(new DefaultIssueComment().setIssueKey("short").setCreatedAt(commentDate).setUserUuid("user_uuid").setMarkdownText("A comment"));
Date diffDate = new Date();
// file diff alone
fromShort.addChange(new FieldDiffs().setCreationDate(diffDate).setIssueKey("short").setUserUuid("user_uuid").setDiff("file", "uuidA1", "uuidB1"));
// file diff with another field
fromShort.addChange(new FieldDiffs().setCreationDate(diffDate).setIssueKey("short").setUserUuid("user_uuid").setDiff("severity", "MINOR", "MAJOR").setDiff("file", "uuidA2", "uuidB2"));
Branch branch = mock(Branch.class);
when(branch.getName()).thenReturn("master");
analysisMetadataHolder.setBranch(branch);
underTest.mergeConfirmedOrResolvedFromPrOrBranch(raw, fromShort, BranchType.PULL_REQUEST, "2");
assertThat(raw.resolution()).isEqualTo("resolution");
assertThat(raw.status()).isEqualTo("status");
assertThat(raw.defaultIssueComments()).extracting(DefaultIssueComment::issueKey, DefaultIssueComment::createdAt, DefaultIssueComment::userUuid, DefaultIssueComment::markdownText).containsOnly(tuple("raw", commentDate, "user_uuid", "A comment"));
assertThat(raw.changes()).hasSize(2);
assertThat(raw.changes().get(0).creationDate()).isEqualTo(diffDate);
assertThat(raw.changes().get(0).userUuid()).isEqualTo("user_uuid");
assertThat(raw.changes().get(0).issueKey()).isEqualTo("raw");
assertThat(raw.changes().get(0).diffs()).containsOnlyKeys("severity");
assertThat(raw.changes().get(1).userUuid()).isEqualTo("default_user_uuid");
assertThat(raw.changes().get(1).diffs()).containsOnlyKeys(IssueFieldsSetter.FROM_BRANCH);
assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).oldValue()).isEqualTo("#2");
assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).newValue()).isEqualTo("master");
assertThat(raw.isNewCodeReferenceIssue()).isTrue();
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueLifecycleTest method copyExistingIssuesFromSourceBranchOfPullRequest.
@Test
public void copyExistingIssuesFromSourceBranchOfPullRequest() {
String pullRequestKey = "1";
Branch branch = mock(Branch.class);
when(branch.getType()).thenReturn(BranchType.PULL_REQUEST);
when(branch.getName()).thenReturn("sourceBranch-1");
when(branch.getPullRequestKey()).thenReturn(pullRequestKey);
analysisMetadataHolder.setBranch(branch);
analysisMetadataHolder.setPullRequestKey(pullRequestKey);
DefaultIssue raw = new DefaultIssue().setKey("raw");
DefaultIssue fromShort = new DefaultIssue().setKey("short");
fromShort.setResolution("resolution");
fromShort.setStatus("status");
Date commentDate = new Date();
fromShort.addComment(new DefaultIssueComment().setIssueKey("short").setCreatedAt(commentDate).setUserUuid("user_uuid").setMarkdownText("A comment"));
Date diffDate = new Date();
// file diff alone
fromShort.addChange(new FieldDiffs().setCreationDate(diffDate).setIssueKey("short").setUserUuid("user_uuid").setDiff("file", "uuidA1", "uuidB1"));
// file diff with another field
fromShort.addChange(new FieldDiffs().setCreationDate(diffDate).setIssueKey("short").setUserUuid("user_uuid").setDiff("severity", "MINOR", "MAJOR").setDiff("file", "uuidA2", "uuidB2"));
underTest.copyExistingIssueFromSourceBranchToPullRequest(raw, fromShort);
assertThat(raw.resolution()).isEqualTo("resolution");
assertThat(raw.status()).isEqualTo("status");
assertThat(raw.defaultIssueComments()).extracting(DefaultIssueComment::issueKey, DefaultIssueComment::createdAt, DefaultIssueComment::userUuid, DefaultIssueComment::markdownText).containsOnly(tuple("raw", commentDate, "user_uuid", "A comment"));
assertThat(raw.changes()).hasSize(2);
assertThat(raw.changes().get(0).creationDate()).isEqualTo(diffDate);
assertThat(raw.changes().get(0).userUuid()).isEqualTo("user_uuid");
assertThat(raw.changes().get(0).issueKey()).isEqualTo("raw");
assertThat(raw.changes().get(0).diffs()).containsOnlyKeys("severity");
assertThat(raw.changes().get(1).userUuid()).isEqualTo("default_user_uuid");
assertThat(raw.changes().get(1).diffs()).containsOnlyKeys(IssueFieldsSetter.FROM_BRANCH);
assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).oldValue()).isEqualTo("sourceBranch-1");
assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_BRANCH).newValue()).isEqualTo("#1");
}
Aggregations