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());
}
}
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);
}
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();
}
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();
}
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();
}
Aggregations