use of org.sonar.server.issue.notification.IssueChangeNotification in project sonarqube by SonarSource.
the class SendIssueNotificationsStep method sendIssueChangeNotification.
private void sendIssueChangeNotification(DefaultIssue issue, Component project) {
IssueChangeNotification changeNotification = new IssueChangeNotification();
changeNotification.setRuleName(rules.getByKey(issue.ruleKey()).getName());
changeNotification.setIssue(issue);
changeNotification.setProject(project.getKey(), project.getName());
service.deliver(changeNotification);
}
use of org.sonar.server.issue.notification.IssueChangeNotification in project sonarqube by SonarSource.
the class IssueUpdater method saveIssue.
public void saveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment) {
issueStorage.save(session, issue);
Optional<RuleDto> rule = getRuleByKey(session, issue.getRuleKey());
ComponentDto project = dbClient.componentDao().selectOrFailByUuid(session, issue.projectUuid());
notificationService.scheduleForSending(new IssueChangeNotification().setIssue(issue).setChangeAuthorLogin(context.login()).setRuleName(rule.isPresent() ? rule.get().getName() : null).setProject(project.getKey(), project.name()).setComponent(dbClient.componentDao().selectOrFailByUuid(session, issue.componentUuid())).setComment(comment));
}
use of org.sonar.server.issue.notification.IssueChangeNotification in project sonarqube by SonarSource.
the class BulkChangeActionTest method send_notification_only_on_changed_issues.
@Test
public void send_notification_only_on_changed_issues() throws Exception {
setUserProjectPermissions(USER, ISSUE_ADMIN);
IssueDto issue1 = db.issues().insertIssue(newUnresolvedIssue().setType(BUG));
IssueDto issue2 = db.issues().insertIssue(newUnresolvedIssue().setType(BUG));
IssueDto issue3 = db.issues().insertIssue(newUnresolvedIssue().setType(VULNERABILITY));
ArgumentCaptor<IssueChangeNotification> issueChangeNotificationCaptor = ArgumentCaptor.forClass(IssueChangeNotification.class);
BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(asList(issue1.getKey(), issue2.getKey(), issue3.getKey())).setSetType(RuleType.BUG.name()).setSendNotifications(true).build());
checkResponse(response, 3, 1, 2, 0);
verify(notificationManager).scheduleForSending(issueChangeNotificationCaptor.capture());
assertThat(issueChangeNotificationCaptor.getAllValues()).hasSize(1);
assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("key")).isEqualTo(issue3.getKey());
}
use of org.sonar.server.issue.notification.IssueChangeNotification in project sonarqube by SonarSource.
the class BulkChangeActionTest method send_notification.
@Test
public void send_notification() throws Exception {
setUserProjectPermissions(USER);
IssueDto issueDto = db.issues().insertIssue(newUnresolvedIssue().setType(BUG));
ArgumentCaptor<IssueChangeNotification> issueChangeNotificationCaptor = ArgumentCaptor.forClass(IssueChangeNotification.class);
BulkChangeWsResponse response = call(BulkChangeRequest.builder().setIssues(singletonList(issueDto.getKey())).setDoTransition("confirm").setSendNotifications(true).build());
checkResponse(response, 1, 1, 0, 0);
verify(notificationManager).scheduleForSending(issueChangeNotificationCaptor.capture());
assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("key")).isEqualTo(issueDto.getKey());
assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("componentName")).isEqualTo(file.longName());
assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("projectName")).isEqualTo(project.longName());
assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("projectKey")).isEqualTo(project.key());
assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("ruleName")).isEqualTo(rule.getName());
assertThat(issueChangeNotificationCaptor.getValue().getFieldValue("changeAuthor")).isEqualTo(user.getLogin());
}
use of org.sonar.server.issue.notification.IssueChangeNotification in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_notification.
@Test
public void verify_notification() throws Exception {
RuleDto rule = ruleDbTester.insertRule(newRuleDto());
ComponentDto project = componentDbTester.insertProject();
ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
DefaultIssue issue = issueDbTester.insertIssue(newDto(rule, file, project)).setSeverity(MAJOR).toDefaultIssue();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
underTest.saveIssue(dbTester.getSession(), issue, context, "increase severity");
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue();
assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key());
assertThat(issueChangeNotification.getFieldValue("old.severity")).isEqualTo(MAJOR);
assertThat(issueChangeNotification.getFieldValue("new.severity")).isEqualTo(BLOCKER);
assertThat(issueChangeNotification.getFieldValue("componentKey")).isEqualTo(file.key());
assertThat(issueChangeNotification.getFieldValue("componentName")).isEqualTo(file.longName());
assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.key());
assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.name());
assertThat(issueChangeNotification.getFieldValue("ruleName")).isEqualTo(rule.getName());
assertThat(issueChangeNotification.getFieldValue("changeAuthor")).isEqualTo("john");
assertThat(issueChangeNotification.getFieldValue("comment")).isEqualTo("increase severity");
}
Aggregations