Search in sources :

Example 1 with IssueChangeNotification

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);
}
Also used : IssueChangeNotification(org.sonar.server.issue.notification.IssueChangeNotification)

Example 2 with IssueChangeNotification

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));
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueChangeNotification(org.sonar.server.issue.notification.IssueChangeNotification)

Example 3 with IssueChangeNotification

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());
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) IssueChangeNotification(org.sonar.server.issue.notification.IssueChangeNotification) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 4 with IssueChangeNotification

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());
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) IssueChangeNotification(org.sonar.server.issue.notification.IssueChangeNotification) BulkChangeWsResponse(org.sonarqube.ws.Issues.BulkChangeWsResponse) Test(org.junit.Test)

Example 5 with IssueChangeNotification

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");
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) RuleTesting.newRuleDto(org.sonar.db.rule.RuleTesting.newRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssueChangeNotification(org.sonar.server.issue.notification.IssueChangeNotification) Date(java.util.Date) Test(org.junit.Test)

Aggregations

IssueChangeNotification (org.sonar.server.issue.notification.IssueChangeNotification)5 Test (org.junit.Test)3 ComponentDto (org.sonar.db.component.ComponentDto)2 IssueDto (org.sonar.db.issue.IssueDto)2 RuleDto (org.sonar.db.rule.RuleDto)2 BulkChangeWsResponse (org.sonarqube.ws.Issues.BulkChangeWsResponse)2 Date (java.util.Date)1 DefaultIssue (org.sonar.core.issue.DefaultIssue)1 IssueChangeContext (org.sonar.core.issue.IssueChangeContext)1 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)1