Search in sources :

Example 31 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class WebHooksImpl method readWebHooksFrom.

private Stream<WebhookDto> readWebHooksFrom(String projectUuid, @CheckForNull PostProjectAnalysisTask.LogStatistics taskLogStatistics) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Optional<ProjectDto> optionalProjectDto = dbClient.projectDao().selectByUuid(dbSession, projectUuid);
        ProjectDto projectDto = checkStateWithOptional(optionalProjectDto, "the requested project '%s' was not found", projectUuid);
        WebhookDao dao = dbClient.webhookDao();
        List<WebhookDto> projectWebhooks = dao.selectByProject(dbSession, projectDto);
        List<WebhookDto> globalWebhooks = dao.selectGlobalWebhooks(dbSession);
        if (taskLogStatistics != null) {
            taskLogStatistics.add("globalWebhooks", globalWebhooks.size());
            taskLogStatistics.add("projectWebhooks", projectWebhooks.size());
        }
        return Stream.concat(projectWebhooks.stream(), globalWebhooks.stream());
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) DbSession(org.sonar.db.DbSession) WebhookDao(org.sonar.db.webhook.WebhookDao)

Example 32 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class SynchronousWebHooksImplTest method send_project_webhooks.

@Test
public void send_project_webhooks() {
    ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
    webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getKey(), projectDto.getName());
    caller.enqueueSuccess(NOW, 200, 1_234);
    underTest.sendProjectAnalysisUpdate(new WebHooks.Analysis(projectDto.getUuid(), "1", "#1"), () -> mock, taskStatistics);
    assertThat(caller.countSent()).isOne();
    assertThat(logTester.logs(DEBUG)).contains("Sent webhook 'First' | url=http://url1 | time=1234ms | status=200");
    verify(deliveryStorage).persist(any(WebhookDelivery.class));
    verify(deliveryStorage).purge(projectDto.getUuid());
    verifyLogStatistics(0, 1);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) Test(org.junit.Test)

Example 33 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class SynchronousWebHooksImplTest method isEnabled_returns_false_if_no_webhooks.

@Test
public void isEnabled_returns_false_if_no_webhooks() {
    ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
    assertThat(underTest.isEnabled(projectDto)).isFalse();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) Test(org.junit.Test)

Example 34 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class QualityProfileChangeEventServiceImplTest method distributeRuleChangeEvent.

@Test
public void distributeRuleChangeEvent() {
    QProfileDto qualityProfileDto = QualityProfileTesting.newQualityProfileDto();
    // Template rule
    RuleDto templateRule = newTemplateRule(RuleKey.of("xoo", "template-key"));
    db.rules().insert(templateRule.getDefinition());
    // Custom rule
    RuleDefinitionDto rule1 = newCustomRule(templateRule.getDefinition()).setLanguage("xoo").setDescription("<div>line1\nline2</div>").setDescriptionFormat(MARKDOWN);
    db.rules().insert(rule1);
    ActiveRuleDto activeRuleDto = ActiveRuleDto.createFor(qualityProfileDto, rule1);
    ActiveRuleChange activeRuleChange = new ActiveRuleChange(ACTIVATED, activeRuleDto, rule1);
    activeRuleChange.setParameter("paramChangeKey", "paramChangeValue");
    Collection<QProfileDto> profiles = Collections.singleton(qualityProfileDto);
    ProjectDto project = db.components().insertPrivateProjectDto();
    db.qualityProfiles().associateWithProject(project, qualityProfileDto);
    underTest.distributeRuleChangeEvent(profiles, of(activeRuleChange), "xoo");
    ArgumentCaptor<RuleSetChangedEvent> eventCaptor = ArgumentCaptor.forClass(RuleSetChangedEvent.class);
    verify(eventsDistributor).pushEvent(eventCaptor.capture());
    RuleSetChangedEvent ruleSetChangedEvent = eventCaptor.getValue();
    assertThat(ruleSetChangedEvent).isNotNull();
    assertThat(ruleSetChangedEvent).extracting(RuleSetChangedEvent::getEvent, RuleSetChangedEvent::getLanguage, RuleSetChangedEvent::getProjects).containsExactly("RuleSetChanged", "xoo", new String[] { project.getKey() });
    assertThat(ruleSetChangedEvent.getActivatedRules()).extracting(RuleChange::getKey, RuleChange::getLanguage, RuleChange::getSeverity, RuleChange::getTemplateKey).containsExactly(tuple(rule1.getRuleKey(), "xoo", null, "template-key"));
    assertThat(ruleSetChangedEvent.getActivatedRules()[0].getParams()).hasSize(1);
    ParamChange actualParamChange = ruleSetChangedEvent.getActivatedRules()[0].getParams()[0];
    assertThat(actualParamChange).extracting(ParamChange::getKey, ParamChange::getValue).containsExactly("paramChangeKey", "paramChangeValue");
    assertThat(ruleSetChangedEvent.getDeactivatedRules()).isEmpty();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ParamChange(org.sonar.core.util.ParamChange) ActiveRuleChange(org.sonar.server.qualityprofile.ActiveRuleChange) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleSetChangedEvent(org.sonar.core.util.RuleSetChangedEvent) Test(org.junit.Test)

Example 35 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class SearchAzureReposAction method toAzureRepo.

private static AzureRepo toAzureRepo(GsonAzureRepo azureRepo, Map<ProjectKeyName, ProjectDto> sqProjectsKeyByAzureKey) {
    AzureRepo.Builder builder = AzureRepo.newBuilder().setName(azureRepo.getName()).setProjectName(azureRepo.getProject().getName());
    ProjectDto projectDto = sqProjectsKeyByAzureKey.get(ProjectKeyName.from(azureRepo));
    if (projectDto != null) {
        builder.setSqProjectName(projectDto.getName());
        builder.setSqProjectKey(projectDto.getKey());
    }
    return builder.build();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) GsonAzureRepo(org.sonar.alm.client.azure.GsonAzureRepo) AzureRepo(org.sonarqube.ws.AlmIntegrations.AzureRepo)

Aggregations

ProjectDto (org.sonar.db.project.ProjectDto)283 Test (org.junit.Test)215 DbSession (org.sonar.db.DbSession)49 BranchDto (org.sonar.db.component.BranchDto)42 UserDto (org.sonar.db.user.UserDto)39 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)38 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 SnapshotDto (org.sonar.db.component.SnapshotDto)27 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)26 ComponentDto (org.sonar.db.component.ComponentDto)23 ComponentTesting.newPrivateProjectDto (org.sonar.db.component.ComponentTesting.newPrivateProjectDto)20 NotFoundException (org.sonar.server.exceptions.NotFoundException)17 WebhookDto (org.sonar.db.webhook.WebhookDto)15 ApplicationProjectDto (org.sonar.db.project.ApplicationProjectDto)14 WebService (org.sonar.api.server.ws.WebService)13 DbClient (org.sonar.db.DbClient)12 PortfolioProjectDto (org.sonar.db.portfolio.PortfolioProjectDto)12 TestRequest (org.sonar.server.ws.TestRequest)11 TestResponse (org.sonar.server.ws.TestResponse)10 Projects (org.sonarqube.ws.Projects)10