Skip to content

Commit

Permalink
SONAR-11929 do not send issue notifications on PRs and short branches
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb authored and sonartech committed Apr 23, 2019
1 parent 0a0784c commit 7fc9093
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 51 deletions.
Expand Up @@ -53,6 +53,7 @@
import org.sonar.core.util.stream.MoreCollectors; import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient; import org.sonar.db.DbClient;
import org.sonar.db.DbSession; import org.sonar.db.DbSession;
import org.sonar.db.component.BranchType;
import org.sonar.db.user.UserDto; import org.sonar.db.user.UserDto;
import org.sonar.server.issue.notification.IssueChangeNotification; import org.sonar.server.issue.notification.IssueChangeNotification;
import org.sonar.server.issue.notification.MyNewIssuesNotification; import org.sonar.server.issue.notification.MyNewIssuesNotification;
Expand All @@ -67,6 +68,7 @@
import static java.util.stream.StreamSupport.stream; import static java.util.stream.StreamSupport.stream;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER; import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
import static org.sonar.db.component.BranchType.PULL_REQUEST; import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.BranchType.SHORT;


/** /**
* Reads issues from disk cache and send related notifications. For performance reasons, * Reads issues from disk cache and send related notifications. For performance reasons,
Expand Down Expand Up @@ -103,6 +105,11 @@ public SendIssueNotificationsStep(IssueCache issueCache, RuleRepository rules, T


@Override @Override
public void execute(ComputationStep.Context context) { public void execute(ComputationStep.Context context) {
BranchType branchType = analysisMetadataHolder.getBranch().getType();
if (branchType == PULL_REQUEST || branchType == SHORT) {
return;
}

Component project = treeRootHolder.getRoot(); Component project = treeRootHolder.getRoot();
NotificationStatistics notificationStatistics = new NotificationStatistics(); NotificationStatistics notificationStatistics = new NotificationStatistics();
if (service.hasProjectSubscribersForTypes(analysisMetadataHolder.getProject().getUuid(), NOTIF_TYPES)) { if (service.hasProjectSubscribersForTypes(analysisMetadataHolder.getProject().getUuid(), NOTIF_TYPES)) {
Expand Down
Expand Up @@ -52,6 +52,7 @@
import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.DefaultIssue;
import org.sonar.db.DbTester; import org.sonar.db.DbTester;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentDto;
import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.user.UserDto; import org.sonar.db.user.UserDto;
Expand Down Expand Up @@ -81,11 +82,14 @@
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.sonar.ce.task.projectanalysis.component.Component.Type; import static org.sonar.ce.task.projectanalysis.component.Component.Type;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder; import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.step.SendIssueNotificationsStep.NOTIF_TYPES; import static org.sonar.ce.task.projectanalysis.step.SendIssueNotificationsStep.NOTIF_TYPES;
import static org.sonar.db.component.BranchType.LONG;
import static org.sonar.db.component.BranchType.PULL_REQUEST; import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.BranchType.SHORT;
import static org.sonar.db.component.ComponentTesting.newBranchDto; import static org.sonar.db.component.ComponentTesting.newBranchDto;
import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
Expand Down Expand Up @@ -232,14 +236,14 @@ public void do_not_send_global_new_issues_notification_if_issue_has_been_backdat
} }


@Test @Test
public void send_global_new_issues_notification_on_branch() { public void send_global_new_issues_notification_on_long_branch() {
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto project = newPrivateProjectDto(newOrganizationDto());
ComponentDto branch = setUpBranch(project); ComponentDto branch = setUpBranch(project, LONG);
issueCache.newAppender().append( issueCache.newAppender().append(
new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close(); new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close();
when(notificationService.hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES)).thenReturn(true); when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), NOTIF_TYPES)).thenReturn(true);
analysisMetadataHolder.setProject(Project.from(project)); analysisMetadataHolder.setProject(Project.from(project));
analysisMetadataHolder.setBranch(newBranch()); analysisMetadataHolder.setBranch(newBranch(BranchType.LONG));


TestComputationStepContext context = new TestComputationStepContext(); TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context); underTest.execute(context);
Expand All @@ -253,9 +257,25 @@ public void send_global_new_issues_notification_on_branch() {
} }


@Test @Test
public void send_global_new_issues_notification_on_pull_request() { public void do_not_send_global_new_issues_notification_on_short_branch() {
ComponentDto project = newPrivateProjectDto(newOrganizationDto());
ComponentDto branch = setUpBranch(project, SHORT);
issueCache.newAppender().append(
new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close();
when(notificationService.hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES)).thenReturn(true);
analysisMetadataHolder.setProject(Project.from(project));
analysisMetadataHolder.setBranch(newBranch(SHORT));

TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);

verifyZeroInteractions(notificationService, newIssuesNotificationMock);
}

@Test
public void do_not_send_global_new_issues_notification_on_pull_request() {
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto project = newPrivateProjectDto(newOrganizationDto());
ComponentDto branch = setUpBranch(project); ComponentDto branch = setUpBranch(project, PULL_REQUEST);
issueCache.newAppender().append( issueCache.newAppender().append(
new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close(); new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close();
when(notificationService.hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES)).thenReturn(true); when(notificationService.hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES)).thenReturn(true);
Expand All @@ -266,23 +286,18 @@ public void send_global_new_issues_notification_on_pull_request() {
TestComputationStepContext context = new TestComputationStepContext(); TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context); underTest.execute(context);


verify(notificationService).deliver(newIssuesNotificationMock); verifyZeroInteractions(notificationService, newIssuesNotificationMock);
verify(newIssuesNotificationMock).setProject(branch.getKey(), branch.longName(), null, PULL_REQUEST_ID);
verify(newIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE));
verify(newIssuesNotificationMock).setStatistics(eq(branch.longName()), any(NewIssuesStatistics.Stats.class));
verify(newIssuesNotificationMock).setDebt(ISSUE_DURATION);
verifyStatistics(context, 1, 0, 0);
} }


@Test @Test
public void do_not_send_global_new_issues_notification_on_branch_if_issue_has_been_backdated() { public void do_not_send_global_new_issues_notification_on_long_branch_if_issue_has_been_backdated() {
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto project = newPrivateProjectDto(newOrganizationDto());
ComponentDto branch = setUpBranch(project); ComponentDto branch = setUpBranch(project, LONG);
issueCache.newAppender().append( issueCache.newAppender().append(
new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))).close(); new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))).close();
when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), NOTIF_TYPES)).thenReturn(true); when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), NOTIF_TYPES)).thenReturn(true);
analysisMetadataHolder.setProject(Project.from(project)); analysisMetadataHolder.setProject(Project.from(project));
analysisMetadataHolder.setBranch(newBranch()); analysisMetadataHolder.setBranch(newBranch(BranchType.LONG));


TestComputationStepContext context = new TestComputationStepContext(); TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context); underTest.execute(context);
Expand Down Expand Up @@ -535,16 +550,16 @@ private DefaultIssue prepareIssue(long issueCreatedAt, UserDto user, ComponentDt
} }


@Test @Test
public void send_issues_change_notification_on_branch() { public void send_issues_change_notification_on_long_branch() {
sendIssueChangeNotificationOnBranch(ANALYSE_DATE); sendIssueChangeNotificationOnLongBranch(ANALYSE_DATE);
} }


@Test @Test
public void send_issues_change_notification_on_branch_even_if_issue_is_backdated() { public void send_issues_change_notification_on_long_branch_even_if_issue_is_backdated() {
sendIssueChangeNotificationOnBranch(ANALYSE_DATE - FIVE_MINUTES_IN_MS); sendIssueChangeNotificationOnLongBranch(ANALYSE_DATE - FIVE_MINUTES_IN_MS);
} }


private void sendIssueChangeNotificationOnBranch(long issueCreatedAt) { private void sendIssueChangeNotificationOnLongBranch(long issueCreatedAt) {
ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto project = newPrivateProjectDto(newOrganizationDto());
ComponentDto branch = newProjectBranch(project, newBranchDto(project).setKey(BRANCH_NAME)); ComponentDto branch = newProjectBranch(project, newBranchDto(project).setKey(BRANCH_NAME));
ComponentDto file = newFileDto(branch); ComponentDto file = newFileDto(branch);
Expand All @@ -561,7 +576,7 @@ private void sendIssueChangeNotificationOnBranch(long issueCreatedAt) {
ruleRepository.add(ruleDefinitionDto.getKey()).setName(ruleDefinitionDto.getName()); ruleRepository.add(ruleDefinitionDto.getKey()).setName(ruleDefinitionDto.getName());
issueCache.newAppender().append(issue).close(); issueCache.newAppender().append(issue).close();
when(notificationService.hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES)).thenReturn(true); when(notificationService.hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES)).thenReturn(true);
analysisMetadataHolder.setBranch(newBranch()); analysisMetadataHolder.setBranch(newBranch(BranchType.LONG));


underTest.execute(new TestComputationStepContext()); underTest.execute(new TestComputationStepContext());


Expand Down Expand Up @@ -623,10 +638,11 @@ private MyNewIssuesNotification createMyNewIssuesNotificationMock() {
return notification; return notification;
} }


private static Branch newBranch() { private static Branch newBranch(BranchType type) {
Branch branch = mock(Branch.class); Branch branch = mock(Branch.class);
when(branch.isMain()).thenReturn(false); when(branch.isMain()).thenReturn(false);
when(branch.getName()).thenReturn(BRANCH_NAME); when(branch.getName()).thenReturn(BRANCH_NAME);
when(branch.getType()).thenReturn(type);
return branch; return branch;
} }


Expand All @@ -639,8 +655,8 @@ private static Branch newPullRequest() {
return branch; return branch;
} }


private ComponentDto setUpBranch(ComponentDto project) { private ComponentDto setUpBranch(ComponentDto project, BranchType branchType) {
ComponentDto branch = newProjectBranch(project, newBranchDto(project).setKey(BRANCH_NAME)); ComponentDto branch = newProjectBranch(project, newBranchDto(project, branchType).setKey(BRANCH_NAME));
ComponentDto file = newFileDto(branch); ComponentDto file = newFileDto(branch);
treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren(
builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build()); builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build());
Expand Down
Expand Up @@ -63,7 +63,7 @@ public final IssueDto insertIssue(Consumer<IssueDto>... populateIssueDto) {
@SafeVarargs @SafeVarargs
public final IssueDto insertIssue(OrganizationDto organizationDto, Consumer<IssueDto>... populators) { public final IssueDto insertIssue(OrganizationDto organizationDto, Consumer<IssueDto>... populators) {
RuleDefinitionDto rule = db.rules().insert(); RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPrivateProject(organizationDto); ComponentDto project = db.components().insertMainBranch(organizationDto);
ComponentDto file = db.components().insertComponent(newFileDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = newIssue(rule, project, file); IssueDto issue = newIssue(rule, project, file);
stream(populators).forEach(p -> p.accept(issue)); stream(populators).forEach(p -> p.accept(issue));
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.sonar.core.util.stream.MoreCollectors; import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient; import org.sonar.db.DbClient;
import org.sonar.db.DbSession; import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueDto; import org.sonar.db.issue.IssueDto;
import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDefinitionDto;
Expand All @@ -41,6 +42,8 @@
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.singleton; import static java.util.Collections.singleton;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.BranchType.SHORT;


public class IssueUpdater { public class IssueUpdater {


Expand All @@ -66,8 +69,9 @@ public SearchResponseData saveIssueAndPreloadSearchResponseData(DbSession dbSess


Optional<RuleDefinitionDto> rule = getRuleByKey(dbSession, issue.getRuleKey()); Optional<RuleDefinitionDto> rule = getRuleByKey(dbSession, issue.getRuleKey());
ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, issue.projectUuid()); ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, issue.projectUuid());
BranchDto branch = getBranch(dbSession, issue, issue.projectUuid());
ComponentDto component = getComponent(dbSession, issue, issue.componentUuid()); ComponentDto component = getComponent(dbSession, issue, issue.componentUuid());
IssueDto issueDto = doSaveIssue(dbSession, issue, context, comment, rule, project, component); IssueDto issueDto = doSaveIssue(dbSession, issue, context, comment, rule, project, branch, component);


SearchResponseData result = new SearchResponseData(issueDto); SearchResponseData result = new SearchResponseData(issueDto);
rule.ifPresent(r -> result.addRules(singletonList(r))); rule.ifPresent(r -> result.addRules(singletonList(r)));
Expand All @@ -85,14 +89,15 @@ public SearchResponseData saveIssueAndPreloadSearchResponseData(DbSession dbSess
public IssueDto saveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment) { public IssueDto saveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment) {
Optional<RuleDefinitionDto> rule = getRuleByKey(session, issue.getRuleKey()); Optional<RuleDefinitionDto> rule = getRuleByKey(session, issue.getRuleKey());
ComponentDto project = getComponent(session, issue, issue.projectUuid()); ComponentDto project = getComponent(session, issue, issue.projectUuid());
BranchDto branch = getBranch(session, issue, issue.projectUuid());
ComponentDto component = getComponent(session, issue, issue.componentUuid()); ComponentDto component = getComponent(session, issue, issue.componentUuid());
return doSaveIssue(session, issue, context, comment, rule, project, component); return doSaveIssue(session, issue, context, comment, rule, project, branch, component);
} }


private IssueDto doSaveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment, private IssueDto doSaveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment,
Optional<RuleDefinitionDto> rule, ComponentDto project, ComponentDto component) { Optional<RuleDefinitionDto> rule, ComponentDto project, BranchDto branch, ComponentDto component) {
IssueDto issueDto = issueStorage.save(session, singletonList(issue)).iterator().next(); IssueDto issueDto = issueStorage.save(session, singletonList(issue)).iterator().next();
if (issue.type() != RuleType.SECURITY_HOTSPOT) { if (issue.type() != RuleType.SECURITY_HOTSPOT && hasNotificationSupport(branch)) {
String assigneeUuid = issue.assignee(); String assigneeUuid = issue.assignee();
UserDto assignee = assigneeUuid == null ? null : dbClient.userDao().selectByUuid(session, assigneeUuid); UserDto assignee = assigneeUuid == null ? null : dbClient.userDao().selectByUuid(session, assigneeUuid);
String authorUuid = context.userUuid(); String authorUuid = context.userUuid();
Expand All @@ -109,6 +114,10 @@ private IssueDto doSaveIssue(DbSession session, DefaultIssue issue, IssueChangeC
return issueDto; return issueDto;
} }


private static boolean hasNotificationSupport(BranchDto branch) {
return branch.getBranchType() != PULL_REQUEST && branch.getBranchType() != SHORT;
}

private ComponentDto getComponent(DbSession dbSession, DefaultIssue issue, @Nullable String componentUuid) { private ComponentDto getComponent(DbSession dbSession, DefaultIssue issue, @Nullable String componentUuid) {
String issueKey = issue.key(); String issueKey = issue.key();
checkState(componentUuid != null, "Issue '%s' has no component", issueKey); checkState(componentUuid != null, "Issue '%s' has no component", issueKey);
Expand All @@ -117,6 +126,14 @@ private ComponentDto getComponent(DbSession dbSession, DefaultIssue issue, @Null
return component; return component;
} }


private BranchDto getBranch(DbSession dbSession, DefaultIssue issue, @Nullable String projectUuid) {
String issueKey = issue.key();
checkState(projectUuid != null, "Issue '%s' has no project", issueKey);
BranchDto component = dbClient.branchDao().selectByUuid(dbSession, projectUuid).orElse(null);
checkState(component != null, "Branch uuid '%s' for issue key '%s' cannot be found", projectUuid, issueKey);
return component;
}

private Optional<RuleDefinitionDto> getRuleByKey(DbSession session, RuleKey ruleKey) { private Optional<RuleDefinitionDto> getRuleByKey(DbSession session, RuleKey ruleKey) {
Optional<RuleDefinitionDto> rule = dbClient.ruleDao().selectDefinitionByKey(session, ruleKey); Optional<RuleDefinitionDto> rule = dbClient.ruleDao().selectDefinitionByKey(session, ruleKey);
return (rule.isPresent() && rule.get().getStatus() != RuleStatus.REMOVED) ? rule : Optional.empty(); return (rule.isPresent() && rule.get().getStatus() != RuleStatus.REMOVED) ? rule : Optional.empty();
Expand Down
Expand Up @@ -30,6 +30,7 @@
import java.util.Set; import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import javax.annotation.Nullable;
import org.sonar.api.issue.DefaultTransitions; import org.sonar.api.issue.DefaultTransitions;
import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity; import org.sonar.api.rule.Severity;
Expand All @@ -47,6 +48,8 @@
import org.sonar.core.util.stream.MoreCollectors; import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient; import org.sonar.db.DbClient;
import org.sonar.db.DbSession; import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueDto; import org.sonar.db.issue.IssueDto;
import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDefinitionDto;
Expand Down Expand Up @@ -253,17 +256,24 @@ private static void addCommentIfNeeded(ActionContext actionContext, BulkChangeDa
private Consumer<DefaultIssue> sendNotification(BulkChangeData bulkChangeData, Map<String, UserDto> userDtoByUuid, UserDto author) { private Consumer<DefaultIssue> sendNotification(BulkChangeData bulkChangeData, Map<String, UserDto> userDtoByUuid, UserDto author) {
return issue -> { return issue -> {
if (bulkChangeData.sendNotification && issue.type() != RuleType.SECURITY_HOTSPOT) { if (bulkChangeData.sendNotification && issue.type() != RuleType.SECURITY_HOTSPOT) {
notificationService.scheduleForSending(new IssueChangeNotification() BranchDto branch = bulkChangeData.branchesByProjectUuid.get(issue.projectUuid());
.setIssue(issue) if (hasNotificationSupport(branch)) {
.setAssignee(userDtoByUuid.get(issue.assignee())) notificationService.scheduleForSending(new IssueChangeNotification()
.setChangeAuthor(author) .setIssue(issue)
.setRuleName(bulkChangeData.rulesByKey.get(issue.ruleKey()).getName()) .setAssignee(userDtoByUuid.get(issue.assignee()))
.setProject(bulkChangeData.projectsByUuid.get(issue.projectUuid())) .setChangeAuthor(author)
.setComponent(bulkChangeData.componentsByUuid.get(issue.componentUuid()))); .setRuleName(bulkChangeData.rulesByKey.get(issue.ruleKey()).getName())
.setProject(bulkChangeData.projectsByUuid.get(issue.projectUuid()))
.setComponent(bulkChangeData.componentsByUuid.get(issue.componentUuid())));
}
} }
}; };
} }


private static boolean hasNotificationSupport(@Nullable BranchDto branch) {
return branch != null && branch.getBranchType() != BranchType.PULL_REQUEST && branch.getBranchType() != BranchType.SHORT;
}

private static Issues.BulkChangeWsResponse toWsResponse(BulkChangeResult result) { private static Issues.BulkChangeWsResponse toWsResponse(BulkChangeResult result) {
return Issues.BulkChangeWsResponse.newBuilder() return Issues.BulkChangeWsResponse.newBuilder()
.setTotal(result.countTotal()) .setTotal(result.countTotal())
Expand Down Expand Up @@ -305,6 +315,7 @@ private class BulkChangeData {
private final boolean sendNotification; private final boolean sendNotification;
private final Collection<DefaultIssue> issues; private final Collection<DefaultIssue> issues;
private final Map<String, ComponentDto> projectsByUuid; private final Map<String, ComponentDto> projectsByUuid;
private final Map<String, BranchDto> branchesByProjectUuid;
private final Map<String, ComponentDto> componentsByUuid; private final Map<String, ComponentDto> componentsByUuid;
private final Map<RuleKey, RuleDefinitionDto> rulesByKey; private final Map<RuleKey, RuleDefinitionDto> rulesByKey;
private final List<Action> availableActions; private final List<Action> availableActions;
Expand All @@ -319,6 +330,8 @@ private class BulkChangeData {


List<ComponentDto> allProjects = getComponents(dbSession, allIssues.stream().map(IssueDto::getProjectUuid).collect(MoreCollectors.toSet())); List<ComponentDto> allProjects = getComponents(dbSession, allIssues.stream().map(IssueDto::getProjectUuid).collect(MoreCollectors.toSet()));
this.projectsByUuid = getAuthorizedProjects(allProjects).stream().collect(uniqueIndex(ComponentDto::uuid, identity())); this.projectsByUuid = getAuthorizedProjects(allProjects).stream().collect(uniqueIndex(ComponentDto::uuid, identity()));
this.branchesByProjectUuid = dbClient.branchDao().selectByUuids(dbSession, projectsByUuid.keySet()).stream()
.collect(uniqueIndex(BranchDto::getUuid, identity()));
this.issues = getAuthorizedIssues(allIssues); this.issues = getAuthorizedIssues(allIssues);
this.componentsByUuid = getComponents(dbSession, this.componentsByUuid = getComponents(dbSession,
issues.stream().map(DefaultIssue::componentUuid).collect(MoreCollectors.toSet())).stream() issues.stream().map(DefaultIssue::componentUuid).collect(MoreCollectors.toSet())).stream()
Expand Down

0 comments on commit 7fc9093

Please sign in to comment.