use of org.sonar.db.component.BranchType.PULL_REQUEST in project sonarqube by SonarSource.
the class ComponentTreeActionTest method pull_request.
@Test
public void pull_request() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
SnapshotDto analysis = db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr-123").setParam(PARAM_METRIC_KEYS, complexity.getKey()).executeProtobuf(ComponentTreeWsResponse.class);
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getPullRequest).containsExactlyInAnyOrder(file.getKey(), "pr-123");
assertThat(response.getBaseComponent().getMeasuresList()).extracting(Measure::getMetric, m -> parseDouble(m.getValue())).containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
}
use of org.sonar.db.component.BranchType.PULL_REQUEST in project sonarqube by SonarSource.
the class AsyncIssueIndexingImplTest method characteristics_are_defined.
@Test
public void characteristics_are_defined() {
BranchDto dto = new BranchDto().setBranchType(BRANCH).setKey("branch_1").setUuid("branch_uuid1").setProjectUuid("project_uuid1");
dbClient.branchDao().insert(dbTester.getSession(), dto);
dbTester.commit();
insertSnapshot("analysis_1", "project_uuid1", 1);
BranchDto dto2 = new BranchDto().setBranchType(PULL_REQUEST).setKey("pr_1").setUuid("pr_uuid_1").setProjectUuid("project_uuid2");
dbClient.branchDao().insert(dbTester.getSession(), dto2);
dbTester.commit();
insertSnapshot("analysis_2", "project_uuid2", 2);
underTest.triggerOnIndexCreation();
ArgumentCaptor<Collection<CeTaskSubmit>> captor = ArgumentCaptor.forClass(Collection.class);
verify(ceQueue, times(1)).massSubmit(captor.capture());
List<Collection<CeTaskSubmit>> captures = captor.getAllValues();
assertThat(captures).hasSize(1);
Collection<CeTaskSubmit> tasks = captures.get(0);
assertThat(tasks).hasSize(2);
assertThat(tasks).extracting(p -> p.getCharacteristics().get(BRANCH_TYPE_KEY), p -> p.getCharacteristics().get(CeTaskCharacteristicDto.BRANCH_KEY), p -> p.getCharacteristics().get(CeTaskCharacteristicDto.PULL_REQUEST)).containsExactlyInAnyOrder(tuple("BRANCH", "branch_1", null), tuple("PULL_REQUEST", null, "pr_1"));
}
use of org.sonar.db.component.BranchType.PULL_REQUEST in project sonarqube by SonarSource.
the class ListActionTest method response_contains_date_of_last_analysis.
@Test
public void response_contains_date_of_last_analysis() {
Long lastAnalysisNonMainBranch = dateToLong(parseDateTime("2017-04-01T00:00:00+0100"));
Long previousAnalysisPullRequest = dateToLong(parseDateTime("2017-04-02T00:00:00+0100"));
Long lastAnalysisPullRequest = dateToLong(parseDateTime("2017-04-03T00:00:00+0100"));
ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto pullRequest1 = db.components().insertProjectBranch(project, b -> b.setKey("pr1").setBranchType(PULL_REQUEST).setMergeBranchUuid(project.uuid()).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/pr1").build()));
ComponentDto nonMainBranch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
ComponentDto pullRequest2 = db.components().insertProjectBranch(project, b -> b.setKey("pr2").setBranchType(PULL_REQUEST).setMergeBranchUuid(nonMainBranch2.uuid()).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/pr2").build()));
db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(nonMainBranch2).setCreatedAt(lastAnalysisNonMainBranch));
db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(pullRequest2).setCreatedAt(previousAnalysisPullRequest).setLast(false));
db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(pullRequest2).setCreatedAt(lastAnalysisPullRequest));
db.commit();
indexIssues();
permissionIndexerTester.allowOnlyAnyone(project);
ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
assertThat(response.getPullRequestsList()).extracting(PullRequest::hasAnalysisDate, b -> "".equals(b.getAnalysisDate()) ? null : dateToLong(parseDateTime(b.getAnalysisDate()))).containsExactlyInAnyOrder(tuple(false, null), tuple(true, lastAnalysisPullRequest));
}
use of org.sonar.db.component.BranchType.PULL_REQUEST in project sonarqube by SonarSource.
the class ComponentKeyUpdaterDaoTest method updateKey_updates_pull_requests_too.
@Test
public void updateKey_updates_pull_requests_too() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
db.components().insertComponent(newFileDto(pullRequest));
db.components().insertComponent(newFileDto(pullRequest));
int branchComponentCount = 3;
String oldProjectKey = project.getKey();
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldProjectKey)).hasSize(1);
String oldBranchKey = pullRequest.getDbKey();
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).hasSize(branchComponentCount);
String newProjectKey = "newKey";
String newBranchKey = ComponentDto.generatePullRequestKey(newProjectKey, pullRequest.getPullRequest());
underTest.updateKey(dbSession, project.uuid(), newProjectKey);
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldProjectKey)).isEmpty();
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).isEmpty();
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1);
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newBranchKey)).hasSize(branchComponentCount);
db.select(dbSession, "select kee from components").forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey)));
}
use of org.sonar.db.component.BranchType.PULL_REQUEST in project sonarqube by SonarSource.
the class SearchHistoryActionTest method pull_request.
@Test
public void pull_request() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
SnapshotDto analysis = db.components().insertSnapshot(branch);
MeasureDto measure = db.measures().insertMeasure(file, analysis, nclocMetric, m -> m.setValue(2d));
SearchHistoryResponse result = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr-123").setParam(PARAM_METRICS, "ncloc").executeProtobuf(SearchHistoryResponse.class);
assertThat(result.getMeasuresList()).extracting(HistoryMeasure::getMetric).hasSize(1);
HistoryMeasure historyMeasure = result.getMeasures(0);
assertThat(historyMeasure.getMetric()).isEqualTo(nclocMetric.getKey());
assertThat(historyMeasure.getHistoryList()).extracting(m -> parseDouble(m.getValue())).containsExactlyInAnyOrder(measure.getValue());
}
Aggregations