@Test public void search_using_main_branch_name() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertMainBranch(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile)); allowAnyoneOnProjects(project); indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, project.getKey()) .setParam(PARAM_BRANCH, "master") .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()) .extracting(Issue::getKey, Issue::getComponent, Issue::hasBranch) .containsExactlyInAnyOrder(tuple(projectIssue.getKey(), projectFile.getKey(), false)); assertThat(result.getComponentsList()) .extracting(Issues.Component::getKey, Issues.Component::hasBranch) .containsExactlyInAnyOrder( tuple(projectFile.getKey(), false), tuple(project.getKey(), false)); }
@Test public void search_by_pull_request() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile)); ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST)); ComponentDto pullRequestFile = db.components().insertComponent(newFileDto(pullRequest)); IssueDto pullRequestIssue = db.issues().insertIssue(newIssue(rule, pullRequest, pullRequestFile)); allowAnyoneOnProjects(project); indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, pullRequest.getKey()) .setParam(PARAM_PULL_REQUEST, pullRequest.getPullRequest()) .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()) .extracting(Issue::getKey, Issue::getComponent, Issue::getPullRequest) .containsExactlyInAnyOrder(tuple(pullRequestIssue.getKey(), pullRequestFile.getKey(), pullRequestFile.getPullRequest())); assertThat(result.getComponentsList()) .extracting(Issues.Component::getKey, Issues.Component::getPullRequest) .containsExactlyInAnyOrder( tuple(pullRequestFile.getKey(), pullRequestFile.getPullRequest()), tuple(pullRequest.getKey(), pullRequest.getPullRequest())); }
@Test public void issues_on_different_projects() { RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); OrganizationDto organization1 = db.organizations().insert(); ComponentDto project = db.components().insertPublicProject(organization1); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue1 = db.issues().insert(rule, project, file); OrganizationDto organization2 = db.organizations().insert(); ComponentDto project2 = db.components().insertPublicProject(organization2); ComponentDto file2 = db.components().insertComponent(newFileDto(project2)); IssueDto issue2 = db.issues().insert(rule, project2, file2); allowAnyoneOnProjects(project, project2); indexIssues(); SearchWsResponse response = ws.newRequest().executeProtobuf(SearchWsResponse.class); assertThat(response.getIssuesList()) .extracting(Issue::getKey, Issue::getComponent, Issue::getProject) .containsExactlyInAnyOrder( tuple(issue1.getKey(), file.getKey(), project.getKey()), tuple(issue2.getKey(), file2.getKey(), project2.getKey())); assertThat(response.getComponentsList()) .extracting(Component::getKey, Component::getEnabled) .containsExactlyInAnyOrder(tuple(project.getKey(), true), tuple(file.getKey(), true), tuple(project2.getKey(), true), tuple(file2.getKey(), true)); }
private List<Issue> toIssues(Issues.SearchWsResponse issuesSearchWsResponse, String branch) { List<Issues.Issue> issues = issuesSearchWsResponse.getIssuesList(); if (issues == null) { return Collections.emptyList(); } List<Issues.Component> components = issuesSearchWsResponse.getComponentsList(); Predicate<String> supported = ((Predicate<String>) Qualifiers.FILE::equals).or(Qualifiers.UNIT_TEST_FILE::equals); List<Issue> res = new ArrayList<>(); for (Issues.Issue issue : issues) { Optional<Issues.Component> componentOptional = components.stream() .filter(c -> supported.test(c.getQualifier())) .filter(c -> c.getKey().equals(issue.getComponent())) .findFirst(); File file = null; if (componentOptional.isPresent()) { Issues.Component component = componentOptional.get(); try { file = componentCache.get(component.getKey(), () -> toFile(componentOptional.get(), branch)); } catch (Exception e) { throw new IllegalStateException("Failed to get component file for " + component.getKey(), e); } } res.add(toIssue(issue, file)); } return res; }
@Test public void return_branch_in_component_list() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile)); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT)); ComponentDto branchFile = db.components().insertComponent(newFileDto(branch)); IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile)); allowAnyoneOnProjects(project); indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, branch.getKey()) .setParam(PARAM_BRANCH, branch.getBranch()) .executeProtobuf(SearchWsResponse.class); assertThat(result.getComponentsList()) .extracting(Issues.Component::getKey, Issues.Component::getBranch) .containsExactlyInAnyOrder( tuple(branchFile.getKey(), branchFile.getBranch()), tuple(branch.getKey(), branch.getBranch())); }